louis030195 commited on
Commit
7bef441
1 Parent(s): 9572c0e

fix: error

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -2,24 +2,24 @@ import streamlit as st
2
 
3
  try:
4
  import dotenv
 
5
  except ImportError:
6
  pass
7
 
8
- dotenv.load_dotenv()
9
  import openai
10
  import os
11
  import streamlit.components.v1 as components
12
  import requests
13
- import asyncio
14
 
15
  openai.api_key = os.getenv("OPENAI_API_KEY")
16
  embedbase_api_key = os.getenv("EMBEDBASE_API_KEY")
17
 
18
- URL = "https://embedbase-hosted-usx5gpslaq-uc.a.run.app"
19
  local_history = []
20
 
21
 
22
- async def add_to_dataset(dataset_id: str, data: str):
23
  response = requests.post(
24
  f"{URL}/v1/{dataset_id}",
25
  headers={
@@ -38,7 +38,7 @@ async def add_to_dataset(dataset_id: str, data: str):
38
  return response.json()
39
 
40
 
41
- async def search_dataset(dataset_id: str, query: str, limit: int = 3):
42
  response = requests.post(
43
  f"{URL}/v1/{dataset_id}/search",
44
  headers={
@@ -54,10 +54,10 @@ async def search_dataset(dataset_id: str, query: str, limit: int = 3):
54
  return response.json()
55
 
56
 
57
- async def chat(user_input: str, conversation_name: str) -> str:
58
  local_history.append(user_input)
59
 
60
- history = await search_dataset(
61
  f"infinite-pt-{conversation_name}",
62
  # searching using last 4 messages from local history
63
  "\n\n---\n\n".join(local_history[-4:]),
@@ -82,7 +82,7 @@ async def chat(user_input: str, conversation_name: str) -> str:
82
  ],
83
  )
84
  message = response.choices[0]["message"]
85
- await add_to_dataset(f"infinite-pt-{conversation_name}", message["content"])
86
 
87
  local_history.append(message)
88
 
@@ -106,7 +106,7 @@ if not os.getenv("OPENAI_API_KEY"):
106
  openai.api_key = openai_key
107
  user_input = st.text_input("You", "How can I reach maximum happiness this year?")
108
  if st.button("Send"):
109
- infinite_pt_response = asyncio.run(chat(user_input, conversation_name))
110
  st.markdown(
111
  f"""
112
  Infinite-PT
 
2
 
3
  try:
4
  import dotenv
5
+ dotenv.load_dotenv()
6
  except ImportError:
7
  pass
8
 
 
9
  import openai
10
  import os
11
  import streamlit.components.v1 as components
12
  import requests
13
+
14
 
15
  openai.api_key = os.getenv("OPENAI_API_KEY")
16
  embedbase_api_key = os.getenv("EMBEDBASE_API_KEY")
17
 
18
+ URL = "https://api.embedbase.xyz"
19
  local_history = []
20
 
21
 
22
+ def add_to_dataset(dataset_id: str, data: str):
23
  response = requests.post(
24
  f"{URL}/v1/{dataset_id}",
25
  headers={
 
38
  return response.json()
39
 
40
 
41
+ def search_dataset(dataset_id: str, query: str, limit: int = 3):
42
  response = requests.post(
43
  f"{URL}/v1/{dataset_id}/search",
44
  headers={
 
54
  return response.json()
55
 
56
 
57
+ def chat(user_input: str, conversation_name: str) -> str:
58
  local_history.append(user_input)
59
 
60
+ history = search_dataset(
61
  f"infinite-pt-{conversation_name}",
62
  # searching using last 4 messages from local history
63
  "\n\n---\n\n".join(local_history[-4:]),
 
82
  ],
83
  )
84
  message = response.choices[0]["message"]
85
+ add_to_dataset(f"infinite-pt-{conversation_name}", message["content"])
86
 
87
  local_history.append(message)
88
 
 
106
  openai.api_key = openai_key
107
  user_input = st.text_input("You", "How can I reach maximum happiness this year?")
108
  if st.button("Send"):
109
+ infinite_pt_response = chat(user_input, conversation_name)
110
  st.markdown(
111
  f"""
112
  Infinite-PT