mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 23:28:39 +08:00
doc: add example function calling requests
This commit is contained in:
parent
aae18e6878
commit
db9597a7b5
@ -60,3 +60,79 @@ URL.createObjectURL(await (await fetch("http://api.puter.localhost:4100/drivers/
|
|||||||
"method": "POST",
|
"method": "POST",
|
||||||
})).blob());
|
})).blob());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Tool Use
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await puter.ai.chat('What\'s the weather like in Vancouver?', {
|
||||||
|
tools: [
|
||||||
|
{
|
||||||
|
type: 'function',
|
||||||
|
'function': {
|
||||||
|
name: 'get_weather',
|
||||||
|
description: 'A string describing the weather',
|
||||||
|
parameters: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
location: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'city',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['location'],
|
||||||
|
additionalProperties: false,
|
||||||
|
},
|
||||||
|
strict: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
await puter.ai.chat([
|
||||||
|
{ content: `What's the weather like in Vancouver?` },
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": null,
|
||||||
|
"tool_calls": [
|
||||||
|
{
|
||||||
|
"id": "call_vcfEOmDczXq7KGMirPGGiNEe",
|
||||||
|
"type": "function",
|
||||||
|
"function": {
|
||||||
|
"name": "get_weather",
|
||||||
|
"arguments": "{\"location\":\"Vancouver\"}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"refusal": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'tool',
|
||||||
|
tool_call_id: 'call_vcfEOmDczXq7KGMirPGGiNEe',
|
||||||
|
content: 'Sunny with a chance of rain'
|
||||||
|
},
|
||||||
|
], {
|
||||||
|
tools: [
|
||||||
|
{
|
||||||
|
type: 'function',
|
||||||
|
'function': {
|
||||||
|
name: 'get_weather',
|
||||||
|
description: 'A string describing the weather',
|
||||||
|
parameters: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
location: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'city',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['location'],
|
||||||
|
additionalProperties: false,
|
||||||
|
},
|
||||||
|
strict: true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user