File size: 964 Bytes
0e59554
38ab472
da174c1
0e59554
 
 
afd8033
0e59554
 
 
 
 
38ab472
0e59554
38ab472
 
 
 
 
0e59554
c15f856
 
 
 
 
da174c1
c15f856
 
768fd1a
 
c15f856
 
0e59554
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
29
30
31
32
33
34
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 index():
    get_search_index()
    return True

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)
    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)
    finally:
        print(result)

    return result