googleapis / googleapis/nodejs-agentplatform

Function calling returns textValue instead of StructValue

Open
#168 0 comments 2 reactions 0 assignees View on GitHub
api: aiplatform priority: p3 type: question
Dominant language
TypeScript
Stars
182
Forks
69
Avg merge
1d 8h
Merged PRs (30d)
10

Description

- What you're trying to do

Use function calling in gemini pro for getting structured results based on OpenAPI schema.

- What code you've already tried

```
const model = vertexAI.preview.getGenerativeModel({
model: "gemini-pro",
generation_config: {
max_output_tokens: 2048,
temperature: 0.9,
top_p: 1
},
safety_settings: []
});
const limit = 5;
const term = "Upgrade Wooden Doors";

const result = await model.generateContent({
contents: [
{
role: "user",
parts: [
{
text: `Create ${limit} questions, answers in spanish and question types such as single choice or multiple choice for a home service ${term}.`
}
]
},
{
role: "model",
parts: [
{
functionCall: {
name: "service_form_generator",
args: { service: term }
}
}
]
},
{
role: "function",
parts: [
{
functionResponse: {
name: "service_form_generator",
response: {
name: "service_form_generator",
content: {
question: "How many doors do you have?",
answer: ["1", "2", "3", "4+"],
type: "single_choice"
}
}
}
}
]
}
],
tools: [
{
function_declarations: [
{
name: "service_form_generator",
description: "Generates a form for a home service.",
parameters: {
type: FunctionDeclarationSchemaType.OBJECT,
properties: {
service: {
type: FunctionDeclarationSchemaType.STRING,
description:
"The home service to get questions and answers for, e.g. 'Upgrade Wooden Doors'."
},
question: {
type: FunctionDeclarationSchemaType.STRING,
description: "The number of questions to generate."
},
answer: {
type: FunctionDeclarationSchemaType.STRING,
description: "The term to generate questions for."
},
type: {
type: FunctionDeclarationSchemaType.STRING,
description:
"The type of question to generate, e.g. single_choice or multiple_choice.",
enum: ["single_choice", "multiple_choice"]
}
},
required: ["service"]
}
}
]
}
]
});
const response = await result.response;
logger.log(response.candidates[0].content.parts[0]);

return response.candidates[0].content.parts[0];
```

- Any error messages you're getting

Not structured data as example
```
"1. ¿Cuántas puertas tienes?\n * 1\n * 2\n * 3\n * 4+\n2. ¿En qué estado están tus puertas?\n * Perfectas\n * Necesitan pequeños arreglos\n * Necesitan reparaciones importantes\n3. ¿Qué tipo de madera tienen tus puertas?\n * Pino\n * Roble\n * Caoba\n * Otro\n4. ¿Cuál es el tamaño de tus puertas?\n * Pequeñas\n * Medianas\n * Grandes\n5. ¿Quieres que las puertas sean pintadas o barnizadas?\n * Pintadas\n * Barnizadas"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.