Attachments
Pearl API allows attaching documents and images to chat conversations for use by the Assistant or Expert.
At first, the files should be uploaded via https://api.pearl.com/api/v1/file endpoint and then attached to a new message before posting.
from uuid import uuid4
from openai import OpenAI
client = OpenAI(
api_key="PEARL_API_KEY",
base_url="https://api.pearl.com/api/v1/"
)
session_id = str(uuid4()) # Generate a unique GUID
# Upload a file
file = client.files.create(
file=open("image.png", "rb"),
extra_body={"sessionId": session_id },
purpose="attachment"
)
response = client.chat.completions.create(
model="pearl-ai",
messages=[
{
"role": "user",
"content": "What's on the image?",
"attachments": [file.id] # Identify the id of the uploaded files
}
],
metadata={"sessionId": session_id}
)
print(response.choices[0].message)