Replace your OpenAI import and add the OpenFiles API key:
Copy
import OpenAI from '@openfiles-ai/sdk/openai' // Changed from 'openai'const ai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, openFilesApiKey: process.env.OPENFILES_API_KEY // Add this line})const response = await ai.chat.completions.create({ model: 'gpt-4', messages: [{ role: 'user', content: 'Create a shopping list for making chocolate chip cookies and save it as shopping-list.md' }]})console.log(response.choices[0].message.content)
Your AI can now create, read, and edit files automatically. The agent will use file operations when it determines they’re needed based on the user’s request.
// Create a file"Create a shopping list for making chocolate chip cookies and save it as shopping-list.md"// Read a file "Read the shopping-list.md file and tell me what's in it"// Edit a file"Add butter and vanilla extract to my shopping list"// List files"Show me all the files I've created"