@output.ai/llm 0.0.9 → 0.0.11
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/package.json +1 -1
- package/src/ai_sdk.js +23 -11
- package/src/index.d.ts +26 -15
- package/src/index.js +0 -1
- package/src/schema.js +0 -8
package/package.json
CHANGED
package/src/ai_sdk.js
CHANGED
|
@@ -11,7 +11,9 @@ const providers = {
|
|
|
11
11
|
openai
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export async function generateText(
|
|
14
|
+
export async function generateText( options ) {
|
|
15
|
+
const { prompt, ...aiSdkOptions } = options;
|
|
16
|
+
|
|
15
17
|
const provider = providers[prompt.config.provider];
|
|
16
18
|
const model = provider( prompt.config.model );
|
|
17
19
|
|
|
@@ -19,31 +21,41 @@ export async function generateText( prompt ) {
|
|
|
19
21
|
model,
|
|
20
22
|
messages: prompt.messages,
|
|
21
23
|
temperature: prompt.config.temperature,
|
|
22
|
-
maxOutputTokens: prompt.config.max_tokens ?? 64000
|
|
24
|
+
maxOutputTokens: prompt.config.max_tokens ?? 64000,
|
|
25
|
+
...aiSdkOptions // Spread remaining AI SDK options (thinking, etc.)
|
|
23
26
|
} );
|
|
24
27
|
|
|
25
|
-
trace( { lib: 'llm', event: 'generateText', input:
|
|
28
|
+
trace( { lib: 'llm', event: 'generateText', input: options, output: result } );
|
|
26
29
|
|
|
27
30
|
return result.text;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
export async function generateObject(
|
|
33
|
+
export async function generateObject( options ) {
|
|
34
|
+
const {
|
|
35
|
+
prompt,
|
|
36
|
+
schema,
|
|
37
|
+
schemaName,
|
|
38
|
+
schemaDescription,
|
|
39
|
+
output = 'object',
|
|
40
|
+
...aiSdkOptions
|
|
41
|
+
} = options;
|
|
42
|
+
|
|
31
43
|
const provider = providers[prompt.config.provider];
|
|
32
44
|
const model = provider( prompt.config.model );
|
|
33
45
|
|
|
34
46
|
const result = await aiGenerateObject( {
|
|
35
47
|
model,
|
|
36
|
-
schema
|
|
37
|
-
schemaName
|
|
38
|
-
schemaDescription
|
|
39
|
-
output
|
|
48
|
+
schema,
|
|
49
|
+
schemaName,
|
|
50
|
+
schemaDescription,
|
|
51
|
+
output,
|
|
40
52
|
messages: prompt.messages,
|
|
41
53
|
temperature: prompt.config.temperature,
|
|
42
|
-
maxOutputTokens: prompt.config.max_tokens ?? 64000
|
|
54
|
+
maxOutputTokens: prompt.config.max_tokens ?? 64000,
|
|
55
|
+
...aiSdkOptions // Spread remaining AI SDK options
|
|
43
56
|
} );
|
|
44
57
|
|
|
45
|
-
trace( { lib: 'llm', event: 'generateObject', input:
|
|
58
|
+
trace( { lib: 'llm', event: 'generateObject', input: options, output: result } );
|
|
46
59
|
|
|
47
60
|
return result.object;
|
|
48
61
|
}
|
|
49
|
-
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GenerateTextOptions,
|
|
3
|
+
GenerateObjectOptions
|
|
4
|
+
} from 'ai';
|
|
5
|
+
|
|
1
6
|
export interface Prompt {
|
|
2
7
|
config: {
|
|
3
8
|
provider: 'anthropic' | 'openai';
|
|
@@ -11,23 +16,29 @@ export interface Prompt {
|
|
|
11
16
|
}>;
|
|
12
17
|
}
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
// Omit prompt/messages from AI SDK options and add our Prompt type
|
|
20
|
+
export type GenerateTextOptionsWithPrompt = Omit<
|
|
21
|
+
GenerateTextOptions,
|
|
22
|
+
'prompt' | 'messages' | 'model'
|
|
23
|
+
> & {
|
|
24
|
+
prompt: Prompt,
|
|
25
|
+
};
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
export type GenerateObjectOptionsWithPrompt<SCHEMA> = Omit<
|
|
28
|
+
GenerateObjectOptions<SCHEMA>,
|
|
29
|
+
'prompt' | 'messages' | 'model' | 'schema' | 'schemaName' | 'schemaDescription' | 'output'
|
|
30
|
+
> & {
|
|
31
|
+
prompt: Prompt,
|
|
32
|
+
schema: Record<string, unknown> | object,
|
|
33
|
+
schemaName?: string,
|
|
34
|
+
schemaDescription?: string,
|
|
35
|
+
output?: 'object' | 'array',
|
|
36
|
+
};
|
|
27
37
|
|
|
28
|
-
export function generateText(
|
|
38
|
+
export function generateText(
|
|
39
|
+
options: GenerateTextOptionsWithPrompt
|
|
40
|
+
): Promise<string>;
|
|
29
41
|
|
|
30
42
|
export function generateObject<T = unknown>(
|
|
31
|
-
|
|
32
|
-
llmSchema: LLMSchema
|
|
43
|
+
options: GenerateObjectOptionsWithPrompt<T>
|
|
33
44
|
): Promise<T>;
|
package/src/index.js
CHANGED