At my openai API account, I’ve created an Assistant with its own System Role instructions and vectored set of uploaded txt files, and I have its Assistant ID. I also have my API key.
I want to set up a simple chatbot that can answer queries from user as to its aforementioned knowledge.
After days of research and chats with chatgpt-4o, I simply have not found any way to set that up using html, JavaScript and/or python. All attempts didn’t work. The endpoint method itself seems unknown. Can someone please very kindly direct me to a template example of the use of an Assistant ID to chat with that Assistant? I can then at the least simply adapt that template to my situation.
It’s been confounding but I hope someone may be able to kindly help! Thankyou.
Have you seen the example in the cookbook? It will guide you through the process of building an assistant using the API and from there you can build a webinterface on top.
If this is not helpful, maybe you need to point me toward the problem again.
I hope this helps.
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",
)
show_json(assistant)
i got the error:
from openai import OpenAI
ImportError: cannot import name ‘OpenAI’ from ‘openai’
response = openai.Assistant.create(
AttributeError: module ‘openai’ has no attribute ‘Assistant’
is here any version wrong? thank you! i already pip install openai
update
import openai
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("SECRET_KEY")
if api_key is None:
raise ValueError("SECRET_KEY not found in .env file")
openai.api_key = api_key
response = openai.ChatCompletion.create(
model="gpt-4-1106-preview",
messages=[
{"role": "system", "content": "You are a personal math tutor. Answer questions briefly, in a sentence or less."},
{"role": "user", "content": "What is the derivative of x^2?"},
]
)
print(response.choices[0].message['content'])
here my correct code, but i can’t understand the wrong T_T
However nothing so far is jumping out at me there as a solution to this.
All i’m looking for is a way to make a chatbot using the Assistant I’ve already created at my openai API account. It seems this is not easily conveyed in any openai documentation. Any further simple template that you might be able to share would be incredibly useful. This would entail simple use of the API key and the Assistant ID, making a self-contained Thread that enables a back-and-forth chat possible between user and the Assistant (which has been created and set up already with its own vectored knowledge files).
You have probably seen that the example starts with creating an assistant via the playground.
In the next step a thread is created and then a run initiated. My apologies if I am looking in the wrong direction here but isn’t that what you are looking for?
Edit: I have an idea. You can follow the example process from step 1, again creating a new example assistant. But you follow the process all the way to the end and then when it works you change the assistant and thread ID with the real IDs respectively. That should do it.