ai 4.0.0-canary.10 → 4.0.0-canary.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # ai
2
2
 
3
+ ## 4.0.0-canary.12
4
+
5
+ ### Patch Changes
6
+
7
+ - b053413: chore (ui): refactorings & README update
8
+ - Updated dependencies [b053413]
9
+ - @ai-sdk/ui-utils@1.0.0-canary.8
10
+ - @ai-sdk/react@1.0.0-canary.8
11
+
12
+ ## 4.0.0-canary.11
13
+
14
+ ### Major Changes
15
+
16
+ - f68d7b1: chore (ai/core): streamObject returns result immediately (no Promise)
17
+ - f967199: chore (ai/core): streamText returns result immediately (no Promise)
18
+
3
19
  ## 4.0.0-canary.10
4
20
 
5
21
  ### Major Changes
package/README.md CHANGED
@@ -32,17 +32,13 @@ npm install @ai-sdk/openai
32
32
  import { generateText } from 'ai';
33
33
  import { openai } from '@ai-sdk/openai'; // Ensure OPENAI_API_KEY environment variable is set
34
34
 
35
- async function main() {
36
- const { text } = await generateText({
37
- model: openai('gpt-4-turbo'),
38
- system: 'You are a friendly assistant!',
39
- prompt: 'Why is the sky blue?',
40
- });
41
-
42
- console.log(text);
43
- }
35
+ const { text } = await generateText({
36
+ model: openai('gpt-4o'),
37
+ system: 'You are a friendly assistant!',
38
+ prompt: 'Why is the sky blue?',
39
+ });
44
40
 
45
- main();
41
+ console.log(text);
46
42
  ```
47
43
 
48
44
  ### AI SDK UI
@@ -85,14 +81,14 @@ export default function Page() {
85
81
  ###### @/app/api/chat/route.ts (Next.js App Router)
86
82
 
87
83
  ```ts
88
- import { CoreMessage, streamText } from 'ai';
84
+ import { streamText } from 'ai';
89
85
  import { openai } from '@ai-sdk/openai';
90
86
 
91
87
  export async function POST(req: Request) {
92
- const { messages }: { messages: CoreMessage[] } = await req.json();
88
+ const { messages } = await req.json();
93
89
 
94
- const result = await streamText({
95
- model: openai('gpt-4'),
90
+ const result = streamText({
91
+ model: openai('gpt-4o'),
96
92
  system: 'You are a helpful assistant.',
97
93
  messages,
98
94
  });
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ToolInvocation, Attachment, Schema, DeepPartial, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
2
- export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, StreamPart, ToolInvocation, UseAssistantOptions, formatStreamPart, jsonSchema, parseStreamPart, processDataProtocolResponse, readDataStream } from '@ai-sdk/ui-utils';
2
+ export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UseAssistantOptions, formatAssistantStreamPart, formatDataStreamPart, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, processDataStream, processTextStream } from '@ai-sdk/ui-utils';
3
3
  export { ToolCall as CoreToolCall, ToolResult as CoreToolResult, generateId } from '@ai-sdk/provider-utils';
4
4
  import { AttributeValue, Tracer } from '@opentelemetry/api';
5
5
  import { EmbeddingModelV1, EmbeddingModelV1Embedding, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, JSONValue, LanguageModelV1CallOptions, NoSuchModelError, AISDKError } from '@ai-sdk/provider';
@@ -891,7 +891,7 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
891
891
  /**
892
892
  Warnings from the model provider (e.g. unsupported settings)
893
893
  */
894
- readonly warnings: CallWarning[] | undefined;
894
+ readonly warnings: Promise<CallWarning[] | undefined>;
895
895
  /**
896
896
  The token usage of the generated response. Resolved when the response is finished.
897
897
  */
@@ -1066,7 +1066,7 @@ Callback that is called when the LLM response and the final object validation ar
1066
1066
  currentDate?: () => Date;
1067
1067
  now?: () => number;
1068
1068
  };
