modelmix 4.4.24 → 4.4.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/json.js +1 -1
- package/index.js +25 -3
- package/package.json +1 -1
- package/test/json.test.js +36 -0
package/demo/json.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ModelMix } from '../index.js';
|
|
|
2
2
|
try { process.loadEnvFile(); } catch {}
|
|
3
3
|
|
|
4
4
|
const model = await ModelMix.new({ options: { max_tokens: 10000 }, config: { debug: 3 } })
|
|
5
|
-
.
|
|
5
|
+
.gpt51()
|
|
6
6
|
// .gptOss()
|
|
7
7
|
// .scout({ config: { temperature: 0 } })
|
|
8
8
|
// .o4mini()
|
package/index.js
CHANGED
|
@@ -1566,7 +1566,7 @@ class MixOpenAIResponses extends MixOpenAI {
|
|
|
1566
1566
|
}
|
|
1567
1567
|
|
|
1568
1568
|
const responsesUrl = this.config.url.replace('/chat/completions', '/responses');
|
|
1569
|
-
const request = MixOpenAIResponses.buildResponsesRequest(options);
|
|
1569
|
+
const request = MixOpenAIResponses.buildResponsesRequest(options, config);
|
|
1570
1570
|
const response = await axios.post(responsesUrl, request, {
|
|
1571
1571
|
headers: this.headers
|
|
1572
1572
|
});
|
|
@@ -1574,16 +1574,38 @@ class MixOpenAIResponses extends MixOpenAI {
|
|
|
1574
1574
|
return MixOpenAIResponses.processResponsesResponse(response);
|
|
1575
1575
|
}
|
|
1576
1576
|
|
|
1577
|
-
static buildResponsesRequest(options = {}) {
|
|
1577
|
+
static buildResponsesRequest(options = {}, config = {}) {
|
|
1578
|
+
const input = MixOpenAIResponses.messagesToResponsesInput(options.messages);
|
|
1579
|
+
if (config.system) {
|
|
1580
|
+
input.unshift({ role: 'developer', content: [{ type: 'input_text', text: config.system }] });
|
|
1581
|
+
}
|
|
1578
1582
|
const request = {
|
|
1579
1583
|
model: options.model,
|
|
1580
|
-
input
|
|
1584
|
+
input,
|
|
1581
1585
|
stream: false
|
|
1582
1586
|
};
|
|
1583
1587
|
|
|
1584
1588
|
if (options.reasoning_effort) request.reasoning = { effort: options.reasoning_effort };
|
|
1585
1589
|
if (options.verbosity) request.text = { verbosity: options.verbosity };
|
|
1586
1590
|
|
|
1591
|
+
if (options.response_format) {
|
|
1592
|
+
const rf = options.response_format;
|
|
1593
|
+
let format;
|
|
1594
|
+
if (rf.type === 'json_schema' && rf.json_schema) {
|
|
1595
|
+
format = {
|
|
1596
|
+
type: 'json_schema',
|
|
1597
|
+
name: rf.json_schema.name || 'response',
|
|
1598
|
+
strict: true,
|
|
1599
|
+
schema: rf.json_schema.schema
|
|
1600
|
+
};
|
|
1601
|
+
} else if (rf.type) {
|
|
1602
|
+
format = { type: rf.type };
|
|
1603
|
+
}
|
|
1604
|
+
if (format) {
|
|
1605
|
+
request.text = { ...request.text, format };
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1587
1609
|
if (typeof options.max_completion_tokens === 'number') {
|
|
1588
1610
|
request.max_output_tokens = options.max_completion_tokens;
|
|
1589
1611
|
} else if (typeof options.max_tokens === 'number') {
|
package/package.json
CHANGED
package/test/json.test.js
CHANGED
|
@@ -376,6 +376,42 @@ describe('JSON Schema and Structured Output Tests', () => {
|
|
|
376
376
|
expect(result.countries[0]).to.have.property('capital');
|
|
377
377
|
});
|
|
378
378
|
|
|
379
|
+
it('should send JSON mode and system instructions in Responses API request', async () => {
|
|
380
|
+
const example = {
|
|
381
|
+
countries: [{
|
|
382
|
+
name: 'France',
|
|
383
|
+
capital: 'Paris'
|
|
384
|
+
}]
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
model.gpt51().addText('Name and capital of 3 South American countries.');
|
|
388
|
+
|
|
389
|
+
let capturedBody;
|
|
390
|
+
nock('https://api.openai.com')
|
|
391
|
+
.post('/v1/responses', (body) => {
|
|
392
|
+
capturedBody = body;
|
|
393
|
+
return true;
|
|
394
|
+
})
|
|
395
|
+
.reply(200, testUtils.createMockResponse('openai-responses', JSON.stringify({
|
|
396
|
+
countries: [
|
|
397
|
+
{ name: 'Argentina', capital: 'BUENOS AIRES' },
|
|
398
|
+
{ name: 'Brazil', capital: 'BRASILIA' },
|
|
399
|
+
{ name: 'Colombia', capital: 'BOGOTA' }
|
|
400
|
+
]
|
|
401
|
+
})));
|
|
402
|
+
|
|
403
|
+
const result = await model.json(example);
|
|
404
|
+
|
|
405
|
+
expect(result.countries).to.be.an('array');
|
|
406
|
+
expect(result.countries).to.have.length(3);
|
|
407
|
+
expect(capturedBody).to.be.an('object');
|
|
408
|
+
expect(capturedBody.text).to.be.an('object');
|
|
409
|
+
expect(capturedBody.text.format).to.deep.equal({ type: 'json_object' });
|
|
410
|
+
expect(capturedBody.input).to.be.an('array').that.is.not.empty;
|
|
411
|
+
expect(capturedBody.input[0].role).to.equal('developer');
|
|
412
|
+
expect(capturedBody.input[0].content[0].text).to.include('JSON');
|
|
413
|
+
});
|
|
414
|
+
|
|
379
415
|
it('should handle complex nested JSON schema', async () => {
|
|
380
416
|
const example = {
|
|
381
417
|
user: {
|