diff --git a/README.md b/README.md index e5bc23c5..158d97ae 100644 --- a/README.md +++ b/README.md @@ -86,82 +86,58 @@ import { StackOneToolSet } from "@stackone/ai"; import * as path from "path"; // Initialize with API key and account ID -const toolset = new StackOneToolSet( - process.env.STACKONE_API_KEY, - process.env.STACKONE_ACCOUNT_ID -); +const toolset = new StackOneToolSet(); const tools = toolset.getTools("documents_*"); const uploadTool = tools.getTool("documents_upload_file"); // Upload a file using the file_path parameter const result = await uploadTool.execute({ - file_path: path.join(__dirname, "document.pdf"), // Path to the file + file_path: "/path/to/document.pdf", // Path to the file }); + +The name, file format, and content of the file are automatically extracted from the path. ``` -### Using with OpenAI or AI SDK +## Integrations -When using file upload tools with OpenAI or AI SDK, the parameters are automatically simplified to a single `file_path` parameter: +### OpenAI ```typescript +import { OpenAI } from "openai"; import { StackOneToolSet } from "@stackone/ai"; -import OpenAI from "openai"; -// Initialize with API key and account ID -const toolset = new StackOneToolSet( - process.env.STACKONE_API_KEY, - process.env.STACKONE_ACCOUNT_ID -); -const tools = toolset.getTools("documents_*"); +const openai = new OpenAI(); +const toolset = new StackOneToolSet(); -// Convert to OpenAI functions -const openAITools = tools.toOpenAI(); - -// The file upload tool will have a simplified schema with just a file_path parameter -// { -// "type": "function", -// "function": { -// "name": "documents_upload_file", -// "description": "Upload a document file", -// "parameters": { -// "type": "object", -// "properties": { -// "file_path": { -// "type": "string", -// "description": "Path to the file to upload. The filename will be extracted from the path." -// } -// }, -// "required": ["file_path"] -// } -// } -// } - -// Use with OpenAI -const openai = new OpenAI({ - apiKey: process.env.OPENAI_API_KEY, -}); +const tools = toolset.getTools("hris_*"); +const tool = tools.getTool("hris_list_employees"); -const response = await openai.chat.completions.create({ +const result = await completionTool.execute({ model: "gpt-4o-mini", - messages: [ - { role: "system", content: "You are a helpful assistant." }, - { role: "user", content: "Upload this document: /path/to/document.pdf" }, - ], - tools: openAITools, + prompt: "What are the names of the employees?", + tools: [tool.toOpenAI()], }); - -// When OpenAI calls the tool with the file_path parameter -// The SDK automatically handles: -// 1. Extracting the filename from the path -// 2. Determining the file format from the extension -// 3. Reading and encoding the file -// 4. Sending it to the API with the correct parameters ``` -## Integrations +### AI SDK by Vercel -### OpenAI +```typescript +import { openai } from "@ai-sdk/openai"; +import { generateText } from "ai"; +import { StackOneToolSet } from "@stackone/ai"; -``` +// Initialize StackOne +const toolset = new StackOneToolSet(); +const tools = toolset.getTools("hris_*", "your-account-id"); +// Convert to AI SDK tools +const aiSdkTools = tools.toAISDKTools(); + +// Use with AI SDK +const { text } = await generateText({ + model: openai("gpt-4o-mini"), + tools: aiSdkTools, + prompt: "Get employee details for John Doe", + maxSteps: 3, // Automatically calls tools when needed +}); ```