File size: 897 Bytes
ebd079c
70e13e2
ebd079c
2376116
ebd079c
2376116
ebd079c
2376116
ebd079c
2376116
ebd079c
2376116
ebd079c
 
 
2376116
ebd079c
2376116
ebd079c
 
 
 
 
 
 
2376116
ebd079c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from utils import create_index, get_agent_chain, get_prompt_and_tools, get_search_index
from utils import get_custom_agent, get_prompt_and_tools_for_custom_agent
question_starters = ['who', 'why', 'what', 'how', 'where', 'when', 'which', 'whom', 'whose']

def run(question):

    index = get_search_index()

    # prompt, tools = get_prompt_and_tools()

    # agent_chain = get_agent_chain(prompt, tools)

    prompt, tools = get_prompt_and_tools_for_custom_agent()

    agent_chain = get_custom_agent(prompt, tools)

    result = None

    try:
        result = agent_chain.run(question)
        print(result)
    except ValueError as ve:
        if "Could not parse LLM output:" in ve.args[0] and question.lower().startswith(tuple(question_starters)) and not question.lower().endswith('?'):
            question = question + '?'
            result = agent_chain.run(question)

    return result