AI embedded functions calls - how can my function influence the AI response?

I'm playing around with CF AI Functions and came up with this. The user message passed to AI hints at a fruit, AI infers the fruit as an orange, and sends "orange" to my function. So far, so good.
import { runWithTools } from '@cloudflare/ai-utils';
router.get('/ai', async (req, env) => {
const fruit = ({fruit}) => {
console.log(fruit);
switch(fruit) {
case 'orange': return '*******';
}
};
return await runWithTools(
env.AI,
'@hf/nousresearch/hermes-2-pro-mistral-7b',
{
messages: [
{
role: 'user',
content: 'Discern the following fruit: shares its name with a colour, is juicy, and is citrus.',
},
],
tools: [
{
name: 'fruit',
description: `Output the user's favourite fruit`,
parameters: {
type: 'object',
properties: {
fruit: { type: 'fruit', description: `the user's favourite fruit` },
},
required: ['fruit'],
},
function: fruit,
},
],
}
);
});
import { runWithTools } from '@cloudflare/ai-utils';
router.get('/ai', async (req, env) => {
const fruit = ({fruit}) => {
console.log(fruit);
switch(fruit) {
case 'orange': return '*******';
}
};
return await runWithTools(
env.AI,
'@hf/nousresearch/hermes-2-pro-mistral-7b',
{
messages: [
{
role: 'user',
content: 'Discern the following fruit: shares its name with a colour, is juicy, and is citrus.',
},
],
tools: [
{
name: 'fruit',
description: `Output the user's favourite fruit`,
parameters: {
type: 'object',
properties: {
fruit: { type: 'fruit', description: `the user's favourite fruit` },
},
required: ['fruit'],
},
function: fruit,
},
],
}
);
});
What I don't know is how to get my function to influence the response. As you can see, my function returns "**", which I thought might implicitly form the AI's response. It doesn't; AI responds in its own wording. Is what I'm trying to do possible?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server