File size: 1,034 Bytes
d8083af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3305431
d8083af
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import openai
import json, csv

def routing_agent(query, key, chat_history):
    
    system_prompt = """
    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.
        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.
    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.
    """

    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": system_prompt},
            {"role": "user", "content": query},
            {"role": "assistant", "content": "Here is the chat history: " + chat_history}
        ]
    )

    return response["choices"][0]["message"]["content"]