Du Mingzhe
commited on
Commit
•
5e4b488
1
Parent(s):
9871c29
Update
Browse files- app.py +3 -0
- components.py +19 -0
app.py
CHANGED
@@ -32,6 +32,9 @@ if prompt := st.chat_input("What's up?"):
|
|
32 |
memory = pinecone_client.query_conversation(messages=st.session_state.messages[:-5], user=st.session_state['user'], top_k=3)
|
33 |
print(f"Memory: {memory}")
|
34 |
|
|
|
|
|
|
|
35 |
web_result = web_searcher.query_web_llm(query=prompt, num_web_results=5)
|
36 |
print(f"Web Result: {web_result}")
|
37 |
|
|
|
32 |
memory = pinecone_client.query_conversation(messages=st.session_state.messages[:-5], user=st.session_state['user'], top_k=3)
|
33 |
print(f"Memory: {memory}")
|
34 |
|
35 |
+
web_query = llm_client.web_query_generator(query=prompt, history=st.session_state.messages)
|
36 |
+
print(f"Web Query: {web_query}")
|
37 |
+
|
38 |
web_result = web_searcher.query_web_llm(query=prompt, num_web_results=5)
|
39 |
print(f"Web Result: {web_result}")
|
40 |
|
components.py
CHANGED
@@ -14,6 +14,25 @@ class LLMClient():
|
|
14 |
self.model_name = model_name
|
15 |
self.llm_client = OpenAI(api_key=api_key)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def response_generate(self, query, history, memory, web_result):
|
18 |
messages = list()
|
19 |
current_time = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
|
|
14 |
self.model_name = model_name
|
15 |
self.llm_client = OpenAI(api_key=api_key)
|
16 |
|
17 |
+
def web_query_generator(self, query, history):
|
18 |
+
messages = list()
|
19 |
+
current_time = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
20 |
+
|
21 |
+
# System Prompt
|
22 |
+
messages += [{"role": "system", "content": f"1) You're Du Mingzhe. 2) Current time is {current_time}. 3) Generate the web search query only."}]
|
23 |
+
|
24 |
+
# Session History
|
25 |
+
messages += [{"role": h["role"], "content": h["content"]} for h in history[:-1]]
|
26 |
+
|
27 |
+
messages += [{"role": 'user', "content": f"Given the context, generate a proper web search query for [{query}]."}]
|
28 |
+
|
29 |
+
response = self.llm_client.chat.completions.create(
|
30 |
+
model = self.model_name,
|
31 |
+
messages = messages,
|
32 |
+
)
|
33 |
+
|
34 |
+
return response.choices[0].message
|
35 |
+
|
36 |
def response_generate(self, query, history, memory, web_result):
|
37 |
messages = list()
|
38 |
current_time = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|