(
options: Options & GenerateObjectOptions<Tools, StructuredOutputSchema>
)
| 834 | ) as any |
| 835 | |
| 836 | const generateObject = < |
| 837 | ObjectEncoded extends Record<string, any>, |
| 838 | StructuredOutputSchema extends Schema.Encoder<ObjectEncoded, unknown>, |
| 839 | Options extends NoExcessProperties< |
| 840 | GenerateObjectOptions<any, StructuredOutputSchema>, |
| 841 | Options |
| 842 | >, |
| 843 | Tools extends Record<string, Tool.Any> = {} |
| 844 | >( |
| 845 | options: Options & GenerateObjectOptions<Tools, StructuredOutputSchema> |
| 846 | ): Effect.Effect< |
| 847 | GenerateObjectResponse<Tools, StructuredOutputSchema["Type"]>, |
| 848 | ExtractError<Options>, |
| 849 | ExtractServices<Options> | StructuredOutputSchema["DecodingServices"] |
| 850 | > => { |
| 851 | const objectName = getObjectName(options.objectName, options.schema) |
| 852 | return Effect.useSpan( |
| 853 | "LanguageModel.generateObject", |
| 854 | { |
| 855 | attributes: { |
| 856 | objectName, |
| 857 | concurrency: options.concurrency, |
| 858 | toolChoice: options.toolChoice |
| 859 | } |
| 860 | }, |
| 861 | Effect.fnUntraced( |
| 862 | function*(span) { |
| 863 | const spanTransformer = yield* getSpanTransformer |
| 864 | |
| 865 | const providerOptions: Mutable<ProviderOptions> = { |
| 866 | prompt: Prompt.make(options.prompt), |
| 867 | tools: [], |
| 868 | toolChoice: "none", |
| 869 | responseFormat: { |
| 870 | type: "json", |
| 871 | objectName, |
| 872 | schema: options.schema |
| 873 | }, |
| 874 | span, |
| 875 | previousResponseId: undefined, |
| 876 | incrementalPrompt: undefined |
| 877 | } |
| 878 | |
| 879 | const content = yield* generateContent(options, providerOptions) |
| 880 | |
| 881 | applySpanTransformer( |
| 882 | spanTransformer, |
| 883 | content as any, |
| 884 | providerOptions |
| 885 | ) |
| 886 | |
| 887 | const { codec } = yield* Effect.try({ |
| 888 | try: () => codecTransformer(options.schema), |
| 889 | catch: (error) => |
| 890 | AiError.make({ |
| 891 | module: "LanguageModel", |
| 892 | method: "generateObject", |
| 893 | reason: new AiError.UnsupportedSchemaError({ |
nothing calls this directly
no test coverage detected