1069
- }): Promise<StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>>;
1069
+ }): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
1070
1070
  /**
1071
1071
  Generate an array with structured, typed elements for a given prompt and element schema using a language model.
1072
1072
 
@@ -1133,7 +1133,7 @@ Callback that is called when the LLM response and the final object validation ar
1133
1133
  currentDate?: () => Date;
1134
1134
  now?: () => number;
1135
1135
  };
1136
- }): Promise<StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>>;
1136
+ }): StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>;
1137
1137
  /**
1138
1138
  Generate JSON with any schema for a given prompt using a language model.
1139
1139
 
@@ -1174,7 +1174,7 @@ Callback that is called when the LLM response and the final object validation ar
1174
1174
  currentDate?: () => Date;
1175
1175
  now?: () => number;
1176
1176
  };
1177
- }): Promise<StreamObjectResult<JSONValue, JSONValue, never>>;
1177
+ }): StreamObjectResult<JSONValue, JSONValue, never>;
1178
1178
 
1179
1179
  type Parameters = z.ZodTypeAny | Schema<any>;
1180
1180
  type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
@@ -1889,7 +1889,7 @@ Details for all steps.
1889
1889
  generateId?: () => string;
1890
1890
  currentDate?: () => Date;
1891
1891
  };
1892
- }): Promise<StreamTextResult<TOOLS>>;
1892
+ }): StreamTextResult<TOOLS>;
1893
1893
 
1894
1894
  /**
1895
1895
  * Experimental middleware for LanguageModelV1.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ToolInvocation, Attachment, Schema, DeepPartial, JSONValue as JSONValue$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
2
- export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, StreamPart, ToolInvocation, UseAssistantOptions, formatStreamPart, jsonSchema, parseStreamPart, processDataProtocolResponse, readDataStream } from '@ai-sdk/ui-utils';
2
+ export { AssistantMessage, AssistantStatus, Attachment, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DataStreamPart, DeepPartial, IdGenerator, JSONValue, Message, RequestOptions, Schema, ToolInvocation, UseAssistantOptions, formatAssistantStreamPart, formatDataStreamPart, jsonSchema, parseAssistantStreamPart, parseDataStreamPart, processDataStream, processTextStream } from '@ai-sdk/ui-utils';
3
3
  export { ToolCall as CoreToolCall, ToolResult as CoreToolResult, generateId } from '@ai-sdk/provider-utils';
4
4
  import { AttributeValue, Tracer } from '@opentelemetry/api';
5
5
  import { EmbeddingModelV1, EmbeddingModelV1Embedding, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, JSONValue, LanguageModelV1CallOptions, NoSuchModelError, AISDKError } from '@ai-sdk/provider';
@@ -891,7 +891,7 @@ interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
891
891
  /**
892
892
  Warnings from the model provider (e.g. unsupported settings)
893
893
  */
894
- readonly warnings: CallWarning[] | undefined;
894
+ readonly warnings: Promise<CallWarning[] | undefined>;
895
895
  /**
896
896
  The token usage of the generated response. Resolved when the response is finished.
897
897
  */
@@ -1066,7 +1066,7 @@ Callback that is called when the LLM response and the final object validation ar
1066
1066
  currentDate?: () => Date;
1067
1067
  now?: () => number;
1068
1068
  };
1069
- }): Promise<StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>>;
1069
+ }): StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>;
1070
1070
  /**
1071
1071
  Generate an array with structured, typed elements for a given prompt and element schema using a language model.
1072
1072
 
@@ -1133,7 +1133,7 @@ Callback that is called when the LLM response and the final object validation ar
1133
1133
  currentDate?: () => Date;
1134
1134
  now?: () => number;
1135
1135
  };
1136
- }): Promise<StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>>;
1136
+ }): StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>;
1137
1137
  /**
1138
1138
  Generate JSON with any schema for a given prompt using a language model.
1139
1139
 
@@ -1174,7 +1174,7 @@ Callback that is called when the LLM response and the final object validation ar
1174
1174
  currentDate?: () => Date;
1175
1175
  now?: () => number;
1176
1176
  };
1177
- }): Promise<StreamObjectResult<JSONValue, JSONValue, never>>;
1177
+ }): StreamObjectResult<JSONValue, JSONValue, never>;
1178
1178
 
1179
1179
  type Parameters = z.ZodTypeAny | Schema<any>;
1180
1180
  type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
@@ -1889,7 +1889,7 @@ Details for all steps.
1889
1889
  generateId?: () => string;
1890
1890
  currentDate?: () => Date;
1891
1891
  };
1892
- }): Promise<StreamTextResult<TOOLS>>;
1892
+ }): StreamTextResult<TOOLS>;
1893
1893
 
1894
1894
  /**
1895
1895
  * Experimental middleware for LanguageModelV1.