@effect/ai-openai 0.16.5 → 0.16.6

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.
@@ -284,37 +284,42 @@ export class StreamChunk extends Data.Class<{
284
284
  * @since 1.0.0
285
285
  */
286
286
  get text(): Option.Option<string> {
287
- return this.parts[0]?._tag === "Content" ? Option.some(this.parts[0].content) : Option.none()
287
+ const firstContentPart = this.parts.find((part) => part._tag === "Content")
288
+ return firstContentPart ? Option.some(firstContentPart.content) : Option.none()
288
289
  }
289
290
  /**
290
291
  * @since 1.0.0
291
292
  */
292
293
  get asAiResponse(): AiResponse.AiResponse {
293
- if (this.parts.length === 0) {
294
- return AiResponse.AiResponse.fromText({
295
- role: AiRole.model,
296
- content: ""
297
- })
298
- }
299
- const part = this.parts[0]
300
- switch (part._tag) {
301
- case "Content":
302
- return AiResponse.AiResponse.fromText({
303
- role: AiRole.model,
304
- content: part.content
305
- })
306
- case "ToolCall":
307
- return new AiResponse.AiResponse({
308
- role: AiRole.model,
309
- parts: Chunk.of(AiResponse.ToolCallPart.fromUnknown({
294
+ const aiResponseParts: Array<AiResponse.Part> = []
295
+
296
+ for (let i = 0; i < this.parts.length; i++) {
297
+ const part = this.parts[i]
298
+ switch (part._tag) {
299
+ case "Content":
300
+ aiResponseParts.push(AiResponse.TextPart.fromContent(part.content))
301
+ break
302
+ case "ToolCall":
303
+ aiResponseParts.push(AiResponse.ToolCallPart.fromUnknown({
310
304
  id: part.id,
311
305
  name: part.name,
312
306
  params: part.arguments
313
307
  }))
314
- })
315
- case "Usage":
316
- return AiResponse.AiResponse.empty
308
+ break
309
+ }
310
+ }
311
+
312
+ if (aiResponseParts.length === 0) {
313
+ return AiResponse.AiResponse.fromText({
314
+ role: AiRole.model,
315
+ content: ""
316
+ })
317
317
  }
318
+
319
+ return new AiResponse.AiResponse({
320
+ role: AiRole.model,
321
+ parts: Chunk.unsafeFromArray(aiResponseParts)
322
+ })
318
323
  }
319
324
  }
320
325
 
@@ -28,7 +28,7 @@ import * as OpenAiTokenizer from "./OpenAiTokenizer.js"
28
28
  * @since 1.0.0
29
29
  * @category models
30
30
  */
31
- export type Model = typeof Generated.CreateChatCompletionRequestModelEnum.Encoded
31
+ export type Model = typeof Generated.ModelIdsSharedEnum.Encoded
32
32
 
33
33
  // =============================================================================
34
34
  // Configuration