Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,11 +11,13 @@ notion_client = Client(auth=os.environ.get("NOTION_API_KEY"))
|
|
11 |
notion_database_id = "4fc0a081f0a84257879d6f7638e368b9"
|
12 |
|
13 |
def store_conversation(user_input, bot_response):
|
|
|
|
|
14 |
notion_client.pages.create(
|
15 |
parent={"database_id": notion_database_id},
|
16 |
properties={
|
17 |
"User Input": {"title": [{"text": {"content": user_input}}]},
|
18 |
-
"Bot Response": {"rich_text": [{"text": {"content":
|
19 |
}
|
20 |
)
|
21 |
|
@@ -30,7 +32,10 @@ def chat_with_groq(user_input, additional_context=None):
|
|
30 |
model="llama-3.1-8b-instant",
|
31 |
)
|
32 |
bot_response = chat_completion.choices[0].message.content
|
33 |
-
|
|
|
|
|
|
|
34 |
return bot_response
|
35 |
|
36 |
demo = gr.ChatInterface(fn=chat_with_groq,
|
|
|
11 |
notion_database_id = "4fc0a081f0a84257879d6f7638e368b9"
|
12 |
|
13 |
def store_conversation(user_input, bot_response):
|
14 |
+
# Truncate bot_response if it exceeds 2000 characters
|
15 |
+
truncated_response = bot_response[:1997] + "..." if len(bot_response) > 2000 else bot_response
|
16 |
notion_client.pages.create(
|
17 |
parent={"database_id": notion_database_id},
|
18 |
properties={
|
19 |
"User Input": {"title": [{"text": {"content": user_input}}]},
|
20 |
+
"Bot Response": {"rich_text": [{"text": {"content": truncated_response}}]}
|
21 |
}
|
22 |
)
|
23 |
|
|
|
32 |
model="llama-3.1-8b-instant",
|
33 |
)
|
34 |
bot_response = chat_completion.choices[0].message.content
|
35 |
+
try:
|
36 |
+
store_conversation(user_input, bot_response)
|
37 |
+
except Exception as e:
|
38 |
+
print(f"Error storing conversation: {str(e)}")
|
39 |
return bot_response
|
40 |
|
41 |
demo = gr.ChatInterface(fn=chat_with_groq,
|