Skip to content

[Responses API] Function calling #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/responses-server/examples/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import OpenAI from "openai";

const openai = new OpenAI({ baseURL: "http://localhost:3000/v1", apiKey: process.env.HF_TOKEN });

const tools = [
{
type: "function",
name: "get_current_weather",
description: "Get the current weather in a given location",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA",
},
unit: { type: "string", enum: ["celsius", "fahrenheit"] },
},
required: ["location", "unit"],
},
},
];

const response = await openai.responses.create({
model: "meta-llama/Llama-3.3-70B-Instruct",
provider: "cerebras",
tools: tools,
input: "What is the weather like in Boston today?",
tool_choice: "auto",
});

console.log(response);
33 changes: 33 additions & 0 deletions packages/responses-server/examples/function_streaming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { OpenAI } from "openai";

const openai = new OpenAI({ baseURL: "http://localhost:3000/v1", apiKey: process.env.HF_TOKEN });

const tools = [
{
type: "function",
name: "get_weather",
description: "Get current temperature for provided coordinates in celsius.",
parameters: {
type: "object",
properties: {
latitude: { type: "number" },
longitude: { type: "number" },
},
required: ["latitude", "longitude"],
additionalProperties: false,
},
strict: true,
},
];

const stream = await openai.responses.create({
model: "meta-llama/Llama-3.3-70B-Instruct",
provider: "cerebras",
input: [{ role: "user", content: "What's the weather like in Paris today?" }],
tools,
stream: true,
});

for await (const event of stream) {
console.log(event);
}
Loading
Loading