(options: Options & GenerateObjectOptions<Tools, A, I, R>)
| 642 | ) as any |
| 643 | |
| 644 | const generateObject = < |
| 645 | A, |
| 646 | I extends Record<string, unknown>, |
| 647 | R, |
| 648 | Options extends NoExcessProperties<GenerateObjectOptions<any, A, I, R>, Options>, |
| 649 | Tools extends Record<string, Tool.Any> = {} |
| 650 | >(options: Options & GenerateObjectOptions<Tools, A, I, R>): Effect.Effect< |
| 651 | GenerateObjectResponse<Tools, A, ExtractEncodedToolParameters<Options>>, |
| 652 | ExtractError<Options>, |
| 653 | R | ExtractContext<Options> |
| 654 | > => { |
| 655 | const schema: Schema.Schema<A, I, R> = options.schema |
| 656 | const objectName = getObjectName(options.objectName, schema) |
| 657 | return Effect.useSpan( |
| 658 | "LanguageModel.generateObject", |
| 659 | { |
| 660 | captureStackTrace: false, |
| 661 | attributes: { |
| 662 | objectName, |
| 663 | concurrency: options.concurrency, |
| 664 | toolChoice: options.toolChoice |
| 665 | } |
| 666 | }, |
| 667 | Effect.fnUntraced( |
| 668 | function*(span) { |
| 669 | const spanTransformer = yield* getSpanTransformer |
| 670 | |
| 671 | const providerOptions: Mutable<ProviderOptions> = { |
| 672 | prompt: Prompt.make(options.prompt), |
| 673 | tools: [], |
| 674 | toolChoice: "none", |
| 675 | responseFormat: { type: "json", objectName, schema }, |
| 676 | span |
| 677 | } |
| 678 | |
| 679 | const content = yield* generateContent(options, providerOptions) |
| 680 | |
| 681 | applySpanTransformer(spanTransformer, content as any, providerOptions) |
| 682 | |
| 683 | const value = yield* resolveStructuredOutput(content as any, schema) |
| 684 | |
| 685 | return new GenerateObjectResponse(value, content) |
| 686 | }, |
| 687 | Effect.catchTag("ParseError", (error) => |
| 688 | AiError.MalformedOutput.fromParseError({ |
| 689 | module: "LanguageModel", |
| 690 | method: "generateText", |
| 691 | error |
| 692 | })), |
| 693 | (effect, span) => Effect.withParentSpan(effect, span), |
| 694 | Effect.provideService(IdGenerator, idGenerator) |
| 695 | ) |
| 696 | ) as any |
| 697 | } |
| 698 | |
| 699 | const streamText: < |
| 700 | Options extends NoExcessProperties<GenerateTextOptions<any>, Options>, |
nothing calls this directly
no test coverage detected