Skip to content

Ability functions

calculator_function(question)

Runs a natural language math query using the LLMMathChain.

Parameters:

Name Type Description Default
question str

The natural language math query.

required

Returns:

Name Type Description
str

The response to the query.

Examples:

>>> calculator_function("What is the square root of 25?")
5
Source code in backend/Multi-Sensory Virtual AAGI/ability_functions/calculator.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def calculator_function(question):
    """
    Runs a natural language math query using the LLMMathChain.
    Args:
      question (str): The natural language math query.
    Returns:
      str: The response to the query.
    Examples:
      >>> calculator_function("What is the square root of 25?")
      5
    """
    chat = ChatOpenAI(temperature  = 0, model= 'gpt-3.5-turbo', openai_api_key=OPENAI_API_KEY)
    llm_math = LLMMathChain(llm=chat, verbose=True)
    response = llm_math.run(question)
    return response

search_function(question)

Searches for information on a given question.

Parameters:

Name Type Description Default
question str

The question to search for.

required

Returns:

Name Type Description
str

Output of the search.

Examples:

>>> search_function("What is the capital of France?")
"Searching for information on this What is the capital of France?
Paris"
Source code in backend/Multi-Sensory Virtual AAGI/ability_functions/search.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def search_function(question):
    """
    Searches for information on a given question.
    Args:
      question (str): The question to search for.
    Returns:
      str: Output of the search.
    Examples:
      >>> search_function("What is the capital of France?")
      "Searching for information on this What is the capital of France?
      Paris"
    """
    # Redirecting stdout to StringIO object
    old_stdout = sys.stdout
    sys.stdout = result = StringIO()
    try:
        chat = ChatOpenAI(temperature  = 0, model= 'gpt-3.5-turbo', openai_api_key=OPENAI_API_KEY)
        tools = load_tools(["google-serper"], llm=chat)
        agent = initialize_agent(tools, chat, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
        response = agent.run("Search and gather information on this " + question)
        output = result.getvalue()
        sys.stdout = old_stdout
        return  str(output) + response 
    except Exception as e:
        output = result.getvalue()
        sys.stdout = old_stdout
        return str(output)

natural_language_task_function(instructions)

Generates a response to a given instruction using OpenAI's GPT-3.5-Turbo model.

Parameters:

Name Type Description Default
instructions str

The instruction to generate a response to.

required

Returns:

Name Type Description
str

The response generated by the GPT-3.5-Turbo model.

Examples:

>>> natural_language_task_function("What is the weather like today?")
"It's sunny and warm today."
Source code in backend/Multi-Sensory Virtual AAGI/ability_functions/natural_language_task.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def natural_language_task_function(instructions):
    """
    Generates a response to a given instruction using OpenAI's GPT-3.5-Turbo model.
    Args:
      instructions (str): The instruction to generate a response to.
    Returns:
      str: The response generated by the GPT-3.5-Turbo model.
    Examples:
      >>> natural_language_task_function("What is the weather like today?")
      "It's sunny and warm today."
    """
    chat = ChatOpenAI(temperature  = 0, model= 'gpt-3.5-turbo', openai_api_key=OPENAI_API_KEY)
    human_template = "{instructions}"
    human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
    chat_prompt = ChatPromptTemplate.from_messages([human_message_prompt])
    response = chat(chat_prompt.format_prompt(instructions=instructions).to_messages()).content
    return response

wikipedia_function(topic)

Runs a query on the Wikipedia API.

Parameters:

Name Type Description Default
topic str

The topic to query.

required

Returns:

Name Type Description
dict

The result of the query.

Examples:

>>> wikipedia_function('Python')
{'title': 'Python', 'summary': 'Python is a programming language...'}
Source code in backend/Multi-Sensory Virtual AAGI/ability_functions/wikipedia.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def wikipedia_function(topic):
    """
    Runs a query on the Wikipedia API.
    Args:
      topic (str): The topic to query.
    Returns:
      dict: The result of the query.
    Examples:
      >>> wikipedia_function('Python')
      {'title': 'Python', 'summary': 'Python is a programming language...'}
    """
    wikipedia = WikipediaAPIWrapper()
    result = wikipedia.run(topic)
    return result