Vision
Pass in URL for the image as well as your prompt.
JS: Be sure to send image_url as an object
import { OpenAI } from "openai";
const userContent = "{'image_desc', 'image_text'}";
const imageUrl = "https://example.com/img.jpg";
const client = new OpenAI({
apiKey: "JSONMODE_API_KEY",
baseURL: "https://jsonmode.com/v1"
});
async function main() {
const response = await client.chat.completions.create({
model: "any",
responseFormat: { type: "json_object" },
messages: [
{
"role": "user",
"content": [
{"type": "text", "text": userContent},
{"type": "image_url", "image_url": {"url": imageUrl}}
],
}
],
temperature: 0.7,
maxTokens: 1024
});
console.log('Response:', response.choices[0].message.content);
}
main();
Python:
import openai
api_key = "JSONMODE_API_KEY"
base_url = "https://jsonmode.com/v1"
user_content = "{'image_desc', 'image_text'}"
image_url = "https://example.com/img.jpg"
client = openai.OpenAI(api_key=api_key, base_url=base_url)
response = client.chat.completions.create(
model="any",
response_format={"type": "json_object"},
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": user_content},
{"type": "image_url", "image_url": {"url": image_url}},
],
}
],
temperature=0.7,
max_tokens=1024
)
print('Response: ', response.choices[0].message.content)