Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,10 @@ import difflib
|
|
10 |
from tiktoken import get_encoding
|
11 |
from openai import AzureOpenAI
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# ConversationMemory class (unchanged)
|
14 |
class ConversationMemory:
|
15 |
def __init__(self, db_path="conversation.db"):
|
@@ -66,7 +70,7 @@ class ConversationMemory:
|
|
66 |
cursor = self.conn.execute("SELECT * FROM conversation_chunks ORDER BY timestamp DESC LIMIT ?", (limit,))
|
67 |
return [{"chunk_id": row[0], "text": row[1], "role": row[2], "timestamp": row[3], "intent": row[4], "token_count": row[5]} for row in cursor]
|
68 |
|
69 |
-
# TextEditor class (
|
70 |
class TextEditor:
|
71 |
def __init__(self, memory):
|
72 |
self.memory = memory
|
@@ -104,7 +108,7 @@ class TextEditor:
|
|
104 |
chunk = self.memory.get_chunk(chunk_id)
|
105 |
if chunk:
|
106 |
chunk['text'] = chunk['text'] + suffix
|
107 |
-
self.memory.update_chunk(chunk_id, chunk['text'])
|
108 |
return chunk['text']
|
109 |
|
110 |
def diff(self, chunk_id, original_text):
|
@@ -115,14 +119,13 @@ class TextEditor:
|
|
115 |
return '\n'.join(diff)
|
116 |
return ""
|
117 |
|
118 |
-
# OpenAIApi class (
|
119 |
class OpenAIApi:
|
120 |
def __init__(self, preprompt="", endpoint="https://T-App-GPT4o.openai.azure.com/openai/v1/", model="gpt-4o", api_key=None):
|
121 |
self.client = AzureOpenAI(
|
122 |
azure_endpoint=endpoint,
|
123 |
api_key=api_key or os.getenv("AZURE_OPENAI_API_KEY"),
|
124 |
-
api_version="2025-01-01-preview"
|
125 |
-
http_client_kwargs={"proxies": None}
|
126 |
)
|
127 |
self.model = model
|
128 |
self.preprompt = preprompt
|
@@ -261,7 +264,7 @@ class OpenAIApi:
|
|
261 |
self.memory.add_chunk(error_msg, "system")
|
262 |
return {"error": error_msg}
|
263 |
|
264 |
-
# Gradio UI (unchanged
|
265 |
async def chat_submit(user_input, chat_history, preprompt):
|
266 |
api = OpenAIApi(preprompt=preprompt, api_key=os.getenv("AZURE_OPENAI_API_KEY"))
|
267 |
response = await api.fetch_response(user_input)
|
|
|
10 |
from tiktoken import get_encoding
|
11 |
from openai import AzureOpenAI
|
12 |
|
13 |
+
# Clear proxy environment variables to avoid proxies error
|
14 |
+
os.environ.pop("HTTP_PROXY", None)
|
15 |
+
os.environ.pop("HTTPS_PROXY", None)
|
16 |
+
|
17 |
# ConversationMemory class (unchanged)
|
18 |
class ConversationMemory:
|
19 |
def __init__(self, db_path="conversation.db"):
|
|
|
70 |
cursor = self.conn.execute("SELECT * FROM conversation_chunks ORDER BY timestamp DESC LIMIT ?", (limit,))
|
71 |
return [{"chunk_id": row[0], "text": row[1], "role": row[2], "timestamp": row[3], "intent": row[4], "token_count": row[5]} for row in cursor]
|
72 |
|
73 |
+
# TextEditor class (unchanged)
|
74 |
class TextEditor:
|
75 |
def __init__(self, memory):
|
76 |
self.memory = memory
|
|
|
108 |
chunk = self.memory.get_chunk(chunk_id)
|
109 |
if chunk:
|
110 |
chunk['text'] = chunk['text'] + suffix
|
111 |
+
self.memory.update_chunk(chunk_id, chunk['text'])
|
112 |
return chunk['text']
|
113 |
|
114 |
def diff(self, chunk_id, original_text):
|
|
|
119 |
return '\n'.join(diff)
|
120 |
return ""
|
121 |
|
122 |
+
# OpenAIApi class (removed http_client_kwargs)
|
123 |
class OpenAIApi:
|
124 |
def __init__(self, preprompt="", endpoint="https://T-App-GPT4o.openai.azure.com/openai/v1/", model="gpt-4o", api_key=None):
|
125 |
self.client = AzureOpenAI(
|
126 |
azure_endpoint=endpoint,
|
127 |
api_key=api_key or os.getenv("AZURE_OPENAI_API_KEY"),
|
128 |
+
api_version="2025-01-01-preview"
|
|
|
129 |
)
|
130 |
self.model = model
|
131 |
self.preprompt = preprompt
|
|
|
264 |
self.memory.add_chunk(error_msg, "system")
|
265 |
return {"error": error_msg}
|
266 |
|
267 |
+
# Gradio UI (unchanged)
|
268 |
async def chat_submit(user_input, chat_history, preprompt):
|
269 |
api = OpenAIApi(preprompt=preprompt, api_key=os.getenv("AZURE_OPENAI_API_KEY"))
|
270 |
response = await api.fetch_response(user_input)
|