In this tutorial, we will use LLMs to select the correct tools to use. In the following, we recommend using a LLM which has been trained on tool datasets. E.g., consider using:
For the rest of this section, we will use an LLM using its prompt. Install the LLM of your choice.
Implement the following functions:
count_char_occurrences(input_string, char)
which takes a string and a character and counts the number of occurrences of the character in the string.simple_calculator(operation, num1, num2)
which takes as input two numbers and perform a simple operation. operation
can get the following values add
, subtract
, multiply
, or divide
.SolveEquation(equation_str)
which takes an equation string and returns its solution. This will make use symbols, Eq, solve, sympify
from sympy
.Use the OpenAI’s format to describe each of your function (see documentation and example below).
{
"name": "get_delivery_date",
"description": "Get the delivery date for a customer's order. Call this whenever you need to know the delivery date, for example when a customer asks 'Where is my package'",
"parameters": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The customer's order ID.",
},
},
"required": ["order_id"],
"additionalProperties": false,
}
}
Store all the function descriptions into a list.
Write a function llm_tool
which takes as input a query (and possibly the output of the previous function calls) and performs the following steps:
[func_name1(params_name1=params_value1, params_name2=params_value2...), func_name2(params)]
<aside> 👉🏻
Expected output for the query "How many r are there in straberrrrrries? How many r are there in rraaaar?"
(and no previous function calls)
["count_char_occurrences(input_string='straberrrrrries', char='r')", "count_char_occurrences(input_string='rraaaar', char='r')"]
</aside>
Write a function llm_reasoner
which takes as input a query and performs the following steps:
evaluations
is created.llm_tool
with the query.llm_tool
is evaluated (if possible) and stored in evaluations
. This dictionary associates the function call to the output.llm_tool
is called again with the query and the content of evaluations
.evaluations
is unchanged.evaluations
and the LLM must use its content to answer the query.<aside> 👉🏻
Expected output
"How many r are there in straberrrrrries? How many r are there in rraaaar?”
Based on the function calls and their output:
- For "straberrrrrries", count_char_occurrences() returns 7.
- For "rraaar", count_char_occurrences() returns 3.
So, the answer is: There are 7 r's in straberrrrrries and 3 r's in rraaaar.
"How much is 123123123 + 4343434?”
To find the result of 123123123 + 4343434, we can look at the function calls provided and see that they were passed to a calculator function.
According to the output:
{"simple_calculator(operation='add', num1=123123123, num2=4343434)": 127466557}
The calculation results in: **127466557**.
"How many r are there in straberrries? How many a are there in rraaaar? Divide the first value by the second”
Based on the function calls and their outputs:
* In "straberrries", the character 'r' appears 4 times.
* In "rraaaar", the character 'a' appears 4 times.
So, dividing the number of 'r's in "straberrries" by the number of 'a's in "rraaaar" gives:
4 (number of 'r's) ÷ 4 (number of 'a's) = 1
"What is the solution for x2-3*x + 21321412412?”**
To solve the equation x**2 - 3*x + 21321412412, we can use the quadratic formula:
x = (-b ± √(b^2 - 4ac)) / 2a
In this case, a = 1, b = -3, and c = 21321412412.
Plugging these values into the formula, we get:
x = (3 ± √((-3)^2 - 4*1*21321412412)) / 2*1
x = (3 ± √(9 - 85285649648)) / 2
x = (3 ± √(-85285649639)) / 2
Since the value under the square root is negative, we know that the solutions will be complex numbers.
Using a calculator or a programming language, we can calculate the solutions:
x ≈ [3/2 - sqrt(85285649639)*I/2, 3/2 + sqrt(85285649639)*I/2]
This matches the output provided in your original function call.
</aside>
streamlit
and langchain
, create a simple application that asks the user for a story topic and generates a title for the story.A group of researcher would like to annotate a set of research papers to detect the presence of “an Opinion Measurement Tool (OMT) which is a computational system, model, algorithm, or method that automatically processes and analyzes textual data to infer evaluation, belief, or feeling of an individual towards a specific subject”.
For each research paper, they want to extract the answer to the following questions: