-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
57 lines (48 loc) · 1.55 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Create a Retrieval Assistant
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI()
# Step 1. Upload the file
file = client.files.create(file=open("bean-there-cafe.pdf", "rb"), purpose="assistants")
# Step 2. Create the Assistant
assistant = client.beta.assistants.create(
instructions="You are a chatbot for Bean There Café, and you have access to files to answer questions about the company.",
name="Bean There Café Bot",
tools=[{"type": "retrieval"}],
model="gpt-4-1106-preview",
file_ids=[file.id],
)
print(assistant)
# Step 3. Create a Thread
thread = client.beta.threads.create()
# Step 4. Create a message
message = client.beta.threads.messages.create(
thread_id='',
role="user",
content="How long will it take us to be profitable at our current monthly revenue if it stays consistent and how long will it take to make back the startup costs?",
)
print(message)
# Step 5. Run the Assistant
run = client.beta.threads.runs.create(
thread_id="", assistant_id=""
)
print(run)
# Step 6. Retrieve the run
run = client.beta.threads.runs.retrieve(
thread_id="",
run_id=""
)
print(run)
# Step 7. Check the messages
thread_messages = client.beta.threads.messages.list("")
print(thread_messages.data[1])
for message in thread_messages.data:
for content in message.content:
print(content.text.value)
# Step 8. Modify the Assistant
assistant = client.beta.assistants.update(
assistant_id='',
tools=[{"type": "retrieval"}, {"type": "code_interpreter"}],
)
print(assistant)