Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from openai import OpenAI client = OpenAI ( ) assistant = client.beta.assistants.create ( name = Python Assistant, instructions = you're a python teaching assistant. you

from openai import OpenAI
client = OpenAI()
assistant = client.beta.assistants.create(
name = "Python Assistant",
instructions = "you're a python teaching assistant. you have mastered the rules of python.You will answer the questions asked to you clearly and clearly according to the oython rules.",
model ="gpt-3.5-turbo-1106",
tools =[{"type": "file_search"}],
)
vector_store = client.beta.vector_stores.create(
name="Personal Data",
expires_after={
"anchor": "last_active_at",
"days" : 1
}
)
file_paths =["data.txt"]
file_streams =[open(path ,"rb") for path in file_paths]
print(file_batch.status)
print(file_batch.file_counts)
assistant = client.beta.assistants.update(
assistant_id=assistant.id,
tool_resources={"file_search":{"vector_store_ids": [vector_store.id]}},
)
thread = client.beta.threads.create(
tool_resources={"file_search": {"vector_store_ids": [vector_store.id]}},
messages=[
{
"role":"user",
"content":"What is functions?",
}
]
)
print(thread.tool_resources.file_search)
run = client.beta.threads.runs.create_and_poll(
thread_id=thread.id, assistant_id=assistant.id
)
messages = list(client.beta.threads.messages.list(thread_id=thread.id, run_id=run.id))
message_content = messages[0].content[0].text
annotations = message_content.annotations
citations =[]
for index, annotation in enumerate(annotations):
message_content.value = message_content.value.replace(annotation.text, f"[{index}]")
if (file_citation := getattr(annotation, "file_citation", None)):
cited_file= client.files.retrieve(file_citation.file_id)
citations.append(f"[{index}]{cited_file.filename}")
print(message_content.value)
print("
".join(citations)) "file_batch" is not definedPylancereportUndefinedVariable

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

Identify and describe basic workplace competencies

Answered: 1 week ago

Question

Describe the steps involved in coaching to improve poor performance

Answered: 1 week ago