Goals
- Use tool calling to build your own AI agent with Friendli Model APIs
- Check out the examples below to see how you can interact with state-of-the-art language models while letting them search the web, run Python code, etc.
- Feel free to make your own custom tools!
Getting started
- Head to Friendli Suite, and create an account.
- Grab a Personal API Key to use Friendli Model APIs within an agent.
Step 1. Playground UI
Experience tool calling on the Playground!- On your left sidebar, click the ‘Model APIs’ option to access the playground page.
- You will see models that can be used as Model APIs. Select the one you want and click the endpoint.
- Click ‘Tools’ button, select Search tool, and enter a query to see the response. 😀
Step 2. Tool calling
Search interesting information using theweb:search tool.
This time, let’s try it by writing Python code.
- Add your input as a
userrole message. - Add the
web:searchtool to the tools option.
Step 3. Multiple tool calling
Use multiple tools at once to calculate “How long it will take you to buy a house in the San Francisco Bay Area based on your annual salary”. Here are the available built-in tools.math:calculator(tool for calculating arithmetic operations)web:search(tool for retrieving data through the web search)code:python-interpreter(tool for writing and executing python code)
Example answer sheet
Step 4. Build a custom tool
Build your own creative tool. We will show you how to make a custom tool that retrieves temperature information. (Completed code snippet is provided at the bottom)- Define a function for using as a custom tool
-
Send a function calling inference request
- Add your input as a
userrole message. - The information about the custom function (e.g.,
get_temperature) goes into the tools option. JSON schema describes the function’s parameters. - The response includes the
argumentsfield, which are values extracted from the user’s input that can be used as parameters of the custom function.
- Add your input as a
-
Generate the final response using the tool calling results
- Add the
tool_callsresponse as anassistantrole message. - Add the result obtained by calling the
get_temperaturefunction as atoolmessage to the Chat API again.
- Add the
-
Complete Code Snippet