in 4-mmrag_tooluse/mmrag_bh.py [0:0]
def main_loop():
"""Interactive loop for processing user queries."""
print("Welcome to the Financial Assistant. Type 'exit' to quit.\n")
process_and_index_data()
while True:
user_query = input("User: ")
if user_query.lower() in ["exit", "quit"]:
print("Exiting the assistant. Goodbye!")
break
messages = [
{"role": "system", "content": TRIAGE_SYSTEM_PROMPT},
{"role": "user", "content": user_query},
]
response = client.chat.completions.create(
model='gpt-4o',
messages=messages,
tools=TOOLS,
tool_choice="required")
# Step 2: determine if the response from the model includes a tool call.
tool_calls = response.choices[0].message.tool_calls
if tool_calls:
# If true the model will return the name of the tool / function to call and the argument(s)
tool_call_id = tool_calls[0].id
tool_function_name = tool_calls[0].function.name
tool_query_string = json.loads(
tool_calls[0].function.arguments)['query']
# Step 3: Call the function and retrieve results. Append the results to the messages list.
if tool_function_name == 'ask_database':
results = ask_database(conn, tool_query_string)
messages.append({
"role": "tool",
"tool_call_id": tool_call_id,
"name": tool_function_name,
"content": results
})
elif tool_function_name == 'query_qdrant':
results = query_rag_system(user_query)
print(results)