mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-01 23:06:52 +01:00
Page:
src backend src modules puterai requests
Pages
AI
Home
README
api README
api concepts share_link
api drivers
api group
api notifications
api share
api type_tagged
api types app_share
api types file_share
backend Kernel
backend README
backend contributors boot_sequence
backend contributors modules
backend contributors structure
backend features protected_apps
backend features service_scripts
backend howto_make_driver
backend lists_of_things list_of_permissions
backend lists_of_things list_of_tto_types
backend modules puterai requests
backend modules test_drivers requests
backend notes 2024_10_03_email_in_use_checks
contributors comment_prefixes
contributors email_testing
contributors extensions README
contributors extensions definitions
contributors extensions events
contributors extensions
contributors structure
contributors vscode
devmeta track_comments
docmeta
gui webpack_attempts
phoenix missing_posix
phoenix parser
planning alternatives_to_$
planning micro_modules
prod
scratch
self_hosters config
self_hosters config_values
self_hosters credit_context
self_hosters domains
self_hosters first_run_issues
self_hosters instructions
self_hosters support
src backend A&A auth
src backend A&A permission
src backend A_and_A auth
src backend A_and_A permission
src backend Kernel
src backend README
src backend contributors boot_sequence
src backend contributors coding_style
src backend contributors modules
src backend contributors structure
src backend features batch_and_symlinks
src backend features metered_services
src backend features protected_apps
src backend features service_scripts
src backend howto_make_driver
src backend lists_of_things list_of_permissions
src backend lists_of_things list_of_tto_types
src backend modules puterai README
src backend notes 2024_10_03_email_in_use_checks
src backend services config
src backend services log
src backend src modules puterai README
src backend src modules puterai ai_services_config
src backend src modules puterai api_examples
src backend src modules puterai config
src backend src modules puterai contributors ai_usage_testing
src backend src modules puterai requests
src backend src modules test_drivers requests
src gui el()
src gui webpack_attempts
src phoenix missing_posix
src phoenix parser
testing_with_email
tools api_tester cartesian
uncategorized README
uncategorized es6_note
uncategorized puter_mods
No results
1
src backend src modules puterai requests
KernelDeimos edited this page 2025-02-25 15:04:16 -05:00
Table of contents
await (await fetch("http://api.puter.localhost:4100/drivers/call", {
"headers": {
"Content-Type": "application/json",
"Authorization": `Bearer ${puter.authToken}`,
},
"body": JSON.stringify({
interface: 'puter-ocr',
driver: 'aws-textract',
method: 'recognize',
args: {
source: '~/Desktop/testocr.png',
},
}),
"method": "POST",
})).json();
await (await fetch("http://api.puter.localhost:4100/drivers/call", {
"headers": {
"Content-Type": "application/json",
"Authorization": `Bearer ${puter.authToken}`,
},
"body": JSON.stringify({
interface: 'puter-chat-completion',
driver: 'openai-completion',
method: 'complete',
args: {
messages: [
{
role: 'system',
content: 'Act like Spongebob'
},
{
role: 'user',
content: 'How do I make my code run faster?'
},
]
},
}),
"method": "POST",
})).json();
URL.createObjectURL(await (await fetch("http://api.puter.localhost:4100/drivers/call", {
"headers": {
"Content-Type": "application/json",
"Authorization": `Bearer ${puter.authToken}`,
},
"body": JSON.stringify({
interface: 'puter-image-generation',
driver: 'openai-image-generation',
method: 'generate',
args: {
prompt: 'photorealistic teapot made of swiss cheese',
}
}),
"method": "POST",
})).blob());
Tool Use
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
},
}
]
})
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
},
}
]
})
Claude Tool Use with Streaming
gen = await puter.ai.chat('What\'s the weather like in Vancouver?', {
model: 'claude',
stream: true,
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
},
}
]
})
for await ( const thing of gen ) { console.log('thing', thing) }
Last item in the stream looks like this:
{
"tool_use": {
"type": "tool_use",
"id": "toolu_01Y4naZhXygjUVRjGBvrL9z8",
"name": "get_weather",
"input": {
"location": "Vancouver"
}
}
}
Respond like this:
gen = await puter.ai.chat([
{ role: 'user', content: `What's the weather like in Vancouver?` },
{
"role": "assistant",
"content": [
{ type: 'text', text: "I'll check the weather in Vancouver for you." },
{ type: 'tool_use', name: 'get_weather', id: 'toolu_01Y4naZhXygjUVRjGBvrL9z8', input: { location: 'Vancouver' } },
]
},
{
role: 'user',
content: [
{
type: 'tool_result',
tool_use_id: 'toolu_01Y4naZhXygjUVRjGBvrL9z8',
content: 'Sunny with a chance of rain'
}
]
},
], {
model: 'claude',
stream: true,
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
},
}
]
})
for await ( const item of gen ) { console.log(item) }
General
API
- Index (README.md)
- api drivers
- Group Endpoints
- Notification Endpoints
- Share Endpoints
- Type-Tagged Objects
Concepts
Types
For Contributors
- Comment Prefixes
- contributors vscode
- Local Email Testing
- Puter Extensions
- Repository Structure and Tooling
Extensions
Devmeta
Planning
- Micro Modules
- [planning alternatives_to_
](planning-alternatives_to_)
Self_hosters
- Configuring Domains for Self-Hosted Puter
- Configuring Puter
- First Run Issues
- self_hosters config_values
- self_hosters support
- Self-Hosting Puter
Src
Backend
A_and_A
For Contributors
- Backend Style
- Puter Backend - Directory Structure
- Puter Backend Boot Sequence
- Puter Kernel Moduels and Services
Features
- Batch and Symlinks
- Metered Services and Cost Management
- Protected Apps and Subdomains
- Service Scripts
Lists_of_things
Modules
Puterai
Notes
Services
Src
Modules
Puterai
- Index (README.md)
- Configuring AI Services
- PuterAI API Request Examples
- src backend src modules puterai config
####### For Contributors
Test_drivers
Gui
Phoenix
Tools
Api_tester
Uncategorized
This wiki is generated from the repository. Do not edit files the wiki.
You are reading documentation for Puter, an open-source high-level operating system.
Getting started with Puter on localhost is as simple as:
git clone https://github.com/HeyPuter/puter.git
npm install
npm run start