Prerequisites
Make sure you have a successfully deployed Sora model as per the previous section.
Obtain the BASE_URL
and BEARER_TOKEN
from the API page as follows.
curl 'https://llm-api-66414768.sora-h26.soracloud.org/v1/chat/completions' \
-H 'authorization: Bearer 2f482a3f-ee14-4bdd-ab21-1782dd7e8890' \
...
In this case, the respective values to take note would be:
Install OpenAI Python package:
With the OpenAI SDK installed, create a file called example.py and copy the example code into it:
from openai import OpenAI
client = OpenAI(base_url=<BASE_URL>, api_key=<BEARER_TOKEN>)
completion = client.chat.completions.create(
model="sora-amazing-model",
messages=[
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
],
stream=True,
)
for chunk in completion:
print(chunk.choices[0].delta)
Install OpenAI Python package:
With the OpenAI SDK installed, create a file called example.py and copy the example code into it:
from openai import OpenAI
client = OpenAI(base_url=<BASE_URL>, api_key=<BEARER_TOKEN>)
completion = client.chat.completions.create(
model="sora-amazing-model",
messages=[
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
],
stream=True,
)
for chunk in completion:
print(chunk.choices[0].delta)
Install OpenAI Node.js package:
With the OpenAI SDK installed, create a file called example.js and copy the example code into it:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "<BASE_URL>",
apiKey: "<BEARER_TOKEN>"
});
const stream = await client.chat.completions.create({
model: "sora-amazing-model",
messages: [
{
role: "user",
content: "Write a one-sentence bedtime story about a unicorn.",
},
],
stream: true,
});
for await (const chunk of stream) {
console.log(chunk);
console.log(chunk.choices[0].delta);
console.log("****************");
}