Add router.py
Browse files
router.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import json, csv
|
| 4 |
+
|
| 5 |
+
def routing_agent(query, key, chat_history):
|
| 6 |
+
|
| 7 |
+
system_prompt = """
|
| 8 |
+
You are a routing agent, purely designed to determine if a user's query is a request for the use of a vector database for semantic search.
|
| 9 |
+
You will determine this based on the chat message history. A vector database is only needed to search for new classes. A user might ask for additional filtering on classes, but this is not necessarily a request for a new search.
|
| 10 |
+
Relay information in a way that is the bare minimum. You should only answer with a "1" when a vector db is needed or "0" otherwise and no other text at all.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
response = openai.ChatCompletion.create(
|
| 14 |
+
model="gpt-3.5-turbo",
|
| 15 |
+
messages=[
|
| 16 |
+
{"role": "system", "content": system_prompt},
|
| 17 |
+
{"role": "user", "content": query},
|
| 18 |
+
{"role": "chat_history", "content": chat_history}
|
| 19 |
+
]
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
return response["choices"][0]["message"]["content"]
|
| 23 |
+
|