adriiita commited on
Commit
a2afe38
·
verified ·
1 Parent(s): 887ef85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -7,19 +7,23 @@ groq_client = Groq(
7
  api_key=os.environ.get("GROQ_API_KEY"),
8
  )
9
 
10
- 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
  # 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
 
24
  def chat_with_groq(user_input, additional_context=None):
25
  chat_completion = groq_client.chat.completions.create(
@@ -32,10 +36,7 @@ def chat_with_groq(user_input, additional_context=None):
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,
 
7
  api_key=os.environ.get("GROQ_API_KEY"),
8
  )
9
 
10
+ notion_client = Client(auth=os.environ.get("NOTION_TOKEN"))
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
+ try:
17
+ notion_client.pages.create(
18
+ parent={"database_id": notion_database_id},
19
+ properties={
20
+ "User Input": {"title": [{"text": {"content": user_input}}]},
21
+ "Bot Response": {"rich_text": [{"text": {"content": truncated_response}}]}
22
+ }
23
+ )
24
+ print("Conversation stored successfully")
25
+ except Exception as e:
26
+ print(f"Error storing conversation: {str(e)}")
27
 
28
  def chat_with_groq(user_input, additional_context=None):
29
  chat_completion = groq_client.chat.completions.create(
 
36
  model="llama-3.1-8b-instant",
37
  )
38
  bot_response = chat_completion.choices[0].message.content
39
+ store_conversation(user_input, bot_response)
 
 
 
40
  return bot_response
41
 
42
  demo = gr.ChatInterface(fn=chat_with_groq,