run = client.beta.threads.create_and_run(
assistant_id=“asst_IgmpQTah3ZfPHCVZjTqAY8Kv”,
thread={
“messages”: [
{“role”: “user”, “content”: “Explain deep learning to a 5 year old.”}
]
}
)
` The error I’m getting is: line 3, in
openai.api_key = “■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■VqeUz38Y”
NameError: name ‘openai’ is not defined. Did you mean: ‘OpenAI’? I don’t know what I’m doing wrong, I just can’t import OpenAI.
seeing the same type of results in my tests using what was documented for the api. I used the math example and this was the results.: PS E:\Ai\AIUI\Izzy> python test.py
Traceback (most recent call last):
File “E:\Ai\AIUI\Izzy\test.py”, line 7, in
assistant = openai.Assistant.create(
^^^^^^^^^^^^^^^^
AttributeError: module ‘openai’ has no attribute ‘Assistant’
PS E:\Ai\AIUI\Izzy>
did a pip upgrade as well on open.ai to be sure that there was not a new version.
import openai
Make sure to use your own API key and keep it secure
openai.api_key = ‘xxxxx’
Step 1: Create an Assistant
assistant = openai.Assistant.create(
name=“Math Tutor”,
instructions=“You are a personal math tutor. Write and run code to answer math questions.”,
tools=[{“type”: “code_interpreter”}],
model=“gpt-4-1106-preview”
)
Step 2: Create a Thread
thread = openai.Thread.create()
Step 3: Add a Message to a Thread
message = openai.Message.create(
thread_id=thread.id,
role=“user”,
content=“I need to solve the equation 3x + 11 = 14. Can you help me?”
)
Step 4: Run the Assistant
run = openai.Run.create(
assistant_id=assistant.id,
thread_id=thread.id
)
assistant = client.beta.assistants.create(
name=“Math Tutor”,
instructions=“You are a personal math tutor. Write and run code to answer math questions.”,
tools=[{“type”: “code_interpreter”}],
model=“gpt-4-1106-preview”
)
I’m still getting this error: line 3, in
from openai import OpenAI
ImportError: cannot import name ‘OpenAI’ from ‘openai’ (/home/pi/.local/lib/python3.9/site-packages/openai/init.py)
It seems to be working now. I was able to upload a csv file, with both code int and retrieval on, and it finally works.
I had been trying all day and the only workaround I found was to disable the retrieval tool: i was then able to upload the desired doc and chat with it. If it’s still not working for you, try that
I don’t think that’s the problem; I just can’t import OpenAI: line 3, in
from openai import OpenAI
ImportError: cannot import name ‘OpenAI’ from ‘openai’ (/home/pi/.local/lib/python3.9/site-packages/openai/init.py)
UPDATE: Now, its working on my PC, but I need it to run on a Pi for a project I’m working on. Does anyone know how to fix that? The error for the pi: line 3, in
from openai import OpenAI
ImportError: cannot import name ‘OpenAI’ from ‘openai’ (/home/pi/.local/lib/python3.9/site-packages/openai/init.py) No error on the PC: Assistant(id=‘asst_xHQVmjMR4LIiXJxVcFEmwswW’, created_at=1699553110, description=None, file_ids=, instructions=‘You are a personal math tutor. Write and run code to answer math questions.’, metadata={}, model=‘gpt-4-1106-preview’, name=‘Math Tutor’, object=‘assistant’, tools=[ToolCodeInterpreter(type=‘code_interpreter’)])