Skip to content

Instantly share code, notes, and snippets.

@up1
Last active December 24, 2025 15:31
Show Gist options
  • Select an option

  • Save up1/3872c17d3cd5d5054e58b695d9ce8ffe to your computer and use it in GitHub Desktop.

Select an option

Save up1/3872c17d3cd5d5054e58b695d9ce8ffe to your computer and use it in GitHub Desktop.
Hello FunctionGemma model
$ollama list
NAME ID SIZE MODIFIED
functiongemma:latest 7c19b650567a 300 MB 15 minutes ago
$ollama run functiongemma
pulling manifest
pulling 415f8f959d80: 100% ▕██████████████████████████████████████████████████████████████████████████▏ 300 MB
pulling 64c834d5c134: 100% ▕██████████████████████████████████████████████████████████████████████████▏ 10 KB
pulling b536e845ddda: 100% ▕██████████████████████████████████████████████████████████████████████████▏ 26 B
pulling d087699a8829: 100% ▕██████████████████████████████████████████████████████████████████████████▏ 468 B
verifying sha256 digest
writing manifest
success
>>>hello
I am sorry, but I cannot assist with assisting with writing creative writing prompts or generating prompts. My current
capabilities are focused on assisting with tasks related to writing stories, such as assisting with generating text. I cannot
generate creative writing prompts.
$node demo.js
Final input:
[
{
"role": "user",
"content": "What is my horoscope? I am an Aquarius."
},
{
"type": "function_call_output",
"call_id": "call_a41756mf",
"output": "{\"horoscope\":\"[object Object] Next Tuesday you will befriend a baby otter.\"}"
}
]
Final output:
[
{
"id": "msg_350979",
"type": "message",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "The horoscope for Aquarius:\n\n**Next Tuesday you will befriend a baby otter.**"
}
]
}
]
import OpenAI from "openai";
const openai = new OpenAI(
{ apiKey: "dummy_api_key",
baseURL: "http://localhost:11434/v1"
}
);
// 1. Define a list of callable tools for the model
const tools = [
{
type: "function",
name: "get_horoscope",
description: "Get today's horoscope for an astrological sign.",
parameters: {
type: "object",
properties: {
sign: {
type: "string",
description: "An astrological sign like Taurus or Aquarius",
},
},
required: ["sign"],
},
},
];
function getHoroscope(sign) {
return sign + " Next Tuesday you will befriend a baby otter.";
}
// Create a running input list we will add to over time
let input = [
{ role: "user", content: "What is my horoscope? I am an Aquarius." },
];
// 2. Prompt the model with tools defined
let response = await openai.responses.create({
model: "functiongemma",
tools,
input,
});
response.output.forEach((item) => {
if (item.type == "function_call") {
if (item.name == "get_horoscope") {
// Prepare to add function call results to input
let input_list = input;
// 3. Execute the function logic for get_horoscope
var horoscope = getHoroscope(JSON.parse(item.arguments))
// 4. Provide function call results to the model
input_list.push({
type: "function_call_output",
call_id: item.call_id,
output: JSON.stringify({
horoscope
})
})
}
}
});
console.log("Final input:");
console.log(JSON.stringify(input, null, 2));
response = await openai.responses.create({
model: "functiongemma",
instructions: "Respond only with a horoscope generated by a tool.",
tools,
input,
});
// 5. The model should be able to give a response!
console.log("Final output:");
console.log(JSON.stringify(response.output, null, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment