Comparing version 0.1.0-rc.1 to 0.1.0-rc.2
@@ -8,2 +8,7 @@ type ToolRunAsistantHint = { | ||
}; | ||
/** | ||
* Tool run failed | ||
* | ||
* The tool run ended with an error. | ||
*/ | ||
type ToolRunError = ToolRunAsistantHint & { | ||
@@ -13,2 +18,8 @@ status: 'error'; | ||
}; | ||
/** | ||
* Tool run requires action | ||
* | ||
* The response requires an action from the user. | ||
* For example, the user may need to connect (authenticate) an 3rd party account. | ||
*/ | ||
type ToolRunActionRequired = ToolRunAsistantHint & { | ||
@@ -19,8 +30,29 @@ status: 'requires_action'; | ||
}; | ||
/** | ||
* Tool run response | ||
* | ||
* Superface responses are either successful, failed, or require action. | ||
* The response contains an assistant hint that can help LLM understand the result and what to do next. | ||
* | ||
*/ | ||
type ToolRun<TResult = unknown> = ToolRunSuccess<TResult> | ToolRunError | ToolRunActionRequired; | ||
type ToolConnectionsRespnose = { | ||
/** | ||
* Response with a link to the user's connections | ||
*/ | ||
type UserConnectionsLink = { | ||
status: 'success'; | ||
configuration_url: string; | ||
url: string; | ||
assistant_hint: string; | ||
}; | ||
/** | ||
* Tool definition | ||
* | ||
* Currenty only function tools are supported. | ||
* | ||
* @param type Type of the tool (currently only 'function' is supported) | ||
* @param function Function tool definition | ||
* @param function.name Name of the tool | ||
* @param function.description Description of the tool | ||
* @param function.parameters Parameters of the tool. Defined as JSON schema. | ||
*/ | ||
type ToolDefinition = { | ||
@@ -54,2 +86,8 @@ type: 'function'; | ||
}; | ||
/** | ||
* Generic error thrown by the Superface client | ||
* | ||
* This should make intercepting errors easier. | ||
* To access the original error, use the `originalError` property. | ||
*/ | ||
declare class SuperfaceError extends Error { | ||
@@ -68,15 +106,16 @@ originalError?: unknown; | ||
/** | ||
* Superface intelligent tools | ||
* Superface HTTP Client | ||
* | ||
* @param opts {SuperfaceOptions} Options for the Superface client | ||
* Low level client for the Superface API. | ||
* Consider using framework-specific clients. | ||
* | ||
* @example | ||
* import Superface from '@superfaceai/client'; | ||
* const client = new Superface({ apiKey }); | ||
* const superface = new Superface({ apiKey }); | ||
* | ||
* // Get and pass the tools to the LLM Call | ||
* const tools = await client.getTools(); | ||
* const tools = await superface.getTools(); | ||
* | ||
* // Once the LLM Call is done, check messages for tool calls and run them | ||
* const result = await client.runTool({ userId, name, args }); | ||
* const result = await superface.runTool({ userId, name, args }); | ||
*/ | ||
@@ -115,2 +154,27 @@ declare class Superface { | ||
* @throws {SuperfaceError} | ||
* | ||
* @example | ||
* const toolRun = await superface.runTool({ | ||
* userId: 'example_user', | ||
* name: toolCall.function.name, | ||
* args: JSON.parse(toolCall.function.arguments), | ||
* }); | ||
* | ||
* switch (toolRun.status) { | ||
* case 'success': { | ||
* console.log('✅', 'Tool run successful'); | ||
* console.log(toolRun.result); | ||
* break; | ||
* } | ||
* case 'error': { | ||
* console.error('❌', 'Tool run failed'); | ||
* console.error(toolRun.error); | ||
* break; | ||
* } | ||
* case 'requires_action': { | ||
* console.error('❗', 'Tool run requires action'); | ||
* console.error(toolRun.action_type, ' => ', toolRun.action_url); | ||
* break; | ||
* } | ||
* } | ||
*/ | ||
@@ -123,3 +187,3 @@ runTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>({ userId, name, args, }: { | ||
/** | ||
* Manage connections | ||
* Get link to users connections | ||
* | ||
@@ -131,10 +195,10 @@ * Fetches a configuration link for the user to manage connections in the Superface. | ||
* @example | ||
* const connections = await superface.toolConnections({ userId: 'example_user' }); | ||
* redirect(connections.configuration_url); | ||
* const link = await superface.linkToUserConnections({ userId: 'example_user' }); | ||
* redirect(link.url); | ||
*/ | ||
toolConnections({ userId, }: { | ||
linkToUserConnections({ userId, }: { | ||
userId: string; | ||
}): Promise<ToolConnectionsRespnose>; | ||
}): Promise<UserConnectionsLink>; | ||
} | ||
export { type ApplicationReturnLink, Superface, SuperfaceError, type SuperfaceOptions, type ToolConnectionsRespnose, type ToolDefinition, type ToolRun, type ToolRunActionRequired, type ToolRunAsistantHint, type ToolRunError, type ToolRunSuccess, assertUserId, Superface as default, isUserIdValid }; | ||
export { type ApplicationReturnLink, Superface, SuperfaceError, type SuperfaceOptions, type ToolDefinition, type ToolRun, type ToolRunActionRequired, type ToolRunAsistantHint, type ToolRunError, type ToolRunSuccess, type UserConnectionsLink, assertUserId, Superface as default, isUserIdValid }; |
@@ -126,2 +126,27 @@ "use strict"; | ||
* @throws {SuperfaceError} | ||
* | ||
* @example | ||
* const toolRun = await superface.runTool({ | ||
* userId: 'example_user', | ||
* name: toolCall.function.name, | ||
* args: JSON.parse(toolCall.function.arguments), | ||
* }); | ||
* | ||
* switch (toolRun.status) { | ||
* case 'success': { | ||
* console.log('✅', 'Tool run successful'); | ||
* console.log(toolRun.result); | ||
* break; | ||
* } | ||
* case 'error': { | ||
* console.error('❌', 'Tool run failed'); | ||
* console.error(toolRun.error); | ||
* break; | ||
* } | ||
* case 'requires_action': { | ||
* console.error('❗', 'Tool run requires action'); | ||
* console.error(toolRun.action_type, ' => ', toolRun.action_url); | ||
* break; | ||
* } | ||
* } | ||
*/ | ||
@@ -187,3 +212,3 @@ async runTool({ | ||
/** | ||
* Manage connections | ||
* Get link to users connections | ||
* | ||
@@ -195,6 +220,6 @@ * Fetches a configuration link for the user to manage connections in the Superface. | ||
* @example | ||
* const connections = await superface.toolConnections({ userId: 'example_user' }); | ||
* redirect(connections.configuration_url); | ||
* const link = await superface.linkToUserConnections({ userId: 'example_user' }); | ||
* redirect(link.url); | ||
*/ | ||
async toolConnections({ | ||
async linkToUserConnections({ | ||
userId | ||
@@ -220,3 +245,7 @@ }) { | ||
const body = await response.json(); | ||
return body; | ||
return { | ||
status: body.status, | ||
url: body.configuration_url, | ||
assistant_hint: body.assistant_hint | ||
}; | ||
} catch (err) { | ||
@@ -223,0 +252,0 @@ lastError = new SuperfaceError( |
@@ -12,2 +12,7 @@ import { ChatCompletionToolMessageParam, ChatCompletionTool } from 'openai/resources/index.mjs'; | ||
}; | ||
/** | ||
* Tool run failed | ||
* | ||
* The tool run ended with an error. | ||
*/ | ||
type ToolRunError = ToolRunAsistantHint & { | ||
@@ -17,2 +22,8 @@ status: 'error'; | ||
}; | ||
/** | ||
* Tool run requires action | ||
* | ||
* The response requires an action from the user. | ||
* For example, the user may need to connect (authenticate) an 3rd party account. | ||
*/ | ||
type ToolRunActionRequired = ToolRunAsistantHint & { | ||
@@ -23,8 +34,29 @@ status: 'requires_action'; | ||
}; | ||
/** | ||
* Tool run response | ||
* | ||
* Superface responses are either successful, failed, or require action. | ||
* The response contains an assistant hint that can help LLM understand the result and what to do next. | ||
* | ||
*/ | ||
type ToolRun<TResult = unknown> = ToolRunSuccess<TResult> | ToolRunError | ToolRunActionRequired; | ||
type ToolConnectionsRespnose = { | ||
/** | ||
* Response with a link to the user's connections | ||
*/ | ||
type UserConnectionsLink = { | ||
status: 'success'; | ||
configuration_url: string; | ||
url: string; | ||
assistant_hint: string; | ||
}; | ||
/** | ||
* Tool definition | ||
* | ||
* Currenty only function tools are supported. | ||
* | ||
* @param type Type of the tool (currently only 'function' is supported) | ||
* @param function Function tool definition | ||
* @param function.name Name of the tool | ||
* @param function.description Description of the tool | ||
* @param function.parameters Parameters of the tool. Defined as JSON schema. | ||
*/ | ||
type ToolDefinition = { | ||
@@ -58,2 +90,8 @@ type: 'function'; | ||
}; | ||
/** | ||
* Generic error thrown by the Superface client | ||
* | ||
* This should make intercepting errors easier. | ||
* To access the original error, use the `originalError` property. | ||
*/ | ||
declare class SuperfaceError extends Error { | ||
@@ -68,15 +106,16 @@ originalError?: unknown; | ||
/** | ||
* Superface intelligent tools | ||
* Superface HTTP Client | ||
* | ||
* @param opts {SuperfaceOptions} Options for the Superface client | ||
* Low level client for the Superface API. | ||
* Consider using framework-specific clients. | ||
* | ||
* @example | ||
* import Superface from '@superfaceai/client'; | ||
* const client = new Superface({ apiKey }); | ||
* const superface = new Superface({ apiKey }); | ||
* | ||
* // Get and pass the tools to the LLM Call | ||
* const tools = await client.getTools(); | ||
* const tools = await superface.getTools(); | ||
* | ||
* // Once the LLM Call is done, check messages for tool calls and run them | ||
* const result = await client.runTool({ userId, name, args }); | ||
* const result = await superface.runTool({ userId, name, args }); | ||
*/ | ||
@@ -115,2 +154,27 @@ declare class Superface$1 { | ||
* @throws {SuperfaceError} | ||
* | ||
* @example | ||
* const toolRun = await superface.runTool({ | ||
* userId: 'example_user', | ||
* name: toolCall.function.name, | ||
* args: JSON.parse(toolCall.function.arguments), | ||
* }); | ||
* | ||
* switch (toolRun.status) { | ||
* case 'success': { | ||
* console.log('✅', 'Tool run successful'); | ||
* console.log(toolRun.result); | ||
* break; | ||
* } | ||
* case 'error': { | ||
* console.error('❌', 'Tool run failed'); | ||
* console.error(toolRun.error); | ||
* break; | ||
* } | ||
* case 'requires_action': { | ||
* console.error('❗', 'Tool run requires action'); | ||
* console.error(toolRun.action_type, ' => ', toolRun.action_url); | ||
* break; | ||
* } | ||
* } | ||
*/ | ||
@@ -123,3 +187,3 @@ runTool<TArgs extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>({ userId, name, args, }: { | ||
/** | ||
* Manage connections | ||
* Get link to users connections | ||
* | ||
@@ -131,13 +195,38 @@ * Fetches a configuration link for the user to manage connections in the Superface. | ||
* @example | ||
* const connections = await superface.toolConnections({ userId: 'example_user' }); | ||
* redirect(connections.configuration_url); | ||
* const link = await superface.linkToUserConnections({ userId: 'example_user' }); | ||
* redirect(link.url); | ||
*/ | ||
toolConnections({ userId, }: { | ||
linkToUserConnections({ userId, }: { | ||
userId: string; | ||
}): Promise<ToolConnectionsRespnose>; | ||
}): Promise<UserConnectionsLink>; | ||
} | ||
/** | ||
* Superface for OpenAI's beta API. | ||
*/ | ||
declare class SuperfaceOpenAIBeta { | ||
private client; | ||
constructor(superface: Superface); | ||
/** | ||
* Get tools definitions to be used with convinience wrapper for automatic tool calls handling, | ||
* | ||
* Read more in OpenAI's [docs](https://github.com/openai/openai-node#automated-function-calls) | ||
* | ||
* @param userId User ID | ||
* | ||
* @example | ||
* const openai = new OpenAI(); | ||
* const superface = new Superface(); | ||
* const runner = openai.beta.chat.completions | ||
* .runTools({ | ||
* model: 'gpt-4o', | ||
* messages: [{ role: 'user', content: 'What tools do you have?' }], | ||
* tools: await superface.beta.getTools({ userId: 'example_user' }), | ||
* }) | ||
* .on('message', (message) => console.log(message)); | ||
* | ||
* const finalContent = await runner.finalContent(); | ||
* console.log(); | ||
* console.log('Final content:', finalContent); | ||
*/ | ||
getTools({ userId }: { | ||
@@ -157,2 +246,7 @@ userId: string; | ||
/** | ||
* Result of a tool run. | ||
* | ||
* Allows to interact with original response or format result to a message. | ||
*/ | ||
declare class ToolRunResult<T = unknown> { | ||
@@ -171,9 +265,50 @@ private toolCall; | ||
} | ||
/** | ||
* Superface for OpenAI's API. | ||
* | ||
* To be used with [OpenAI TypeScript and JavaScript API Library](https://github.com/openai/openai-node). | ||
* | ||
* @example | ||
* const superface = new Superface(); | ||
* | ||
* const chatCompletion = await openai.chat.completions.create({ | ||
* model: 'gpt-4o', | ||
* tools: await superface.getTools(), | ||
* messages, | ||
* }); | ||
* | ||
* const toolRunResults = await superface.handleToolCalls({ | ||
* userId: 'example_user', | ||
* message: chatCompletion.choices[0].message, | ||
* }); | ||
*/ | ||
declare class Superface { | ||
client: Superface$1; | ||
beta: SuperfaceOpenAIBeta; | ||
constructor(opts?: SuperfaceOptions & { | ||
client?: Superface$1; | ||
constructor(opts?: SuperfaceOptions | { | ||
client: Superface$1; | ||
}); | ||
/** | ||
* Get tools definitions | ||
* | ||
* Then pass the tools to the OpenAI API. | ||
* | ||
* @example | ||
* const chatCompletion = await openai.chat.completions.create({ | ||
* model: 'gpt-4o', | ||
* tools: await superface.getTools(), | ||
* messages, | ||
* }); | ||
*/ | ||
getTools(): Promise<ChatCompletionTool[]>; | ||
/** | ||
* Handle all tool calls in a chat completion message. | ||
* | ||
* @example | ||
* const toolRunResults = await superface.handleToolCalls({ | ||
* userId: 'example_user', | ||
* message: chatCompletion.choices[0].message, | ||
* }); | ||
* const toolMessages = toolRunResults.map((result) => result.toMessage()); | ||
*/ | ||
handleToolCalls<T = unknown>({ userId, message, }: { | ||
@@ -183,2 +318,14 @@ userId: string; | ||
}): Promise<ToolRunResult[]>; | ||
/** | ||
* Run tool call. | ||
* | ||
* Take tool call and run it. | ||
* To handle all tool calls in a chat completion message, use `handleToolCalls`. | ||
* | ||
* @example | ||
* const toolRunResult = superface.runTool({ | ||
* userId: 'example_user', | ||
* toolCall: chatCompletion.choices[0].message.tool_calls[0], | ||
* }); | ||
*/ | ||
runTool<T = unknown>({ userId, toolCall, }: { | ||
@@ -188,5 +335,16 @@ userId: string; | ||
}): Promise<ToolRunResult<T>>; | ||
toolConnections(...args: Parameters<Superface$1['toolConnections']>): ReturnType<Superface$1['toolConnections']>; | ||
/** | ||
* Get link to users connections | ||
* | ||
* Fetches a configuration link for the user to manage connections in the Superface. | ||
* | ||
* @throws {SuperfaceError} | ||
* | ||
* @example | ||
* const link = await superface.linkToUserConnections({ userId: 'example_user' }); | ||
* redirect(link.url); | ||
*/ | ||
linkToUserConnections(...args: Parameters<Superface$1['linkToUserConnections']>): ReturnType<Superface$1['linkToUserConnections']>; | ||
} | ||
export { Superface, SuperfaceError, type SuperfaceOptions, ToolRunResult, Superface as default, isUserIdValid }; |
@@ -128,2 +128,27 @@ "use strict"; | ||
* @throws {SuperfaceError} | ||
* | ||
* @example | ||
* const toolRun = await superface.runTool({ | ||
* userId: 'example_user', | ||
* name: toolCall.function.name, | ||
* args: JSON.parse(toolCall.function.arguments), | ||
* }); | ||
* | ||
* switch (toolRun.status) { | ||
* case 'success': { | ||
* console.log('✅', 'Tool run successful'); | ||
* console.log(toolRun.result); | ||
* break; | ||
* } | ||
* case 'error': { | ||
* console.error('❌', 'Tool run failed'); | ||
* console.error(toolRun.error); | ||
* break; | ||
* } | ||
* case 'requires_action': { | ||
* console.error('❗', 'Tool run requires action'); | ||
* console.error(toolRun.action_type, ' => ', toolRun.action_url); | ||
* break; | ||
* } | ||
* } | ||
*/ | ||
@@ -189,3 +214,3 @@ async runTool({ | ||
/** | ||
* Manage connections | ||
* Get link to users connections | ||
* | ||
@@ -197,6 +222,6 @@ * Fetches a configuration link for the user to manage connections in the Superface. | ||
* @example | ||
* const connections = await superface.toolConnections({ userId: 'example_user' }); | ||
* redirect(connections.configuration_url); | ||
* const link = await superface.linkToUserConnections({ userId: 'example_user' }); | ||
* redirect(link.url); | ||
*/ | ||
async toolConnections({ | ||
async linkToUserConnections({ | ||
userId | ||
@@ -222,3 +247,7 @@ }) { | ||
const body = await response.json(); | ||
return body; | ||
return { | ||
status: body.status, | ||
url: body.configuration_url, | ||
assistant_hint: body.assistant_hint | ||
}; | ||
} catch (err) { | ||
@@ -249,2 +278,24 @@ lastError = new SuperfaceError( | ||
} | ||
/** | ||
* Get tools definitions to be used with convinience wrapper for automatic tool calls handling, | ||
* | ||
* Read more in OpenAI's [docs](https://github.com/openai/openai-node#automated-function-calls) | ||
* | ||
* @param userId User ID | ||
* | ||
* @example | ||
* const openai = new OpenAI(); | ||
* const superface = new Superface(); | ||
* const runner = openai.beta.chat.completions | ||
* .runTools({ | ||
* model: 'gpt-4o', | ||
* messages: [{ role: 'user', content: 'What tools do you have?' }], | ||
* tools: await superface.beta.getTools({ userId: 'example_user' }), | ||
* }) | ||
* .on('message', (message) => console.log(message)); | ||
* | ||
* const finalContent = await runner.finalContent(); | ||
* console.log(); | ||
* console.log('Final content:', finalContent); | ||
*/ | ||
async getTools({ userId }) { | ||
@@ -319,8 +370,30 @@ const tools = await this.client.getTools(); | ||
constructor(opts = {}) { | ||
this.client = new client_default(opts); | ||
this.client = "client" in opts ? opts.client : new client_default(opts); | ||
this.beta = new SuperfaceOpenAIBeta(this); | ||
} | ||
/** | ||
* Get tools definitions | ||
* | ||
* Then pass the tools to the OpenAI API. | ||
* | ||
* @example | ||
* const chatCompletion = await openai.chat.completions.create({ | ||
* model: 'gpt-4o', | ||
* tools: await superface.getTools(), | ||
* messages, | ||
* }); | ||
*/ | ||
async getTools() { | ||
return await this.client.getTools(); | ||
} | ||
/** | ||
* Handle all tool calls in a chat completion message. | ||
* | ||
* @example | ||
* const toolRunResults = await superface.handleToolCalls({ | ||
* userId: 'example_user', | ||
* message: chatCompletion.choices[0].message, | ||
* }); | ||
* const toolMessages = toolRunResults.map((result) => result.toMessage()); | ||
*/ | ||
async handleToolCalls({ | ||
@@ -342,2 +415,14 @@ userId, | ||
} | ||
/** | ||
* Run tool call. | ||
* | ||
* Take tool call and run it. | ||
* To handle all tool calls in a chat completion message, use `handleToolCalls`. | ||
* | ||
* @example | ||
* const toolRunResult = superface.runTool({ | ||
* userId: 'example_user', | ||
* toolCall: chatCompletion.choices[0].message.tool_calls[0], | ||
* }); | ||
*/ | ||
async runTool({ | ||
@@ -354,4 +439,15 @@ userId, | ||
} | ||
async toolConnections(...args) { | ||
return await this.client.toolConnections(...args); | ||
/** | ||
* Get link to users connections | ||
* | ||
* Fetches a configuration link for the user to manage connections in the Superface. | ||
* | ||
* @throws {SuperfaceError} | ||
* | ||
* @example | ||
* const link = await superface.linkToUserConnections({ userId: 'example_user' }); | ||
* redirect(link.url); | ||
*/ | ||
async linkToUserConnections(...args) { | ||
return await this.client.linkToUserConnections(...args); | ||
} | ||
@@ -358,0 +454,0 @@ }; |
{ | ||
"name": "superface", | ||
"version": "0.1.0-rc.1", | ||
"version": "0.1.0-rc.2", | ||
"description": "Intelligent Tools for Agentic AI", | ||
"author": "Superface Team <hello@superface.ai>", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/superfaceai/sdk" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"ai", | ||
"agents", | ||
"tools" | ||
], | ||
"exports": { | ||
@@ -37,8 +46,8 @@ "./client": { | ||
}, | ||
"peerDependencies": { | ||
"openai": "^4.75.0" | ||
}, | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"peerDependencies": { | ||
"openai": "^4.75.0" | ||
} | ||
] | ||
} |
@@ -1,89 +0,41 @@ | ||
# Superface SDK - TypeScript | ||
**TypeScript** | Python (soon) | ||
## Install | ||
# <img src="https://github.com/superfaceai/sdk/raw/main/docs/logos/typescript.png" alt="TypeScript" width="30" height="30" /> Superface SDK | ||
```sh | ||
npm install superface | ||
``` | ||
[Superface SDK](https://superface.ai) lets you integrate external apps with your AI agent using function calling. | ||
## Use | ||
Out of box: | ||
- intelligent tools | ||
- managed OAuth | ||
- complete end-user auth flows. | ||
### Superface Client | ||
## Installation | ||
```ts | ||
// import client | ||
import Superface from 'superface/client'; | ||
// create instance | ||
const superface = new Superface(); | ||
// get tools definitions | ||
const tools = await superface.getTools(); | ||
// format and pass tools to LLM | ||
const response = await callLLM({ | ||
tools: tools.map(tool => ({ ... })), | ||
prompt: '...' | ||
}); | ||
// handle tool calls | ||
for (const toolCall of response.toolCalls) { | ||
const toolRun = await superface.runTool({ | ||
userId: 'example_user', | ||
name: toolCall.function.name, | ||
args: JSON.parse(toolCall.function.arguments), | ||
}); | ||
} | ||
```sh | ||
npm install superface | ||
``` | ||
Let users manage tool connections | ||
```ts | ||
const connections = await superface.toolConnections({ userId: 'example_user' }); | ||
redirect(connections.configuration_url); | ||
``` | ||
## Usage with AI frameworks | ||
### With OpenAI | ||
### [<img src="https://github.com/superfaceai/sdk/raw/main/docs/logos/openai.png" alt="OpenAI" width="16" height="16"> OpenAI →](./src/openai/) | ||
```ts | ||
// import SDK | ||
import Superface from 'superface/openai'; | ||
import OpenAI from 'openai'; | ||
### [<img src="https://github.com/superfaceai/sdk/raw/main/docs/logos/client.png" alt="Superface" width="16" height="16"> HTTP Client →](./src/client/) | ||
// Create instance | ||
const superface = new Superface(); | ||
const openai = new OpenAI(); | ||
### <img src="https://github.com/superfaceai/sdk/raw/main/docs/logos/anthropic.png" alt="Anthropic" width="16" height="16"> Anthropic (soon) | ||
const messages: ChatCompletionMessageParam[] = [ | ||
{ role: 'user', content: '...' }, | ||
]; | ||
### <img src="https://github.com/superfaceai/sdk/raw/main/docs/logos/langchain.png" alt="LangChain" width="16" height="16"> LangChain (soon) | ||
// Call OpenAI with Superface tools | ||
const chatCompletion = await openai.chat.completions.create({ | ||
model: 'gpt-4o', | ||
tools: await superface.getTools(), | ||
messages, | ||
}); | ||
const message = chatCompletion.choices[0].message; | ||
messages.push(message); | ||
### <img src="https://github.com/superfaceai/sdk/raw/main/docs/logos/vercel_ai.png" alt="Vercel AI SDK" width="16" height="16"> Vercel AI SDK (soon) | ||
// handle tool calls | ||
for (const toolCall of message.tool_calls ?? []) { | ||
const toolRunResult = await superface.runTool({ | ||
userId: 'example_user', | ||
toolCall, | ||
}); | ||
messages.push(toolRunResult.toMessage()); | ||
} | ||
``` | ||
### <img src="https://github.com/superfaceai/sdk/raw/main/docs/logos/llamaindex.png" alt="Llamaindex" width="16" height="16"> Llamaindex (soon) | ||
### Examples | ||
## Examples | ||
For more examples see [typescript/examples](./examples) folder. | ||
See all examples in [typescript/examples](./examples) folder. | ||
## Environemt variables | ||
- [Simple chat using OpenAI SDK with tool calling](./examples/openai/handle-tool-calls/) | ||
- [Using OpenAI's beta tool runner](./examples/openai/beta-automated-function-calls/) | ||
`SUPERFACE_API_KEY` this value is used to authenticate clients to Superface API | ||
## License | ||
`SUPERFACE_CACHE_TIMEOUT` Set in miliseconds to change cache of tools definitions. By default they are valid for 60000ms. | ||
`SUPERFACE_MAX_RETRIES` Max retries to communicate with Superface servers. affects `getTools` and `runTool` functions. | ||
This project is licensed under the MIT license. See the [LICENSE](../LICENSE) file for details. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
161481
1915
0
12
41