Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ import httpx
|
|
15 |
os.environ.pop("HTTP_PROXY", None)
|
16 |
os.environ.pop("HTTPS_PROXY", None)
|
17 |
|
18 |
-
# ConversationMemory class
|
19 |
class ConversationMemory:
|
20 |
def __init__(self, db_path="conversation.db"):
|
21 |
self.conn = sqlite3.connect(db_path)
|
@@ -71,7 +71,7 @@ class ConversationMemory:
|
|
71 |
cursor = self.conn.execute("SELECT * FROM conversation_chunks ORDER BY timestamp DESC LIMIT ?", (limit,))
|
72 |
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]
|
73 |
|
74 |
-
# TextEditor class
|
75 |
class TextEditor:
|
76 |
def __init__(self, memory):
|
77 |
self.memory = memory
|
@@ -120,10 +120,9 @@ class TextEditor:
|
|
120 |
return '\n'.join(diff)
|
121 |
return ""
|
122 |
|
123 |
-
# OpenAIApi class
|
124 |
class OpenAIApi:
|
125 |
def __init__(self, preprompt="", endpoint="https://T-App-GPT4o.openai.azure.com/openai/v1/", model="gpt-4o", api_key=None):
|
126 |
-
# Create a custom httpx client with proxies disabled
|
127 |
http_client = httpx.Client(proxies=None)
|
128 |
self.client = AzureOpenAI(
|
129 |
azure_endpoint=endpoint,
|
@@ -168,7 +167,7 @@ class OpenAIApi:
|
|
168 |
"type": "function",
|
169 |
"name": "paste_text",
|
170 |
"description": "Paste clipboard content into a conversation chunk.",
|
171 |
-
"
|
172 |
"type": "object",
|
173 |
"properties": {
|
174 |
"chunk_id": {"type": "string", "description": "ID of the conversation chunk"},
|
@@ -268,7 +267,7 @@ class OpenAIApi:
|
|
268 |
self.memory.add_chunk(error_msg, "system")
|
269 |
return {"error": error_msg}
|
270 |
|
271 |
-
# Gradio UI
|
272 |
async def chat_submit(user_input, chat_history, preprompt):
|
273 |
api = OpenAIApi(preprompt=preprompt, api_key=os.getenv("AZURE_OPENAI_API_KEY"))
|
274 |
response = await api.fetch_response(user_input)
|
@@ -365,6 +364,6 @@ def create_ui():
|
|
365 |
|
366 |
return demo
|
367 |
|
368 |
-
|
369 |
demo = create_ui()
|
370 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
15 |
os.environ.pop("HTTP_PROXY", None)
|
16 |
os.environ.pop("HTTPS_PROXY", None)
|
17 |
|
18 |
+
# ConversationMemory class
|
19 |
class ConversationMemory:
|
20 |
def __init__(self, db_path="conversation.db"):
|
21 |
self.conn = sqlite3.connect(db_path)
|
|
|
71 |
cursor = self.conn.execute("SELECT * FROM conversation_chunks ORDER BY timestamp DESC LIMIT ?", (limit,))
|
72 |
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]
|
73 |
|
74 |
+
# TextEditor class
|
75 |
class TextEditor:
|
76 |
def __init__(self, memory):
|
77 |
self.memory = memory
|
|
|
120 |
return '\n'.join(diff)
|
121 |
return ""
|
122 |
|
123 |
+
# OpenAIApi class
|
124 |
class OpenAIApi:
|
125 |
def __init__(self, preprompt="", endpoint="https://T-App-GPT4o.openai.azure.com/openai/v1/", model="gpt-4o", api_key=None):
|
|
|
126 |
http_client = httpx.Client(proxies=None)
|
127 |
self.client = AzureOpenAI(
|
128 |
azure_endpoint=endpoint,
|
|
|
167 |
"type": "function",
|
168 |
"name": "paste_text",
|
169 |
"description": "Paste clipboard content into a conversation chunk.",
|
170 |
+
" QUEparameters": {
|
171 |
"type": "object",
|
172 |
"properties": {
|
173 |
"chunk_id": {"type": "string", "description": "ID of the conversation chunk"},
|
|
|
267 |
self.memory.add_chunk(error_msg, "system")
|
268 |
return {"error": error_msg}
|
269 |
|
270 |
+
# Gradio UI
|
271 |
async def chat_submit(user_input, chat_history, preprompt):
|
272 |
api = OpenAIApi(preprompt=preprompt, api_key=os.getenv("AZURE_OPENAI_API_KEY"))
|
273 |
response = await api.fetch_response(user_input)
|
|
|
364 |
|
365 |
return demo
|
366 |
|
367 |
+
if __name__ == "__main__":
|
368 |
demo = create_ui()
|
369 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|