Peerwave

Peerwave

Discover

Download

Docs

Discord

Tools

Execute tool calls on behalf of users to access internet services and data. Tools can be used directly or integrated with chat models for enhanced AI interactions.

Basic Tool Request

Execute a tool call directly using the /api/tools endpoint. Currently available tools are internet-accessible services that don't require personal user data. Available tools can be found by using the /api/models endpoint.

Try Wikipedia Tool

fetch("https://api.peerwave.ai/api/tools", { method: "POST", headers: { "Content-Type": "application/json", "Redirect": window.location.pathname + "?codeblock=wikipedia-tool" }, body: JSON.stringify({ "function": { "name": "wikipedia", "arguments": { "query": "Benjamin Franklin" } } }) }).then((response) => { if (!response.ok) { throw new Error("Invalid response"); } return response.json().then((data) => { console.log(data); return data; }) })

Parameters

function (required)

The tool function to execute, containing:

  • name - The name of the tool to execute (e.g., "wikipedia")

  • arguments - An object containing the parameters for the tool

Integration with Chat Models

Tools integrate seamlessly with chat responses. When you provide tool definitions in a chat request, the model can select and use tools as needed and provide it's choices in the tool_calls field of a message. You can pass in each tool call directly to the tools endpoint.

Chat with Tools Example

fetch("https://api.peerwave.ai/api/chat", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ "model": "cheapest", "messages": [ { "role": "user", "content": "Tell me about Benjamin Franklin" } ], "tools": [ { "type": "function", "function": { "name": "wikipedia", "description": "Search Wikipedia for information on a topic", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "The topic to search for" } } } } } ] }), }).then((response) => { return response.json().then((data) => { // If the model wants to use a tool, data.message.tool_calls will contain the calls if (data.message.tool_calls) { // Execute each tool call using /api/tools endpoint data.message.tool_calls.forEach(toolCall => { fetch("https://api.peerwave.ai/api/tools", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(toolCall) }).then((response) => { return response.json().then((data) => { console.log(data); }) }); }); } }); })

Tool Call Compatibility: The parameters for the tools endpoint are identical to what models emit in tool_calls, allowing you to send each tool call entry directly to the endpoint.

Tool Definitions

When using tools with chat models, you define available tools using JSON Schema format. This tells the model what to use a tool for and what parameters to provide when calling it.

Example Tool Definition

{ "type": "function", "function": { "name": "search", "description": "A wrapper around a search engine. Useful for when you need to answer general questions that you don't have existing knowledge of in this conversation. Input should be what you are looking for information on.", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "The thing you are looking for information on" } } } } }