Hi,
I tried creating a GPT by uploading a PDF. It worked well from the UI and was able to answer questions. But when I sent the link to some one they need to be ChatGPT plus users to use it. So I tried using an API and linking assistant with ChatCompletion end point but that kept on giving me errors. I also tried passing file id to chatCompletion but that did not work. Below are relevant code snippets - please guide on suitable approach.
file = client.files.create(
file=open(“mydoc.pdf”, “rb”),
purpose=‘assistants’
)
Add the file to the assistant
assistant = client.beta.assistants.create(
instructions="You will answer question on the pdf document that I have uploaded. … ",
model=“gpt-4-1106-preview”,
tools=[{“type”: “retrieval”}],
file_ids=[file.id]
)
while True:
# Get user input
user_input = input("You: ") #followed by exit code
#using assitant with chat
‘’’
response = client.assistants.chat(
assistant_id=assistant_id,
messages=[{“role”: “user”, “content”: user_input}]
)
‘’’
#using file id with ChatCompletion
response = client.ChatCompletion.create(
model=“gpt-4-1106-preview”,
messages=[
{“role”: “system”, “content”: “You will answer question on the pdf document that I have uploaded. …”},
{“role”: “user”, “content”: user_input}
],
file=file.id
)
Regards
dbeings