-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hi, I'm trying out the API for something I'm building, and I'm having issues with json responses.
My code:
const completion = await client.chat.completions.create({
messages: [{ content: promptContent, role: 'user' }],
model: 'Llama-4-Scout-17B-16E-Instruct-FP8',
response_format: {
type: 'json_schema',
json_schema: {
name: 'similarity_scores',
schema: {
type: 'array',
items: {
type: 'object',
properties: {
productID: { type: 'string' },
similarity: { type: 'number', minimum: 0, maximum: 10 },
},
required: ['productID', 'similarity'],
additionalProperties: false,
},
},
},
},
});The api response:
BadRequestError: 400 {"title":"Bad request","detail":"Response format 'json_schema' is an invalid JSON schema object","status":400}
at APIError.generate (file:///Users/yohance/Documents/coding/digreddit/lead_evaluator/.wrangler/tmp/dev-ow855L/index.js:987:14)
at _LlamaAPIClient.makeStatusError (file:///Users/yohance/Documents/coding/digreddit/lead_evaluator/.wrangler/tmp/dev-ow855L/index.js:2249:21)
at _LlamaAPIClient.makeRequest (file:///Users/yohance/Documents/coding/digreddit/lead_evaluator/.wrangler/tmp/dev-ow855L/index.js:2380:24)
at async calculateSimilarity (file:///Users/yohance/Documents/coding/digreddit/lead_evaluator/.wrangler/tmp/dev-ow855L/index.js:2608:24)
at async Object.fetch (file:///Users/yohance/Documents/coding/digreddit/lead_evaluator/.wrangler/tmp/dev-ow855L/index.js:5234:24)
at async drainBody (file:///Users/yohance/Documents/coding/digreddit/lead_evaluator/.wrangler/tmp/dev-ow855L/index.js:5257:12) {
status: 400,
headers: Headers,
error: Object,
stack: Error: 400 {"title":"Bad request","detail":"Respon…luator/.wrangler/tmp/dev-ow855L/index.js:5257:12),
message: 400 {"title":"Bad request","detail":"Response form…' is an invalid JSON schema object","status":400}
}
Let me know if the issue resides on my end, and a possible fix. I couldn't find any related information in the only docs I found related to json schema responses - they only mention how to manage objects.
Metadata
Metadata
Assignees
Labels
No labels