(
options: Options & GenerateTextOptions<Tools>
)
| 780 | ) |
| 781 | |
| 782 | const generateText = < |
| 783 | Options extends NoExcessProperties<GenerateTextOptions<any>, Options>, |
| 784 | Tools extends Record<string, Tool.Any> = {} |
| 785 | >( |
| 786 | options: Options & GenerateTextOptions<Tools> |
| 787 | ): Effect.Effect< |
| 788 | GenerateTextResponse<Tools>, |
| 789 | ExtractError<Options>, |
| 790 | ExtractServices<Options> |
| 791 | > => |
| 792 | Effect.useSpan( |
| 793 | "LanguageModel.generateText", |
| 794 | { |
| 795 | attributes: { |
| 796 | concurrency: options.concurrency, |
| 797 | toolChoice: options.toolChoice |
| 798 | } |
| 799 | }, |
| 800 | Effect.fnUntraced( |
| 801 | function*(span) { |
| 802 | const spanTransformer = yield* getSpanTransformer |
| 803 | |
| 804 | const providerOptions: Mutable<ProviderOptions> = { |
| 805 | prompt: Prompt.make(options.prompt), |
| 806 | tools: [], |
| 807 | toolChoice: "none", |
| 808 | responseFormat: { type: "text" }, |
| 809 | span, |
| 810 | previousResponseId: undefined, |
| 811 | incrementalPrompt: undefined |
| 812 | } |
| 813 | const content = yield* generateContent(options, providerOptions) |
| 814 | |
| 815 | applySpanTransformer( |
| 816 | spanTransformer, |
| 817 | content as any, |
| 818 | providerOptions |
| 819 | ) |
| 820 | |
| 821 | return new GenerateTextResponse(content) |
| 822 | }, |
| 823 | Effect.catchTag("SchemaError", (error) => |
| 824 | Effect.fail( |
| 825 | AiError.make({ |
| 826 | module: "LanguageModel", |
| 827 | method: "generateText", |
| 828 | reason: AiError.InvalidOutputError.fromSchemaError(error) |
| 829 | }) |
| 830 | )), |
| 831 | (effect, span) => Effect.withParentSpan(effect, span, { captureStackTrace: false }), |
| 832 | Effect.provideService(IdGenerator, idGenerator) |
| 833 | ) |
| 834 | ) as any |
| 835 | |
| 836 | const generateObject = < |
| 837 | ObjectEncoded extends Record<string, any>, |
nothing calls this directly
no test coverage detected