#Hello
1 messages · Page 1 of 1 (latest)
Hi @wary sentinel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Sure, I'd be happy to help you with the Assistants API. Here's a brief overview:
The Assistants API is a tool developed by OpenAI that allows developers to build powerful AI assistants within their applications. An assistant represents a purpose-built AI that uses OpenAI’s models and can access files, maintain persistent threads, and call tools. The API currently supports three types of tools: Code Interpreter, File Search, and Function calling[^1^][^2^][^4^].
A typical integration of the Assistants API has the following flow[^4^]:
- Create an Assistant by defining its custom instructions and picking a model. If helpful, add files and enable tools like Code Interpreter, File Search, and Function calling.
- Create a Thread when a user starts a conversation.
- Add Messages to the Thread as the user asks questions.
- Run the Assistant on the Thread to generate a response by calling the model and the tools.
Here's an example of how to create an Assistant using Python[^5^]:
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY", "<your OpenAI API key if not set as env var>"))
assistant = client.beta.assistants.create(
name="Math Tutor",
instructions="You are a personal math tutor. Answer questions briefly, in a sentence or less.",
model="gpt-4-1106-preview",
)
You can also explore the capabilities of the Assistants API using the Assistants playground[^4^] or check out the Playground for the Assistants API[^9^].
If you're migrating from the old Assistants API beta version (v1) to the new one (v2), you can check out this migration guide[^9^].
If you're getting an error, it might mean that your prompt is not set up correctly. Here are some things to try[^9^]:
- Make sure to restructure your prompt to treat any function-like commands as functions
- Add any commands in your prompt as a function to
tools
For more detailed information, you can refer to the official documentation[^4^] or check out this YouTube tutorial[^10^].
^1^]: [Source (https://help.openai.com/en/articles/8550641-assistants-api-v2-faq)
^2^]: [Source (https://help.openai.com/en/articles/8673914-gpts-vs-assistants#h_5740051b75)
^4^]: [Source (https://platform.openai.com/docs/assistants/overview)
^5^]: [Source (https://cookbook.openai.com/examples/assistants_api_overview_python#assistants)
^9^]: [Source (https://help.openai.com/en/articles/8550641-assistants-api-v2-faq#h_c8ff59051b)
^10^]: [Source (https://community.openai.com/t/512975)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@wary sentinel kapa.ai is still learning and improving, please let us know how it did by reacting below
Do openAI assistants now support streaming? I think with the recent update they added that. I'm coding in nodeJS.
Do openAI assistants now support streaming? I think with the recent update they added that. I'm coding in nodeJS.
@manic moss please respond
Let me check the knowledge base for you. One moment! :books:
Of course, I'm here to help! Could you please provide more details about the specific issue or question you have regarding the Assistants API? This will help me provide a more accurate and helpful response.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@wary sentinel kapa.ai is still learning and improving, please let us know how it did by reacting below
@manic moss Do openAI assistants now support streaming? I think with the recent update they added that. I'm coding in nodeJS.
Let me check the knowledge base for you. One moment! :books:
Yes, you're correct. As of the update on March 14th, 2024, OpenAI has added support for streaming in the Assistants API[^1^]. This means you can now stream responses from the assistant in real-time, which can be particularly useful for creating more interactive and responsive applications.
In addition to this, OpenAI has also added several streaming and polling helpers to their Node SDK[^4^][^5^]. This should make it easier for you to implement streaming in your Node.js application.
Here's an example of how you might use the streaming feature in Node.js, based on a code snippet from a related GitHub issue[^6^]:
import OpenAI from "openai";
async function a() {
const openai = new OpenAI({ apiKey: "<Your API Key>" })
const threadID = (await openai.beta.threads.create()).id;
await openai.beta.threads.messages.create(threadID, {
role: "user",
content: "Hi"
});
const assistant_id = "<Your Assistant ID>"
const assistantStream = await openai.beta.threads.runs.create(threadID, { assistant_id, stream: true });
for await (const event of assistantStream) {
console.log("Event: ", event) // Single character from system prompt
console.log("Event:Data:", event.data) // null
console.log("Event:Event:", event.event) // null
}
}
Please replace <Your API Key> and <Your Assistant ID> with your actual API key and Assistant ID.
For more detailed information on how to use the streaming feature, you can refer to the official OpenAI documentation[^4^].