Skip to content

Commit c57e248

Browse files
authored
chore (provider): remove mode (#5580)
1 parent 33f4a6a commit c57e248

File tree

54 files changed

+1492
-2962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1492
-2962
lines changed

‎.changeset/thick-chairs-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/provider': major
3+
---
4+
5+
chore (provider): remove mode

‎examples/ai-core/src/test/response-format.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dotenv/config';
33

44
async function main() {
55
const result = await openai('gpt-4-turbo').doStream({
6-
mode: { type: 'regular' },
76
inputFormat: 'prompt',
87
responseFormat: {
98
type: 'json',

‎packages/ai/core/generate-object/generate-object.test.ts

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ describe('output = "object"', () => {
2020
it('should generate object with json mode', async () => {
2121
const result = await generateObject({
2222
model: new MockLanguageModelV2({
23-
doGenerate: async ({ prompt, mode }) => {
24-
assert.deepStrictEqual(mode, {
25-
type: 'object-json',
23+
doGenerate: async ({ prompt, responseFormat }) => {
24+
expect(responseFormat).toStrictEqual({
25+
type: 'json',
2626
name: undefined,
2727
description: undefined,
2828
schema: {
@@ -67,9 +67,9 @@ describe('output = "object"', () => {
6767
const result = await generateObject({
6868
model: new MockLanguageModelV2({
6969
supportsStructuredOutputs: true,
70-
doGenerate: async ({ prompt, mode }) => {
71-
assert.deepStrictEqual(mode, {
72-
type: 'object-json',
70+
doGenerate: async ({ prompt, responseFormat }) => {
71+
expect(responseFormat).toStrictEqual({
72+
type: 'json',
7373
name: undefined,
7474
description: undefined,
7575
schema: {
@@ -107,9 +107,9 @@ describe('output = "object"', () => {
107107
const result = await generateObject({
108108
model: new MockLanguageModelV2({
109109
supportsStructuredOutputs: true,
110-
doGenerate: async ({ prompt, mode }) => {
111-
assert.deepStrictEqual(mode, {
112-
type: 'object-json',
110+
doGenerate: async ({ prompt, responseFormat }) => {
111+
expect(responseFormat).toStrictEqual({
112+
type: 'json',
113113
name: 'test-name',
114114
description: 'test description',
115115
schema: {
@@ -148,10 +148,9 @@ describe('output = "object"', () => {
148148
it('should generate object with tool mode', async () => {
149149
const result = await generateObject({
150150
model: new MockLanguageModelV2({
151-
doGenerate: async ({ prompt, mode }) => {
152-
assert.deepStrictEqual(mode, {
153-
type: 'object-tool',
154-
tool: {
151+
doGenerate: async ({ prompt, tools, toolChoice }) => {
152+
expect(tools).toStrictEqual([
153+
{
155154
type: 'function',
156155
name: 'json',
157156
description: 'Respond with a JSON object.',
@@ -163,7 +162,8 @@ describe('output = "object"', () => {
163162
type: 'object',
164163
},
165164
},
166-
});
165+
]);
166+
expect(toolChoice).toStrictEqual({ type: 'required' });
167167

168168
expect(prompt).toStrictEqual([
169169
{
@@ -197,10 +197,9 @@ describe('output = "object"', () => {
197197
it('should use name and description with tool mode', async () => {
198198
const result = await generateObject({
199199
model: new MockLanguageModelV2({
200-
doGenerate: async ({ prompt, mode }) => {
201-
assert.deepStrictEqual(mode, {
202-
type: 'object-tool',
203-
tool: {
200+
doGenerate: async ({ prompt, tools, toolChoice }) => {
201+
expect(tools).toStrictEqual([
202+
{
204203
type: 'function',
205204
name: 'test-name',
206205
description: 'test description',
@@ -212,7 +211,9 @@ describe('output = "object"', () => {
212211
type: 'object',
213212
},
214213
},
215-
});
214+
]);
215+
expect(toolChoice).toStrictEqual({ type: 'required' });
216+
216217
expect(prompt).toStrictEqual([
217218
{
218219
role: 'user',
@@ -379,9 +380,9 @@ describe('output = "object"', () => {
379380
it('should generate object when using zod transform', async () => {
380381
const result = await generateObject({
381382
model: new MockLanguageModelV2({
382-
doGenerate: async ({ prompt, mode }) => {
383-
assert.deepStrictEqual(mode, {
384-
type: 'object-json',
383+
doGenerate: async ({ prompt, responseFormat }) => {
384+
expect(responseFormat).toStrictEqual({
385+
type: 'json',
385386
name: undefined,
386387
description: undefined,
387388
schema: {
@@ -426,9 +427,9 @@ describe('output = "object"', () => {
426427
it('should generate object with tool mode when using zod prePreprocess', async () => {
427428
const result = await generateObject({
428429
model: new MockLanguageModelV2({
429-
doGenerate: async ({ prompt, mode }) => {
430-
assert.deepStrictEqual(mode, {
431-
type: 'object-json',
430+
doGenerate: async ({ prompt, responseFormat }) => {
431+
expect(responseFormat).toStrictEqual({
432+
type: 'json',
432433
name: undefined,
433434
description: undefined,
434435
schema: {
@@ -478,9 +479,9 @@ describe('output = "object"', () => {
478479
it('should generate object with json mode', async () => {
479480
const result = await generateObject({
480481
model: new MockLanguageModelV2({
481-
doGenerate: async ({ prompt, mode }) => {
482-
assert.deepStrictEqual(mode, {
483-
type: 'object-json',
482+
doGenerate: async ({ prompt, responseFormat }) => {
483+
expect(responseFormat).toStrictEqual({
484+
type: 'json',
484485
name: undefined,
485486
description: undefined,
486487
schema: {
@@ -980,9 +981,9 @@ describe('output = "array"', () => {
980981
it('should generate an array with 3 elements', async () => {
981982
const result = await generateObject({
982983
model: new MockLanguageModelV2({
983-
doGenerate: async ({ prompt, mode }) => {
984-
assert.deepStrictEqual(mode, {
985-
type: 'object-json',
984+
doGenerate: async ({ prompt, responseFormat }) => {
985+
expect(responseFormat).toStrictEqual({
986+
type: 'json',
986987
name: undefined,
987988
description: undefined,
988989
schema: {
@@ -1050,9 +1051,9 @@ describe('output = "enum"', () => {
10501051
it('should generate an enum value', async () => {
10511052
const result = await generateObject({
10521053
model: new MockLanguageModelV2({
1053-
doGenerate: async ({ prompt, mode }) => {
1054-
expect(mode).toEqual({
1055-
type: 'object-json',
1054+
doGenerate: async ({ prompt, responseFormat }) => {
1055+
expect(responseFormat).toStrictEqual({
1056+
type: 'json',
10561057
name: undefined,
10571058
description: undefined,
10581059
schema: {
@@ -1101,9 +1102,9 @@ describe('output = "no-schema"', () => {
11011102
it('should generate object', async () => {
11021103
const result = await generateObject({
11031104
model: new MockLanguageModelV2({
1104-
doGenerate: async ({ prompt, mode }) => {
1105-
assert.deepStrictEqual(mode, {
1106-
type: 'object-json',
1105+
doGenerate: async ({ prompt, responseFormat }) => {
1106+
expect(responseFormat).toStrictEqual({
1107+
type: 'json',
11071108
name: undefined,
11081109
description: undefined,
11091110
schema: undefined,

‎packages/ai/core/generate-object/generate-object.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ export async function generateObject<SCHEMA, RESULT>({
530530
tracer,
531531
fn: async span => {
532532
const result = await model.doGenerate({
533-
mode: {
534-
type: 'object-json',
533+
responseFormat: {
534+
type: 'json',
535535
schema: outputStrategy.jsonSchema,
536536
name: schemaName,
537537
description: schemaDescription,
@@ -651,16 +651,16 @@ export async function generateObject<SCHEMA, RESULT>({
651651
tracer,
652652
fn: async span => {
653653
const result = await model.doGenerate({
654-
mode: {
655-
type: 'object-tool',
656-
tool: {
654+
tools: [
655+
{
657656
type: 'function',
658657
name: schemaName ?? 'json',
659658
description:
660659
schemaDescription ?? 'Respond with a JSON object.',
661660
parameters: outputStrategy.jsonSchema!,
662661
},
663-
},
662+
],
663+
toolChoice: { type: 'required' },
664664
...prepareCallSettings(settings),
665665
inputFormat,
666666
prompt: promptMessages,

‎packages/ai/core/generate-object/stream-object.test.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ describe('streamObject', () => {
2323
it('should send object deltas with json mode', async () => {
2424
const result = streamObject({
2525
model: new MockLanguageModelV2({
26-
doStream: async ({ prompt, mode }) => {
27-
expect(mode).toStrictEqual({
28-
type: 'object-json',
26+
doStream: async ({ prompt, responseFormat }) => {
27+
expect(responseFormat).toStrictEqual({
28+
type: 'json',
2929
name: undefined,
3030
description: undefined,
3131
schema: {
@@ -90,9 +90,9 @@ describe('streamObject', () => {
9090
const result = streamObject({
9191
model: new MockLanguageModelV2({
9292
supportsStructuredOutputs: true,
93-
doStream: async ({ prompt, mode }) => {
94-
assert.deepStrictEqual(mode, {
95-
type: 'object-json',
93+
doStream: async ({ prompt, responseFormat }) => {
94+
expect(responseFormat).toStrictEqual({
95+
type: 'json',
9696
name: undefined,
9797
description: undefined,
9898
schema: {
@@ -149,9 +149,9 @@ describe('streamObject', () => {
149149
const result = streamObject({
150150
model: new MockLanguageModelV2({
151151
supportsStructuredOutputs: true,
152-
doStream: async ({ prompt, mode }) => {
153-
assert.deepStrictEqual(mode, {
154-
type: 'object-json',
152+
doStream: async ({ prompt, responseFormat }) => {
153+
expect(responseFormat).toStrictEqual({
154+
type: 'json',
155155
name: 'test-name',
156156
description: 'test description',
157157
schema: {
@@ -210,10 +210,9 @@ describe('streamObject', () => {
210210
it('should send object deltas with tool mode', async () => {
211211
const result = streamObject({
212212
model: new MockLanguageModelV2({
213-
doStream: async ({ prompt, mode }) => {
214-
assert.deepStrictEqual(mode, {
215-
type: 'object-tool',
216-
tool: {
213+
doStream: async ({ prompt, tools, toolChoice }) => {
214+
expect(tools).toStrictEqual([
215+
{
217216
type: 'function',
218217
name: 'json',
219218
description: 'Respond with a JSON object.',
@@ -225,7 +224,8 @@ describe('streamObject', () => {
225224
type: 'object',
226225
},
227226
},
228-
});
227+
]);
228+
expect(toolChoice).toStrictEqual({ type: 'required' });
229229
expect(prompt).toStrictEqual([
230230
{
231231
role: 'user',
@@ -307,10 +307,9 @@ describe('streamObject', () => {
307307
it('should use name and description with tool mode', async () => {
308308
const result = streamObject({
309309
model: new MockLanguageModelV2({
310-
doStream: async ({ prompt, mode }) => {
311-
assert.deepStrictEqual(mode, {
312-
type: 'object-tool',
313-
tool: {
310+
doStream: async ({ prompt, tools, toolChoice }) => {
311+
expect(tools).toStrictEqual([
312+
{
314313
type: 'function',
315314
name: 'test-name',
316315
description: 'test description',
@@ -322,7 +321,9 @@ describe('streamObject', () => {
322321
type: 'object',
323322
},
324323
},
325-
});
324+
]);
325+
expect(toolChoice).toStrictEqual({ type: 'required' });
326+
326327
expect(prompt).toStrictEqual([
327328
{
328329
role: 'user',
@@ -1197,9 +1198,9 @@ describe('streamObject', () => {
11971198
it('should send object deltas with json mode', async () => {
11981199
const result = streamObject({
11991200
model: new MockLanguageModelV2({
1200-
doStream: async ({ prompt, mode }) => {
1201-
assert.deepStrictEqual(mode, {
1202-
type: 'object-json',
1201+
doStream: async ({ prompt, responseFormat }) => {
1202+
expect(responseFormat).toStrictEqual({
1203+
type: 'json',
12031204
name: undefined,
12041205
description: undefined,
12051206
schema: jsonSchema({
@@ -1557,9 +1558,9 @@ describe('streamObject', () => {
15571558
beforeEach(async () => {
15581559
result = streamObject({
15591560
model: new MockLanguageModelV2({
1560-
doStream: async ({ prompt, mode }) => {
1561-
assert.deepStrictEqual(mode, {
1562-
type: 'object-json',
1561+
doStream: async ({ prompt, responseFormat }) => {
1562+
expect(responseFormat).toStrictEqual({
1563+
type: 'json',
15631564
name: undefined,
15641565
description: undefined,
15651566
schema: {
@@ -1712,9 +1713,9 @@ describe('streamObject', () => {
17121713
beforeEach(async () => {
17131714
result = streamObject({
17141715
model: new MockLanguageModelV2({
1715-
doStream: async ({ prompt, mode }) => {
1716-
assert.deepStrictEqual(mode, {
1717-
type: 'object-json',
1716+
doStream: async ({ prompt, responseFormat }) => {
1717+
expect(responseFormat).toStrictEqual({
1718+
type: 'json',
17181719
name: undefined,
17191720
description: undefined,
17201721
schema: {
@@ -1824,9 +1825,9 @@ describe('streamObject', () => {
18241825
it('should send object deltas with json mode', async () => {
18251826
const result = streamObject({
18261827
model: new MockLanguageModelV2({
1827-
doStream: async ({ prompt, mode }) => {
1828-
assert.deepStrictEqual(mode, {
1829-
type: 'object-json',
1828+
doStream: async ({ prompt, responseFormat }) => {
1829+
expect(responseFormat).toStrictEqual({
1830+
type: 'json',
18301831
name: undefined,
18311832
description: undefined,
18321833
schema: undefined,

‎packages/ai/core/generate-object/stream-object.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ class DefaultStreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM>
603603
});
604604

605605
callOptions = {
606-
mode: {
607-
type: 'object-json',
606+
responseFormat: {
607+
type: 'json',
608608
schema: outputStrategy.jsonSchema,
609609
name: schemaName,
610610
description: schemaDescription,
@@ -646,16 +646,16 @@ class DefaultStreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM>
646646
});
647647

648648
callOptions = {
649-
mode: {
650-
type: 'object-tool',
651-
tool: {
649+
tools: [
650+
{
652651
type: 'function',
653652
name: schemaName ?? 'json',
654653
description:
655654
schemaDescription ?? 'Respond with a JSON object.',
656655
parameters: outputStrategy.jsonSchema!,
657656
},
658-
},
657+
],
658+
toolChoice: { type: 'required' },
659659
...prepareCallSettings(settings),
660660
inputFormat: standardizedPrompt.type,
661661
prompt: await convertToLanguageModelPrompt({

0 commit comments

Comments
 (0)