@output.ai/llm 0.0.8 → 0.0.10

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@output.ai/llm",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Framework abstraction to interact with LLM models",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/ai_sdk.js CHANGED
@@ -11,7 +11,9 @@ const providers = {
11
11
  openai
12
12
  };
13
13
 
14
- export async function generateText( prompt ) {
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
- maxTokens: prompt.config.max_tokens ?? 1024
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: prompt, output: result } );
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( prompt, llmSchema ) {
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: llmSchema.schema,
37
- schemaName: llmSchema.name,
38
- schemaDescription: llmSchema.description,
39
- output: llmSchema.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 ?? 1024
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: prompt, output: result } );
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
- export class LLMSchema {
15
- name: string;
16
- schema: Record<string, unknown> | object;
17
- description: string;
18
- output: 'object' | 'array';
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
- constructor( options: {
21
- name: string;
22
- description: string;
23
- schema: Record<string, unknown> | object;
24
- output?: 'object' | 'array';
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( prompt: Prompt ): Promise<string>;
38
+ export function generateText(
39
+ options: GenerateTextOptionsWithPrompt
40
+ ): Promise<string>;
29
41
 
30
42
  export function generateObject<T = unknown>(
31
- prompt: Prompt,
32
- llmSchema: LLMSchema
43
+ options: GenerateObjectOptionsWithPrompt<T>
33
44
  ): Promise<T>;