@jaypie/llm 1.1.5 → 1.1.6
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/dist/Llm.d.ts +12 -3
- package/dist/constants.d.ts +14 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +814 -54
- package/dist/index.js.map +1 -1
- package/dist/providers/AnthropicProvider.class.d.ts +4 -1
- package/dist/providers/{OpenAiProvider.class.d.ts → openai/OpenAiProvider.class.d.ts} +2 -1
- package/dist/providers/openai/index.d.ts +1 -0
- package/dist/providers/openai/operate.d.ts +12 -0
- package/dist/providers/openai/types.d.ts +73 -0
- package/dist/providers/openai/utils.d.ts +59 -0
- package/dist/tools/Toolkit.class.d.ts +15 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/random.d.ts +2 -0
- package/dist/tools/roll.d.ts +2 -0
- package/dist/tools/time.d.ts +2 -0
- package/dist/tools/weather.d.ts +2 -0
- package/dist/types/LlmProvider.interface.d.ts +21 -0
- package/dist/types/LlmTool.interface.d.ts +8 -0
- package/dist/util/random.d.ts +39 -0
- package/package.json +7 -5
- package/dist/__tests__/Llm.class.spec.d.ts +0 -1
- package/dist/__tests__/constants.spec.d.ts +0 -1
- package/dist/__tests__/index.spec.d.ts +0 -1
- package/dist/providers/__tests__/OpenAiProvider.spec.d.ts +0 -1
- package/dist/util/__tests__/naturalZodSchema.spec.d.ts +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/constants.ts","../src/util/naturalZodSchema.ts","../src/providers/OpenAiProvider.class.ts","../src/providers/AnthropicProvider.class.ts","../src/Llm.ts"],"sourcesContent":["export const PROVIDER = {\n ANTHROPIC: {\n MODEL: {\n CLAUDE_3_HAIKU: \"claude-3-5-haiku-latest\" as const,\n CLAUDE_3_OPUS: \"claude-3-opus-latest\" as const,\n CLAUDE_3_SONNET: \"claude-3-5-sonnet-latest\" as const,\n DEFAULT: \"claude-3-5-sonnet-latest\" as const,\n },\n NAME: \"anthropic\" as const,\n },\n OPENAI: {\n MODEL: {\n DEFAULT: \"gpt-4o\" as const,\n GPT_4: \"gpt-4\" as const,\n GPT_4_O: \"gpt-4o\" as const,\n },\n NAME: \"openai\" as const,\n },\n} as const;\n\nexport type LlmProviderName =\n | typeof PROVIDER.OPENAI.NAME\n | typeof PROVIDER.ANTHROPIC.NAME;\n\n// Last: Defaults\nexport const DEFAULT = {\n PROVIDER: PROVIDER.OPENAI,\n} as const;\n","import { z } from \"zod\";\nimport { NaturalSchema } from \"@jaypie/types\";\n\nexport default function naturalZodSchema(\n definition: NaturalSchema,\n): z.ZodTypeAny {\n if (Array.isArray(definition)) {\n if (definition.length === 0) {\n // Handle empty array - accept any[]\n return z.array(z.any());\n } else if (definition.length === 1) {\n // Handle array types\n const itemType = definition[0];\n switch (itemType) {\n case String:\n return z.array(z.string());\n case Number:\n return z.array(z.number());\n case Boolean:\n return z.array(z.boolean());\n default:\n if (typeof itemType === \"object\") {\n // Handle array of objects\n return z.array(naturalZodSchema(itemType));\n }\n // Handle enum arrays\n return z.enum(definition as [string, ...string[]]);\n }\n } else {\n // Handle enum arrays\n return z.enum(definition as [string, ...string[]]);\n }\n } else if (definition && typeof definition === \"object\") {\n if (Object.keys(definition).length === 0) {\n // Handle empty object - accept any key-value pairs\n return z.record(z.string(), z.any());\n } else {\n // Handle object with properties\n const schemaShape: Record<string, z.ZodTypeAny> = {};\n for (const [key, value] of Object.entries(definition)) {\n schemaShape[key] = naturalZodSchema(value);\n }\n return z.object(schemaShape);\n }\n } else {\n switch (definition) {\n case String:\n return z.string();\n case Number:\n return z.number();\n case Boolean:\n return z.boolean();\n case Object:\n return z.record(z.string(), z.any());\n case Array:\n return z.array(z.any());\n default:\n throw new Error(`Unsupported type: ${definition}`);\n }\n }\n}\n","import { getEnvSecret } from \"@jaypie/aws\";\nimport {\n ConfigurationError,\n JAYPIE,\n log as defaultLog,\n placeholders,\n} from \"@jaypie/core\";\nimport { JsonObject, NaturalSchema } from \"@jaypie/types\";\nimport { OpenAI } from \"openai\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { z } from \"zod\";\nimport { PROVIDER } from \"../constants.js\";\nimport {\n LlmProvider,\n LlmMessageOptions,\n} from \"../types/LlmProvider.interface.js\";\nimport naturalZodSchema from \"../util/naturalZodSchema.js\";\n\nexport class OpenAiProvider implements LlmProvider {\n private model: string;\n private _client?: OpenAI;\n private apiKey?: string;\n private log: typeof defaultLog;\n\n constructor(\n model: string = PROVIDER.OPENAI.MODEL.DEFAULT,\n { apiKey }: { apiKey?: string } = {},\n ) {\n this.model = model;\n this.apiKey = apiKey;\n this.log = defaultLog.lib({ lib: JAYPIE.LIB.LLM });\n }\n\n private async getClient(): Promise<OpenAI> {\n if (this._client) {\n return this._client;\n }\n\n const apiKey = this.apiKey || (await getEnvSecret(\"OPENAI_API_KEY\"));\n if (!apiKey) {\n throw new ConfigurationError(\n \"The application could not resolve the requested keys\",\n );\n }\n\n this._client = new OpenAI({ apiKey });\n this.log.trace(\"Initialized OpenAI client\");\n return this._client;\n }\n\n async send(\n message: string,\n options?: LlmMessageOptions,\n ): Promise<string | JsonObject> {\n const client = await this.getClient();\n const messages = [];\n\n if (options?.system) {\n const content =\n options?.placeholders?.system === false\n ? options.system\n : placeholders(options.system, options?.data);\n const systemMessage = {\n role: \"developer\" as const,\n content,\n };\n messages.push(systemMessage);\n this.log.trace(`System message: ${content?.length} characters`);\n }\n const formattedMessage =\n options?.placeholders?.message === false\n ? message\n : placeholders(message, options?.data);\n const userMessage = {\n role: \"user\" as const,\n content: formattedMessage,\n };\n messages.push(userMessage);\n this.log.trace(`User message: ${formattedMessage?.length} characters`);\n\n if (options?.response) {\n this.log.trace(\"Using structured output\");\n const zodSchema =\n options.response instanceof z.ZodType\n ? options.response\n : naturalZodSchema(options.response as NaturalSchema);\n\n const completion = await client.beta.chat.completions.parse({\n messages,\n model: options?.model || this.model,\n response_format: zodResponseFormat(zodSchema, \"response\"),\n });\n this.log.var({ assistantReply: completion.choices[0].message.parsed });\n return completion.choices[0].message.parsed;\n }\n\n this.log.trace(\"Using text output (unstructured)\");\n const completion = await client.chat.completions.create({\n messages,\n model: options?.model || this.model,\n });\n this.log.trace(\n `Assistant reply: ${completion.choices[0]?.message?.content?.length} characters`,\n );\n\n return completion.choices[0]?.message?.content || \"\";\n }\n}\n","import { JsonObject } from \"@jaypie/types\";\nimport { PROVIDER } from \"../constants.js\";\nimport { LlmProvider } from \"../types/LlmProvider.interface.js\";\n\nexport class AnthropicProvider implements LlmProvider {\n private model: string;\n\n constructor(model: string = PROVIDER.ANTHROPIC.MODEL.DEFAULT) {\n this.model = model;\n }\n\n async send(message: string): Promise<string | JsonObject> {\n // TODO: Implement Anthropic API call\n return `[anthropic ${this.model}] ${message}`;\n }\n}\n","import { JsonObject } from \"@jaypie/types\";\nimport { DEFAULT, LlmProviderName, PROVIDER } from \"./constants.js\";\nimport {\n LlmProvider,\n LlmMessageOptions,\n} from \"./types/LlmProvider.interface.js\";\nimport { OpenAiProvider } from \"./providers/OpenAiProvider.class.js\";\nimport { AnthropicProvider } from \"./providers/AnthropicProvider.class.js\";\n\nclass Llm implements LlmProvider {\n private _provider: LlmProviderName;\n private _llm: LlmProvider;\n\n constructor(providerName: LlmProviderName = DEFAULT.PROVIDER.NAME) {\n this._provider = providerName;\n this._llm = this.createProvider(providerName);\n }\n\n private createProvider(providerName: LlmProviderName): LlmProvider {\n switch (providerName) {\n case PROVIDER.OPENAI.NAME:\n return new OpenAiProvider();\n case PROVIDER.ANTHROPIC.NAME:\n return new AnthropicProvider();\n default:\n throw new Error(`Unsupported provider: ${providerName}`);\n }\n }\n\n async send(\n message: string,\n options?: LlmMessageOptions,\n ): Promise<string | JsonObject> {\n return this._llm.send(message, options);\n }\n\n static async send(\n message: string,\n options?: LlmMessageOptions & { llm?: LlmProviderName },\n ): Promise<string | JsonObject> {\n const { llm, ...messageOptions } = options || {};\n const instance = new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,QAAQ,CAAC,SAAS,CAAC,IAAI;gBAC1B,OAAO,IAAI,iBAAiB,EAAE;AAChC,YAAA;AACE,gBAAA,MAAM,IAAI,KAAK,CAAC,yBAAyB,YAAY,CAAA,CAAE,CAAC;;;AAI9D,IAAA,MAAM,IAAI,CACR,OAAe,EACf,OAA2B,EAAA;QAE3B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;;AAGzC,IAAA,aAAa,IAAI,CACf,OAAe,EACf,OAAuD,EAAA;QAEvD,MAAM,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE;AAChD,QAAA,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC;QAC7B,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC;;AAEhD;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/constants.ts","../src/util/naturalZodSchema.ts","../src/providers/openai/utils.ts","../src/tools/Toolkit.class.ts","../src/providers/openai/operate.ts","../src/providers/openai/OpenAiProvider.class.ts","../src/providers/AnthropicProvider.class.ts","../src/Llm.ts","../src/util/random.ts","../src/tools/random.ts","../src/tools/roll.ts","../src/tools/time.ts","../src/tools/weather.ts","../src/tools/index.ts"],"sourcesContent":["export const PROVIDER = {\n ANTHROPIC: {\n MODEL: {\n CLAUDE_3_HAIKU: \"claude-3-5-haiku-latest\" as const,\n CLAUDE_3_OPUS: \"claude-3-opus-latest\" as const,\n CLAUDE_3_SONNET: \"claude-3-5-sonnet-latest\" as const,\n DEFAULT: \"claude-3-5-sonnet-latest\" as const,\n },\n NAME: \"anthropic\" as const,\n },\n OPENAI: {\n MODEL: {\n DEFAULT: \"gpt-4o\" as const,\n GPT_4: \"gpt-4\" as const,\n GPT_4_O_MINI: \"gpt-4o-mini\" as const,\n GPT_4_O: \"gpt-4o\" as const,\n GPT_4_5: \"gpt-4.5-preview\" as const,\n O1: \"o1\" as const,\n O1_MINI: \"o1-mini\" as const,\n O1_PRO: \"o1-pro\" as const,\n O3_MINI: \"o3-mini\" as const,\n O3_MINI_HIGH: \"o3-mini-high\" as const,\n },\n NAME: \"openai\" as const,\n },\n} as const;\n\nexport type LlmProviderName =\n | typeof PROVIDER.OPENAI.NAME\n | typeof PROVIDER.ANTHROPIC.NAME;\n\n// Last: Defaults\nexport const DEFAULT = {\n PROVIDER: PROVIDER.OPENAI,\n} as const;\n","import { z } from \"zod\";\nimport { NaturalSchema } from \"@jaypie/types\";\n\nexport default function naturalZodSchema(\n definition: NaturalSchema,\n): z.ZodTypeAny {\n if (Array.isArray(definition)) {\n if (definition.length === 0) {\n // Handle empty array - accept any[]\n return z.array(z.any());\n } else if (definition.length === 1) {\n // Handle array types\n const itemType = definition[0];\n switch (itemType) {\n case String:\n return z.array(z.string());\n case Number:\n return z.array(z.number());\n case Boolean:\n return z.array(z.boolean());\n default:\n if (typeof itemType === \"object\") {\n // Handle array of objects\n return z.array(naturalZodSchema(itemType));\n }\n // Handle enum arrays\n return z.enum(definition as [string, ...string[]]);\n }\n } else {\n // Handle enum arrays\n return z.enum(definition as [string, ...string[]]);\n }\n } else if (definition && typeof definition === \"object\") {\n if (Object.keys(definition).length === 0) {\n // Handle empty object - accept any key-value pairs\n return z.record(z.string(), z.any());\n } else {\n // Handle object with properties\n const schemaShape: Record<string, z.ZodTypeAny> = {};\n for (const [key, value] of Object.entries(definition)) {\n schemaShape[key] = naturalZodSchema(value);\n }\n return z.object(schemaShape);\n }\n } else {\n switch (definition) {\n case String:\n return z.string();\n case Number:\n return z.number();\n case Boolean:\n return z.boolean();\n case Object:\n return z.record(z.string(), z.any());\n case Array:\n return z.array(z.any());\n default:\n throw new Error(`Unsupported type: ${definition}`);\n }\n }\n}\n","import { getEnvSecret } from \"@jaypie/aws\";\nimport {\n ConfigurationError,\n log as defaultLog,\n placeholders as replacePlaceholders,\n JAYPIE,\n} from \"@jaypie/core\";\nimport { JsonObject, NaturalSchema } from \"@jaypie/types\";\nimport { OpenAI } from \"openai\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { z } from \"zod\";\nimport { LlmMessageOptions } from \"../../types/LlmProvider.interface.js\";\nimport naturalZodSchema from \"../../util/naturalZodSchema.js\";\n\n// Logger\nexport const getLogger = () => defaultLog.lib({ lib: JAYPIE.LIB.LLM });\n\n// Client initialization\nexport async function initializeClient({\n apiKey,\n}: {\n apiKey?: string;\n} = {}): Promise<OpenAI> {\n const logger = getLogger();\n const resolvedApiKey = apiKey || (await getEnvSecret(\"OPENAI_API_KEY\"));\n\n if (!resolvedApiKey) {\n throw new ConfigurationError(\n \"The application could not resolve the requested keys\",\n );\n }\n\n const client = new OpenAI({ apiKey: resolvedApiKey });\n logger.trace(\"Initialized OpenAI client\");\n return client;\n}\n\n// Message formatting\nexport interface ChatMessage {\n role: \"user\" | \"developer\";\n content: string;\n}\n\nexport function formatSystemMessage(\n systemPrompt: string,\n { data, placeholders }: Pick<LlmMessageOptions, \"data\" | \"placeholders\"> = {},\n): ChatMessage {\n const content =\n placeholders?.system === false\n ? systemPrompt\n : replacePlaceholders(systemPrompt, data);\n\n return {\n role: \"developer\" as const,\n content,\n };\n}\n\nexport function formatUserMessage(\n message: string,\n { data, placeholders }: Pick<LlmMessageOptions, \"data\" | \"placeholders\"> = {},\n): ChatMessage {\n const content =\n placeholders?.message === false\n ? message\n : replacePlaceholders(message, data);\n\n return {\n role: \"user\" as const,\n content,\n };\n}\n\nexport function prepareMessages(\n message: string,\n { system, data, placeholders }: LlmMessageOptions = {},\n): ChatMessage[] {\n const logger = getLogger();\n const messages: ChatMessage[] = [];\n\n if (system) {\n const systemMessage = formatSystemMessage(system, { data, placeholders });\n messages.push(systemMessage);\n logger.trace(`System message: ${systemMessage.content?.length} characters`);\n }\n\n const userMessage = formatUserMessage(message, { data, placeholders });\n messages.push(userMessage);\n logger.trace(`User message: ${userMessage.content?.length} characters`);\n\n return messages;\n}\n\n// Completion requests\nexport async function createStructuredCompletion(\n client: OpenAI,\n {\n messages,\n responseSchema,\n model,\n }: {\n messages: ChatMessage[];\n responseSchema: z.ZodType | NaturalSchema;\n model: string;\n },\n): Promise<JsonObject> {\n const logger = getLogger();\n logger.trace(\"Using structured output\");\n\n const zodSchema =\n responseSchema instanceof z.ZodType\n ? responseSchema\n : naturalZodSchema(responseSchema as NaturalSchema);\n\n const completion = await client.beta.chat.completions.parse({\n messages,\n model,\n response_format: zodResponseFormat(zodSchema, \"response\"),\n });\n\n logger.var({ assistantReply: completion.choices[0].message.parsed });\n return completion.choices[0].message.parsed;\n}\n\nexport async function createTextCompletion(\n client: OpenAI,\n {\n messages,\n model,\n }: {\n messages: ChatMessage[];\n model: string;\n },\n): Promise<string> {\n const logger = getLogger();\n logger.trace(\"Using text output (unstructured)\");\n\n const completion = await client.chat.completions.create({\n messages,\n model,\n });\n\n logger.trace(\n `Assistant reply: ${completion.choices[0]?.message?.content?.length} characters`,\n );\n\n return completion.choices[0]?.message?.content || \"\";\n}\n","import { LlmTool } from \"../types/LlmTool.interface\";\n\nconst DEFAULT_TOOL_TYPE = \"function\";\n\nexport interface ToolkitOptions {\n explain?: boolean;\n}\n\nexport class Toolkit {\n private readonly _tools: LlmTool[];\n private readonly _options: ToolkitOptions;\n private readonly explain: boolean;\n\n constructor(tools: LlmTool[], options?: ToolkitOptions) {\n this._tools = tools;\n this._options = options || {};\n this.explain = this._options.explain ? true : false;\n }\n\n get tools(): Omit<LlmTool, \"call\">[] {\n return this._tools.map((tool) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const toolCopy: any = { ...tool };\n delete toolCopy.call;\n\n if (this.explain && toolCopy.parameters?.type === \"object\") {\n if (toolCopy.parameters?.properties) {\n if (!toolCopy.parameters.properties.__Explanation) {\n toolCopy.parameters.properties.__Explanation = {\n type: \"string\",\n description:\n \"Explain the reasoning behind this function call. What is the expected result? Describe possible next steps and the conditions under which they should be taken.\",\n };\n }\n }\n }\n\n // Set default type if not provided\n if (!toolCopy.type) {\n toolCopy.type = DEFAULT_TOOL_TYPE;\n }\n\n return toolCopy;\n });\n }\n\n async call({ name, arguments: args }: { name: string; arguments: string }) {\n const tool = this._tools.find((t) => t.name === name);\n if (!tool) {\n throw new Error(`Tool '${name}' not found`);\n }\n\n let parsedArgs;\n try {\n parsedArgs = JSON.parse(args);\n if (this.explain) {\n delete parsedArgs.__Explanation;\n }\n } catch {\n parsedArgs = args;\n }\n\n const result = tool.call(parsedArgs);\n\n if (result instanceof Promise) {\n return await result;\n }\n\n return result;\n }\n}\n","import { sleep, placeholders } from \"@jaypie/core\";\nimport { BadGatewayError } from \"@jaypie/errors\";\nimport { JsonObject, NaturalSchema } from \"@jaypie/types\";\nimport {\n APIConnectionError,\n APIConnectionTimeoutError,\n APIUserAbortError,\n AuthenticationError,\n BadRequestError,\n ConflictError,\n InternalServerError,\n NotFoundError,\n OpenAI,\n PermissionDeniedError,\n RateLimitError,\n UnprocessableEntityError,\n} from \"openai\";\nimport { zodResponseFormat } from \"openai/helpers/zod\";\nimport { z } from \"zod\";\nimport naturalZodSchema from \"../../util/naturalZodSchema.js\";\nimport { LlmOperateOptions } from \"../../types/LlmProvider.interface.js\";\nimport { getLogger } from \"./utils.js\";\nimport { PROVIDER } from \"../../constants.js\";\nimport { Toolkit } from \"../../tools/Toolkit.class.js\";\nimport {\n OpenAIRawResponse,\n OpenAIResponse,\n OpenAIResponseTurn,\n} from \"./types.js\";\n\n// Constants\n\nexport const MAX_RETRIES_ABSOLUTE_LIMIT = 72;\nexport const MAX_RETRIES_DEFAULT_LIMIT = 6;\n\n// Retry policy constants\nconst INITIAL_RETRY_DELAY_MS = 1000; // 1 second\nconst MAX_RETRY_DELAY_MS = 32000; // 32 seconds\nconst RETRY_BACKOFF_FACTOR = 2; // Exponential backoff multiplier\n\nconst RETRYABLE_ERRORS = [\n APIConnectionError,\n APIConnectionTimeoutError,\n InternalServerError,\n];\n\nconst NOT_RETRYABLE_ERRORS = [\n APIUserAbortError,\n AuthenticationError,\n BadRequestError,\n ConflictError,\n NotFoundError,\n PermissionDeniedError,\n RateLimitError,\n UnprocessableEntityError,\n];\n\n// Turn policy constants\nexport const MAX_TURNS_ABSOLUTE_LIMIT = 72;\nexport const MAX_TURNS_DEFAULT_LIMIT = 12;\n\n//\n//\n// Helpers\n//\n\nexport function maxTurnsFromOptions(options: LlmOperateOptions): number {\n // Default to single turn (1) when turns are disabled\n\n // Handle the turns parameter\n if (options.turns === undefined) {\n // Default to default limit when undefined\n return MAX_TURNS_DEFAULT_LIMIT;\n } else if (options.turns === true) {\n // Explicitly set to true\n return MAX_TURNS_DEFAULT_LIMIT;\n } else if (typeof options.turns === \"number\") {\n if (options.turns > 0) {\n // Positive number - use that limit (capped at absolute limit)\n return Math.min(options.turns, MAX_TURNS_ABSOLUTE_LIMIT);\n } else if (options.turns < 0) {\n // Negative number - use default limit\n return MAX_TURNS_DEFAULT_LIMIT;\n }\n // If turns is 0, return 1 (disabled)\n return 1;\n }\n // All other values (false, null, etc.) will return 1 (disabled)\n return 1;\n}\n\n//\n//\n// Main\n//\n\nexport async function operate(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input: string | any[],\n options: LlmOperateOptions = {},\n context: { client: OpenAI; maxRetries?: number } = {\n client: new OpenAI(),\n },\n): Promise<OpenAIResponse> {\n const log = getLogger();\n const openai = context.client;\n\n // Validate\n if (!context.maxRetries) {\n context.maxRetries = MAX_RETRIES_DEFAULT_LIMIT;\n }\n const model = options?.model || PROVIDER.OPENAI.MODEL.DEFAULT;\n\n // Setup\n let retryCount = 0;\n let retryDelay = INITIAL_RETRY_DELAY_MS;\n const maxRetries = Math.min(context.maxRetries, MAX_RETRIES_ABSOLUTE_LIMIT);\n const allResponses: OpenAIResponseTurn[] = [];\n\n // Determine max turns from options\n const maxTurns = maxTurnsFromOptions(options);\n const enableMultipleTurns = maxTurns > 1;\n let currentTurn = 0;\n let currentInput = input;\n let toolkit: Toolkit | undefined;\n const explain = options?.explain ?? false;\n\n // Initialize toolkit if tools are provided\n if (options.tools?.length) {\n toolkit = new Toolkit(options.tools, { explain });\n }\n\n // OpenAI Multi-turn Loop\n while (currentTurn < maxTurns) {\n currentTurn++;\n retryCount = 0;\n retryDelay = INITIAL_RETRY_DELAY_MS;\n\n // OpenAI Retry Loop\n while (true) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const requestOptions: /* OpenAI.Responses.InputItems */ any = {\n model,\n input:\n typeof currentInput === \"string\" &&\n options?.data &&\n (options.placeholders?.input === undefined ||\n options.placeholders?.input)\n ? placeholders(currentInput, options.data)\n : currentInput,\n };\n\n if (options?.user) {\n requestOptions.user = options.user;\n }\n\n // Add any provider-specific options\n if (options?.providerOptions) {\n Object.assign(requestOptions, options.providerOptions);\n }\n\n if (options?.instructions) {\n // Apply placeholders to instructions if data is provided and placeholders.instructions is undefined or true\n requestOptions.instructions =\n options.data &&\n (options.placeholders?.instructions === undefined ||\n options.placeholders?.instructions)\n ? placeholders(options.instructions, options.data)\n : options.instructions;\n } else if ((options as unknown as { system: string })?.system) {\n // Check for illegal system option, use it as instructions, and log a warning\n log.warn(\"[operate] Use 'instructions' instead of 'system'.\");\n // Apply placeholders to system if data is provided and placeholders.instructions is undefined or true\n requestOptions.instructions =\n options.data &&\n (options.placeholders?.instructions === undefined ||\n options.placeholders?.instructions)\n ? placeholders(\n (options as unknown as { system: string }).system,\n options.data,\n )\n : (options as unknown as { system: string }).system;\n }\n\n if (options?.format) {\n // Check if format is a JsonObject with type \"json_schema\"\n if (\n typeof options.format === \"object\" &&\n options.format !== null &&\n !Array.isArray(options.format) &&\n (options.format as JsonObject).type === \"json_schema\"\n ) {\n // Direct pass-through for JsonObject with type \"json_schema\"\n requestOptions.text = {\n format: options.format,\n };\n } else {\n // Convert NaturalSchema to Zod schema if needed\n const zodSchema =\n options.format instanceof z.ZodType\n ? options.format\n : naturalZodSchema(options.format as NaturalSchema);\n const responseFormat = zodResponseFormat(zodSchema, \"response\");\n\n // Set up structured output format in the format expected by the test\n requestOptions.text = {\n format: {\n name: responseFormat.json_schema.name,\n schema: responseFormat.json_schema.schema,\n strict: responseFormat.json_schema.strict,\n type: responseFormat.type,\n },\n };\n }\n }\n\n // Add tools if toolkit is initialized\n if (toolkit) {\n requestOptions.tools = toolkit.tools;\n }\n\n if (currentTurn > 1) {\n log.trace(`[operate] Calling OpenAI Responses API - ${currentTurn}`);\n } else {\n log.trace(\"[operate] Calling OpenAI Responses API\");\n }\n\n log.var({ requestOptions });\n // Use type assertion to handle the OpenAI SDK response type\n const currentResponse = (await openai.responses.create(\n requestOptions,\n )) as unknown as OpenAIRawResponse;\n if (retryCount > 0) {\n log.debug(`OpenAI API call succeeded after ${retryCount} retries`);\n }\n // Add the entire response to allResponses\n allResponses.push(currentResponse as unknown as OpenAIResponseTurn);\n\n // Check if we need to process function calls for multi-turn conversations\n let hasFunctionCall = false;\n\n try {\n if (currentResponse.output && Array.isArray(currentResponse.output)) {\n // New OpenAI API format with output array\n for (const output of currentResponse.output) {\n if (output.type === \"function_call\") {\n hasFunctionCall = true;\n\n if (toolkit && enableMultipleTurns) {\n try {\n // Parse arguments for validation\n JSON.parse(output.arguments);\n\n // Call the tool and ensure the result is resolved if it's a Promise\n log.trace(`[operate] Calling tool - ${output.name}`);\n const result = await toolkit.call({\n name: output.name,\n arguments: output.arguments,\n });\n\n // Prepare for next turn by adding function call and result\n // Add the function call to the input for the next turn\n if (typeof currentInput === \"string\") {\n // Convert string input to array format for the first turn\n currentInput = [{ content: currentInput, role: \"user\" }];\n }\n\n // Add model's function call and result\n if (Array.isArray(currentInput)) {\n currentInput.push(output);\n // Add function call result\n currentInput.push({\n type: \"function_call_output\",\n call_id: output.call_id,\n output: JSON.stringify(result),\n });\n }\n } catch (error) {\n log.error(\n `Error executing function call ${output.name}:`,\n error,\n );\n // We don't add error messages to allResponses here as we want to keep the original response objects\n }\n } else if (!toolkit) {\n log.warn(\n \"Model requested function call but no toolkit available\",\n );\n }\n }\n }\n }\n } catch (error) {\n // If there's an error processing the response, log it but don't fail\n // This helps with test mocks that might not have the expected structure\n log.warn(\"Error processing response for function calls\");\n log.var({ error });\n }\n\n // If there's no function call or we can't take another turn, exit the loop\n if (!hasFunctionCall || !enableMultipleTurns) {\n return allResponses;\n }\n\n // If we've reached the maximum number of turns, exit the loop\n if (currentTurn >= maxTurns) {\n log.warn(\n `Model requested function call but exceeded ${maxTurns} turns`,\n );\n return allResponses;\n }\n\n // Continue to next turn\n break;\n } catch (error: unknown) {\n // Check if we've reached the maximum number of retries\n if (retryCount >= maxRetries) {\n log.error(`OpenAI API call failed after ${maxRetries} retries`);\n log.var({ error });\n throw new BadGatewayError();\n }\n\n // Check if the error is not retryable\n let isNotRetryable = false;\n for (const notRetryableError of NOT_RETRYABLE_ERRORS) {\n if (error instanceof notRetryableError) {\n isNotRetryable = true;\n break;\n }\n }\n\n if (isNotRetryable) {\n log.error(\"OpenAI API call failed with non-retryable error\");\n log.var({ error });\n throw new BadGatewayError();\n }\n\n // Warn if this error is not in our known retryable errors\n let isUnknownError = true;\n for (const retryableError of RETRYABLE_ERRORS) {\n if (error instanceof retryableError) {\n isUnknownError = false;\n break;\n }\n }\n if (isUnknownError) {\n log.warn(\"OpenAI API returned unknown error\");\n log.var({ error });\n }\n\n // Log the error and retry\n log.warn(`OpenAI API call failed. Retrying in ${retryDelay}ms...`);\n\n // Wait before retrying\n await sleep(retryDelay);\n\n // Increase retry count and delay for next attempt (exponential backoff)\n retryCount++;\n retryDelay = Math.min(\n retryDelay * RETRY_BACKOFF_FACTOR,\n MAX_RETRY_DELAY_MS,\n );\n }\n }\n }\n\n // If we've reached the maximum number of turns, return all responses\n return allResponses;\n}\n","import { JsonObject } from \"@jaypie/types\";\nimport { OpenAI } from \"openai\";\nimport { PROVIDER } from \"../../constants.js\";\nimport {\n LlmMessageOptions,\n LlmOperateOptions,\n LlmProvider,\n} from \"../../types/LlmProvider.interface.js\";\nimport { operate } from \"./operate.js\";\nimport {\n createStructuredCompletion,\n createTextCompletion,\n getLogger,\n initializeClient,\n prepareMessages,\n} from \"./utils.js\";\n\nexport class OpenAiProvider implements LlmProvider {\n private model: string;\n private _client?: OpenAI;\n private apiKey?: string;\n private log = getLogger();\n\n constructor(\n model: string = PROVIDER.OPENAI.MODEL.DEFAULT,\n { apiKey }: { apiKey?: string } = {},\n ) {\n this.model = model;\n this.apiKey = apiKey;\n }\n\n private async getClient(): Promise<OpenAI> {\n if (this._client) {\n return this._client;\n }\n\n this._client = await initializeClient({ apiKey: this.apiKey });\n return this._client;\n }\n\n async send(\n message: string,\n options?: LlmMessageOptions,\n ): Promise<string | JsonObject> {\n const client = await this.getClient();\n const messages = prepareMessages(message, options || {});\n const modelToUse = options?.model || this.model;\n\n if (options?.response) {\n return createStructuredCompletion(client, {\n messages,\n responseSchema: options.response,\n model: modelToUse,\n });\n }\n\n return createTextCompletion(client, {\n messages,\n model: modelToUse,\n });\n }\n\n async operate(\n input: string,\n options: LlmOperateOptions = {},\n ): Promise<unknown> {\n const client = await this.getClient();\n options.model = options?.model || this.model;\n\n return operate(input, options, { client });\n }\n}\n","import { JsonObject } from \"@jaypie/types\";\nimport { PROVIDER } from \"../constants.js\";\nimport { LlmProvider } from \"../types/LlmProvider.interface.js\";\n\nexport class AnthropicProvider implements LlmProvider {\n private model: string;\n private apiKey?: string;\n\n constructor(\n model: string = PROVIDER.ANTHROPIC.MODEL.DEFAULT,\n { apiKey }: { apiKey?: string } = {},\n ) {\n this.model = model;\n this.apiKey = apiKey;\n }\n\n async send(message: string): Promise<string | JsonObject> {\n // TODO: Implement Anthropic API call\n return `[anthropic ${this.model}] ${message}`;\n }\n}\n","import { JsonArray, JsonObject } from \"@jaypie/types\";\nimport { NotImplementedError } from \"@jaypie/errors\";\nimport { DEFAULT, LlmProviderName, PROVIDER } from \"./constants.js\";\nimport {\n LlmProvider,\n LlmMessageOptions,\n LlmOperateOptions,\n LlmOptions,\n} from \"./types/LlmProvider.interface.js\";\nimport { OpenAiProvider } from \"./providers/openai/index.js\";\nimport { AnthropicProvider } from \"./providers/AnthropicProvider.class.js\";\n\nclass Llm implements LlmProvider {\n private _provider: LlmProviderName;\n private _llm: LlmProvider;\n private _options: LlmOptions;\n\n constructor(\n providerName: LlmProviderName = DEFAULT.PROVIDER.NAME,\n options: LlmOptions = {},\n ) {\n this._provider = providerName;\n this._options = options;\n this._llm = this.createProvider(providerName, options);\n }\n\n private createProvider(\n providerName: LlmProviderName,\n options: LlmOptions = {},\n ): LlmProvider {\n const { apiKey, model } = options;\n\n switch (providerName) {\n case PROVIDER.OPENAI.NAME:\n return new OpenAiProvider(model || PROVIDER.OPENAI.MODEL.DEFAULT, {\n apiKey,\n });\n case PROVIDER.ANTHROPIC.NAME:\n return new AnthropicProvider(\n model || PROVIDER.ANTHROPIC.MODEL.DEFAULT,\n { apiKey },\n );\n default:\n throw new Error(`Unsupported provider: ${providerName}`);\n }\n }\n\n async send(\n message: string,\n options?: LlmMessageOptions,\n ): Promise<string | JsonObject> {\n return this._llm.send(message, options);\n }\n\n async operate(\n message: string,\n options: LlmOperateOptions = {},\n ): Promise<JsonArray> {\n if (!this._llm.operate) {\n throw new NotImplementedError(\n `Provider ${this._provider} does not support operate method`,\n );\n }\n return this._llm.operate(message, options) as Promise<JsonArray>;\n }\n\n static async send(\n message: string,\n options?: LlmMessageOptions & {\n llm?: LlmProviderName;\n apiKey?: string;\n model?: string;\n },\n ): Promise<string | JsonObject> {\n const { llm, apiKey, model, ...messageOptions } = options || {};\n const instance = new Llm(llm, { apiKey, model });\n return instance.send(message, messageOptions);\n }\n\n static async operate(\n message: string,\n options?: LlmOperateOptions & {\n llm?: LlmProviderName;\n apiKey?: string;\n model?: string;\n },\n ): Promise<JsonArray> {\n const { llm, apiKey, model, ...operateOptions } = options || {};\n const instance = new Llm(llm, { apiKey, model });\n return instance.operate(message, operateOptions);\n }\n}\n\nexport default Llm;\n","import RandomLib from \"random\";\nimport { ConfigurationError } from \"@jaypie/errors\";\n\n//\n// Types\n//\n\ninterface RandomOptions {\n min?: number;\n max?: number;\n mean?: number;\n stddev?: number;\n integer?: boolean;\n start?: number;\n seed?: string;\n precision?: number;\n currency?: boolean;\n}\n\ntype RandomFunction = {\n (options?: RandomOptions): number;\n};\n\n//\n// Constants\n//\n\nexport const DEFAULT_MIN = 0;\nexport const DEFAULT_MAX = 1;\n\n//\n// Helper Functions\n//\n\n/**\n * Clamps a number between optional minimum and maximum values\n * @param num - The number to clamp\n * @param min - Optional minimum value\n * @param max - Optional maximum value\n * @returns The clamped number\n */\nconst clamp = (num: number, min?: number, max?: number): number => {\n let result = num;\n if (typeof min === \"number\") result = Math.max(result, min);\n if (typeof max === \"number\") result = Math.min(result, max);\n return result;\n};\n\n/**\n * Validates that min is not greater than max\n * @param min - Optional minimum value\n * @param max - Optional maximum value\n * @throws {ConfigurationError} If min is greater than max\n */\nconst validateBounds = (\n min: number | undefined,\n max: number | undefined,\n): void => {\n if (typeof min === \"number\" && typeof max === \"number\" && min > max) {\n throw new ConfigurationError(\n `Invalid bounds: min (${min}) cannot be greater than max (${max})`,\n );\n }\n};\n\n//\n// Main\n//\n\n/**\n * Creates a random number generator with optional seeding\n *\n * @param defaultSeed - Seed string for the default RNG\n * @returns A function that generates random numbers based on provided options\n *\n * @example\n * const rng = random(\"default-seed\");\n *\n * // Generate a random float between 0 and 1\n * const basic = rng();\n *\n * // Generate an integer between 1 and 10\n * const integer = rng({ min: 1, max: 10, integer: true });\n *\n * // Generate from normal distribution\n * const normal = rng({ mean: 50, stddev: 10 });\n *\n * // Use consistent seeding\n * const seeded = rng({ seed: \"my-seed\" });\n */\nconst random = (defaultSeed?: string): RandomFunction => {\n // Initialize default seeded RNG\n const defaultRng = RandomLib.clone(defaultSeed);\n\n // Store per-seed RNGs\n const seedMap = new Map<string, ReturnType<typeof RandomLib.clone>>();\n\n const rngFn = ({\n min,\n max: providedMax,\n mean,\n stddev,\n integer = false,\n start = 0,\n seed,\n precision,\n currency = false,\n }: RandomOptions = {}): number => {\n // Select the appropriate RNG based on seed\n const rng = seed\n ? seedMap.get(seed) ||\n (() => {\n const newRng = RandomLib.clone(seed);\n seedMap.set(seed, newRng);\n return newRng;\n })()\n : defaultRng;\n\n // If only min is set, set max to min*2, but keep track of whether max was provided\n let max = providedMax;\n if (typeof min === \"number\" && typeof max !== \"number\") {\n max = min * 2;\n }\n\n validateBounds(min, max);\n\n // Determine effective precision based on parameters\n const getEffectivePrecision = (): number | undefined => {\n if (integer) return 0;\n\n const precisions: number[] = [];\n if (typeof precision === \"number\" && precision >= 0) {\n precisions.push(precision);\n }\n if (currency) {\n precisions.push(2);\n }\n\n // Return the lowest precision if any are set, undefined otherwise\n return precisions.length > 0 ? Math.min(...precisions) : undefined;\n };\n\n // Helper function to apply precision\n const applyPrecision = (value: number): number => {\n const effectivePrecision = getEffectivePrecision();\n if (typeof effectivePrecision === \"number\") {\n const factor = Math.pow(10, effectivePrecision);\n return Math.round(value * factor) / factor;\n }\n return value;\n };\n\n // Use normal distribution if both mean and stddev are provided\n if (typeof mean === \"number\" && typeof stddev === \"number\") {\n const normalDist = rng.normal(mean, stddev);\n const value = normalDist();\n\n // Only clamp if min/max are defined\n const clampedValue = clamp(value, min, providedMax);\n\n // Switch to uniform distribution only if both bounds were explicitly provided and exceeded\n if (\n typeof min === \"number\" &&\n typeof providedMax === \"number\" &&\n clampedValue !== value\n ) {\n const baseValue = integer ? rng.int(min, max) : rng.float(min, max);\n return applyPrecision(start + baseValue);\n }\n\n return applyPrecision(\n start + (integer ? Math.round(clampedValue) : clampedValue),\n );\n }\n\n // For uniform distribution, use defaults if min/max are undefined\n const uniformMin = typeof min === \"number\" ? min : DEFAULT_MIN;\n const uniformMax = typeof max === \"number\" ? max : DEFAULT_MAX;\n\n const baseValue = integer\n ? rng.int(uniformMin, uniformMax)\n : rng.float(uniformMin, uniformMax);\n return applyPrecision(start + baseValue);\n };\n\n return rngFn;\n};\n\n//\n// Export\n//\n\nexport default random;\n","import { LlmTool } from \"../types/LlmTool.interface.js\";\nimport randomUtil from \"../util/random.js\";\n\nexport const random: LlmTool = {\n description:\n \"Generate a random number with optional distribution, precision, range, and seeding\",\n\n name: \"random\",\n parameters: {\n type: \"object\",\n properties: {\n min: {\n type: \"number\",\n description:\n \"Minimum value (inclusive). Default: 0. When used with mean/stddev, acts as a clamp on the normal distribution\",\n },\n max: {\n type: \"number\",\n description:\n \"Maximum value (inclusive). Default: 1. When used with mean/stddev, acts as a clamp on the normal distribution\",\n },\n mean: {\n type: \"number\",\n description:\n \"Mean value for normal distribution. When set with stddev, uses normal distribution (clamped by min/max if provided)\",\n },\n stddev: {\n type: \"number\",\n description:\n \"Standard deviation for normal distribution. When set with mean, uses normal distribution (clamped by min/max if provided)\",\n },\n integer: {\n type: \"boolean\",\n description: \"Whether to return an integer value. Default: false\",\n },\n seed: {\n type: \"string\",\n description:\n \"Seed string for consistent random generation. Default: undefined (uses default RNG)\",\n },\n precision: {\n type: \"number\",\n description:\n \"Number of decimal places for the result. Default: undefined (full precision)\",\n },\n currency: {\n type: \"boolean\",\n description:\n \"Whether to format as currency (2 decimal places). Default: false\",\n },\n },\n required: [],\n },\n type: \"function\",\n call: (options) => {\n const rng = randomUtil();\n return rng(options);\n },\n};\n","import { LlmTool } from \"../types/LlmTool.interface.js\";\nimport random from \"../util/random.js\";\n\nexport const roll: LlmTool = {\n description: \"Roll one or more dice with a specified number of sides\",\n name: \"roll\",\n parameters: {\n type: \"object\",\n properties: {\n number: {\n type: \"number\",\n description: \"Number of dice to roll. Default: 1\",\n },\n sides: {\n type: \"number\",\n description: \"Number of sides on each die. Default: 6\",\n },\n },\n required: [\"number\", \"sides\"],\n },\n type: \"function\",\n call: ({ number = 1, sides = 6 }) => {\n const rng = random();\n const rolls: number[] = [];\n let total = 0;\n\n for (let i = 0; i < number; i++) {\n const rollValue = rng({ min: 1, max: sides, integer: true });\n rolls.push(rollValue);\n total += rollValue;\n }\n\n return { rolls, total };\n },\n};\n","import { LlmTool } from \"../types/LlmTool.interface.js\";\n\nexport const time: LlmTool = {\n description:\n \"Returns the provided date as an ISO UTC string or the current time if no date provided.\",\n name: \"time\",\n parameters: {\n type: \"object\",\n properties: {\n date: {\n type: \"string\",\n description:\n \"Date string to convert to ISO UTC format. Default: current time\",\n },\n },\n required: [],\n },\n type: \"function\",\n call: ({ date } = {}) => {\n if (date) {\n const parsedDate = new Date(date);\n if (isNaN(parsedDate.getTime())) {\n throw new Error(`Invalid date format: ${date}`);\n }\n return parsedDate.toISOString();\n }\n return new Date().toISOString();\n },\n};\n","import { LlmTool } from \"../types/LlmTool.interface.js\";\nimport { fetchWeatherApi } from \"openmeteo\";\n\nexport const weather: LlmTool = {\n description: \"Get current weather and forecast data for a specific location\",\n name: \"weather\",\n parameters: {\n type: \"object\",\n properties: {\n latitude: {\n type: \"number\",\n description:\n \"Latitude of the location. Default: 42.051554533384866 (Evanston, IL)\",\n },\n longitude: {\n type: \"number\",\n description:\n \"Longitude of the location. Default: -87.6759911441785 (Evanston, IL)\",\n },\n timezone: {\n type: \"string\",\n description: \"Timezone for the location. Default: America/Chicago\",\n },\n past_days: {\n type: \"number\",\n description:\n \"Number of past days to include in the forecast. Default: 1\",\n },\n forecast_days: {\n type: \"number\",\n description: \"Number of forecast days to include. Default: 1\",\n },\n },\n required: [],\n },\n type: \"function\",\n call: async ({\n latitude = 42.051554533384866,\n longitude = -87.6759911441785,\n timezone = \"America/Chicago\",\n past_days = 1,\n forecast_days = 1,\n } = {}) => {\n try {\n const params = {\n latitude,\n longitude,\n hourly: [\n \"temperature_2m\",\n \"precipitation_probability\",\n \"precipitation\",\n ],\n current: [\n \"temperature_2m\",\n \"is_day\",\n \"showers\",\n \"cloud_cover\",\n \"wind_speed_10m\",\n \"relative_humidity_2m\",\n \"precipitation\",\n \"snowfall\",\n \"rain\",\n \"apparent_temperature\",\n ],\n timezone,\n past_days,\n forecast_days,\n wind_speed_unit: \"mph\",\n temperature_unit: \"fahrenheit\",\n precipitation_unit: \"inch\",\n };\n\n const url = \"https://api.open-meteo.com/v1/forecast\";\n const responses = await fetchWeatherApi(url, params);\n\n // Helper function to form time ranges\n const range = (start: number, stop: number, step: number) =>\n Array.from(\n { length: (stop - start) / step },\n (_, i) => start + i * step,\n );\n\n // Process first location\n const response = responses[0];\n\n // Attributes for timezone and location\n const utcOffsetSeconds = response.utcOffsetSeconds();\n const timezoneAbbreviation = response.timezoneAbbreviation();\n\n const current = response.current()!;\n const hourly = response.hourly()!;\n\n // Create weather data object\n const weatherData = {\n location: {\n latitude: response.latitude(),\n longitude: response.longitude(),\n timezone: response.timezone(),\n timezoneAbbreviation,\n utcOffsetSeconds,\n },\n current: {\n time: new Date(\n (Number(current.time()) + utcOffsetSeconds) * 1000,\n ).toISOString(),\n temperature2m: current.variables(0)!.value(),\n isDay: current.variables(1)!.value(),\n showers: current.variables(2)!.value(),\n cloudCover: current.variables(3)!.value(),\n windSpeed10m: current.variables(4)!.value(),\n relativeHumidity2m: current.variables(5)!.value(),\n precipitation: current.variables(6)!.value(),\n snowfall: current.variables(7)!.value(),\n rain: current.variables(8)!.value(),\n apparentTemperature: current.variables(9)!.value(),\n },\n hourly: {\n time: range(\n Number(hourly.time()),\n Number(hourly.timeEnd()),\n hourly.interval(),\n ).map((t) => new Date((t + utcOffsetSeconds) * 1000).toISOString()),\n temperature2m: Array.from(hourly.variables(0)!.valuesArray()!),\n precipitationProbability: Array.from(\n hourly.variables(1)!.valuesArray()!,\n ),\n precipitation: Array.from(hourly.variables(2)!.valuesArray()!),\n },\n };\n\n return weatherData;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`Weather API error: ${error.message}`);\n }\n throw new Error(\"Unknown error occurred while fetching weather data\");\n }\n },\n};\n","import { random } from \"./random.js\";\nimport { roll } from \"./roll.js\";\nimport { time } from \"./time.js\";\nimport { weather } from \"./weather.js\";\n\nexport const toolkit = {\n random,\n roll,\n time,\n weather,\n};\n\nexport const tools = Object.values(toolkit);\n"],"names":["defaultLog","placeholders","replacePlaceholders","ConfigurationError","random","randomUtil"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KAAK,EAAE;AACnD,iBAAA;AACD,gBAAA,MAAM,EAAE;oBACN,IAAI,EAAE,KAAK,CACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EACrB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EACxB,MAAM,CAAC,QAAQ,EAAE,CAClB,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,IAAI,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AACnE,oBAAA,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAE,CAAC,WAAW,EAAG,CAAC;AAC9D,oBAAA,wBAAwB,EAAE,KAAK,CAAC,IAAI,CAClC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAE,CAAC,WAAW,EAAG,CACpC;AACD,oBAAA,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAE,CAAC,WAAW,EAAG,CAAC;AAC/D,iBAAA;aACF;AAED,YAAA,OAAO,WAAW;;QAClB,OAAO,KAAK,EAAE;AACd,YAAA,IAAI,KAAK,YAAY,KAAK,EAAE;gBAC1B,MAAM,IAAI,KAAK,CAAC,CAAA,mBAAA,EAAsB,KAAK,CAAC,OAAO,CAAE,CAAA,CAAC;;AAExD,YAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC;;KAExE;CACF;;ACrIY,MAAA,OAAO,GAAG;IACrB,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,OAAO;;AAGI,MAAA,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO;;;;"}
|
|
@@ -2,6 +2,9 @@ import { JsonObject } from "@jaypie/types";
|
|
|
2
2
|
import { LlmProvider } from "../types/LlmProvider.interface.js";
|
|
3
3
|
export declare class AnthropicProvider implements LlmProvider {
|
|
4
4
|
private model;
|
|
5
|
-
|
|
5
|
+
private apiKey?;
|
|
6
|
+
constructor(model?: string, { apiKey }?: {
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
});
|
|
6
9
|
send(message: string): Promise<string | JsonObject>;
|
|
7
10
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonObject } from "@jaypie/types";
|
|
2
|
-
import {
|
|
2
|
+
import { LlmMessageOptions, LlmOperateOptions, LlmProvider } from "../../types/LlmProvider.interface.js";
|
|
3
3
|
export declare class OpenAiProvider implements LlmProvider {
|
|
4
4
|
private model;
|
|
5
5
|
private _client?;
|
|
@@ -10,4 +10,5 @@ export declare class OpenAiProvider implements LlmProvider {
|
|
|
10
10
|
});
|
|
11
11
|
private getClient;
|
|
12
12
|
send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
|
|
13
|
+
operate(input: string, options?: LlmOperateOptions): Promise<unknown>;
|
|
13
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { OpenAiProvider } from "./OpenAiProvider.class.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OpenAI } from "openai";
|
|
2
|
+
import { LlmOperateOptions } from "../../types/LlmProvider.interface.js";
|
|
3
|
+
import { OpenAIResponse } from "./types.js";
|
|
4
|
+
export declare const MAX_RETRIES_ABSOLUTE_LIMIT = 72;
|
|
5
|
+
export declare const MAX_RETRIES_DEFAULT_LIMIT = 6;
|
|
6
|
+
export declare const MAX_TURNS_ABSOLUTE_LIMIT = 72;
|
|
7
|
+
export declare const MAX_TURNS_DEFAULT_LIMIT = 12;
|
|
8
|
+
export declare function maxTurnsFromOptions(options: LlmOperateOptions): number;
|
|
9
|
+
export declare function operate(input: string | any[], options?: LlmOperateOptions, context?: {
|
|
10
|
+
client: OpenAI;
|
|
11
|
+
maxRetries?: number;
|
|
12
|
+
}): Promise<OpenAIResponse>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for OpenAI API responses
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Represents a function call in the OpenAI response
|
|
6
|
+
*/
|
|
7
|
+
export interface OpenAIFunctionCall {
|
|
8
|
+
type: "function_call";
|
|
9
|
+
name: string;
|
|
10
|
+
arguments: string;
|
|
11
|
+
call_id: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a text message in the OpenAI response
|
|
15
|
+
*/
|
|
16
|
+
export interface OpenAIContentItem {
|
|
17
|
+
type: "text";
|
|
18
|
+
text: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents a message in the OpenAI response
|
|
22
|
+
*/
|
|
23
|
+
export interface OpenAIMessage {
|
|
24
|
+
role: "assistant";
|
|
25
|
+
content: OpenAIContentItem[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents a function call output in the OpenAI response
|
|
29
|
+
*/
|
|
30
|
+
export interface OpenAIFunctionCallOutput {
|
|
31
|
+
type: "function_call_output";
|
|
32
|
+
call_id: string;
|
|
33
|
+
output: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Union type for all possible response items
|
|
37
|
+
*/
|
|
38
|
+
export type OpenAIResponseItem = OpenAIFunctionCall | OpenAIMessage | OpenAIFunctionCallOutput;
|
|
39
|
+
/**
|
|
40
|
+
* Raw response from the OpenAI API
|
|
41
|
+
*/
|
|
42
|
+
export interface OpenAIRawResponse {
|
|
43
|
+
id?: string;
|
|
44
|
+
object?: string;
|
|
45
|
+
created_at?: number;
|
|
46
|
+
model?: string;
|
|
47
|
+
output?: Array<OpenAIResponseItem | any>;
|
|
48
|
+
output_text?: string;
|
|
49
|
+
error?: any | null;
|
|
50
|
+
status?: string | any;
|
|
51
|
+
_request_id?: string | null;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Represents a single turn in a multi-turn conversation
|
|
56
|
+
*/
|
|
57
|
+
export interface OpenAIResponseTurn {
|
|
58
|
+
id?: string;
|
|
59
|
+
object?: string;
|
|
60
|
+
created_at?: number;
|
|
61
|
+
model?: string;
|
|
62
|
+
output?: Array<OpenAIResponseItem | any>;
|
|
63
|
+
output_text?: string;
|
|
64
|
+
error?: any | null;
|
|
65
|
+
status?: string;
|
|
66
|
+
_request_id?: string | null;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Represents the complete response from the OpenAI API,
|
|
71
|
+
* which is an array of turns
|
|
72
|
+
*/
|
|
73
|
+
export type OpenAIResponse = Array<OpenAIResponseTurn>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { log as defaultLog } from "@jaypie/core";
|
|
2
|
+
import { JsonObject, NaturalSchema } from "@jaypie/types";
|
|
3
|
+
import { OpenAI } from "openai";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
|
|
6
|
+
export declare const getLogger: () => {
|
|
7
|
+
debug: {
|
|
8
|
+
(...args: unknown[]): void;
|
|
9
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
10
|
+
};
|
|
11
|
+
error: {
|
|
12
|
+
(...args: unknown[]): void;
|
|
13
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
14
|
+
};
|
|
15
|
+
fatal: {
|
|
16
|
+
(...args: unknown[]): void;
|
|
17
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
18
|
+
};
|
|
19
|
+
info: {
|
|
20
|
+
(...args: unknown[]): void;
|
|
21
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
22
|
+
};
|
|
23
|
+
trace: {
|
|
24
|
+
(...args: unknown[]): void;
|
|
25
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
26
|
+
};
|
|
27
|
+
warn: {
|
|
28
|
+
(...args: unknown[]): void;
|
|
29
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
30
|
+
};
|
|
31
|
+
var(key: string | Record<string, unknown>, value?: unknown): void;
|
|
32
|
+
with(tags: Record<string, unknown>): typeof defaultLog;
|
|
33
|
+
tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
|
|
34
|
+
untag(tags: string | string[] | Record<string, unknown> | null): void;
|
|
35
|
+
lib(options: {
|
|
36
|
+
level?: string;
|
|
37
|
+
lib?: string;
|
|
38
|
+
tags?: Record<string, unknown>;
|
|
39
|
+
}): typeof defaultLog;
|
|
40
|
+
};
|
|
41
|
+
export declare function initializeClient({ apiKey, }?: {
|
|
42
|
+
apiKey?: string;
|
|
43
|
+
}): Promise<OpenAI>;
|
|
44
|
+
export interface ChatMessage {
|
|
45
|
+
role: "user" | "developer";
|
|
46
|
+
content: string;
|
|
47
|
+
}
|
|
48
|
+
export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
|
|
49
|
+
export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
|
|
50
|
+
export declare function prepareMessages(message: string, { system, data, placeholders }?: LlmMessageOptions): ChatMessage[];
|
|
51
|
+
export declare function createStructuredCompletion(client: OpenAI, { messages, responseSchema, model, }: {
|
|
52
|
+
messages: ChatMessage[];
|
|
53
|
+
responseSchema: z.ZodType | NaturalSchema;
|
|
54
|
+
model: string;
|
|
55
|
+
}): Promise<JsonObject>;
|
|
56
|
+
export declare function createTextCompletion(client: OpenAI, { messages, model, }: {
|
|
57
|
+
messages: ChatMessage[];
|
|
58
|
+
model: string;
|
|
59
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LlmTool } from "../types/LlmTool.interface";
|
|
2
|
+
export interface ToolkitOptions {
|
|
3
|
+
explain?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class Toolkit {
|
|
6
|
+
private readonly _tools;
|
|
7
|
+
private readonly _options;
|
|
8
|
+
private readonly explain;
|
|
9
|
+
constructor(tools: LlmTool[], options?: ToolkitOptions);
|
|
10
|
+
get tools(): Omit<LlmTool, "call">[];
|
|
11
|
+
call({ name, arguments: args }: {
|
|
12
|
+
name: string;
|
|
13
|
+
arguments: string;
|
|
14
|
+
}): Promise<any>;
|
|
15
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsonObject, NaturalSchema } from "@jaypie/types";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { LlmTool } from "./LlmTool.interface.js";
|
|
3
4
|
export interface LlmMessageOptions {
|
|
4
5
|
data?: Record<string, string>;
|
|
5
6
|
model?: string;
|
|
@@ -10,6 +11,26 @@ export interface LlmMessageOptions {
|
|
|
10
11
|
response?: NaturalSchema | z.ZodType;
|
|
11
12
|
system?: string;
|
|
12
13
|
}
|
|
14
|
+
export interface LlmOperateOptions {
|
|
15
|
+
data?: Record<string, string>;
|
|
16
|
+
explain?: boolean;
|
|
17
|
+
format?: JsonObject | NaturalSchema | z.ZodType;
|
|
18
|
+
instructions?: string;
|
|
19
|
+
model?: string;
|
|
20
|
+
placeholders?: {
|
|
21
|
+
input?: boolean;
|
|
22
|
+
instructions?: boolean;
|
|
23
|
+
};
|
|
24
|
+
providerOptions?: Record<string, unknown>;
|
|
25
|
+
tools?: LlmTool[];
|
|
26
|
+
turns?: boolean | number;
|
|
27
|
+
user?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface LlmOptions {
|
|
30
|
+
apiKey?: string;
|
|
31
|
+
model?: string;
|
|
32
|
+
}
|
|
13
33
|
export interface LlmProvider {
|
|
34
|
+
operate?(input: string, options?: LlmOperateOptions): Promise<unknown>;
|
|
14
35
|
send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
|
|
15
36
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
interface RandomOptions {
|
|
2
|
+
min?: number;
|
|
3
|
+
max?: number;
|
|
4
|
+
mean?: number;
|
|
5
|
+
stddev?: number;
|
|
6
|
+
integer?: boolean;
|
|
7
|
+
start?: number;
|
|
8
|
+
seed?: string;
|
|
9
|
+
precision?: number;
|
|
10
|
+
currency?: boolean;
|
|
11
|
+
}
|
|
12
|
+
type RandomFunction = {
|
|
13
|
+
(options?: RandomOptions): number;
|
|
14
|
+
};
|
|
15
|
+
export declare const DEFAULT_MIN = 0;
|
|
16
|
+
export declare const DEFAULT_MAX = 1;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a random number generator with optional seeding
|
|
19
|
+
*
|
|
20
|
+
* @param defaultSeed - Seed string for the default RNG
|
|
21
|
+
* @returns A function that generates random numbers based on provided options
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const rng = random("default-seed");
|
|
25
|
+
*
|
|
26
|
+
* // Generate a random float between 0 and 1
|
|
27
|
+
* const basic = rng();
|
|
28
|
+
*
|
|
29
|
+
* // Generate an integer between 1 and 10
|
|
30
|
+
* const integer = rng({ min: 1, max: 10, integer: true });
|
|
31
|
+
*
|
|
32
|
+
* // Generate from normal distribution
|
|
33
|
+
* const normal = rng({ mean: 50, stddev: 10 });
|
|
34
|
+
*
|
|
35
|
+
* // Use consistent seeding
|
|
36
|
+
* const seeded = rng({ seed: "my-seed" });
|
|
37
|
+
*/
|
|
38
|
+
declare const random: (defaultSeed?: string) => RandomFunction;
|
|
39
|
+
export default random;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaypie/llm",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Large language model utilities",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Finlayson Studio",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "rollup --config",
|
|
20
|
+
"build:manual": "rollup --config",
|
|
21
21
|
"format": "eslint . --fix",
|
|
22
22
|
"lint": "eslint .",
|
|
23
23
|
"test": "vitest run .",
|
|
@@ -26,14 +26,16 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@jaypie/aws": "^1.1.15",
|
|
28
28
|
"@jaypie/core": "^1.1.2",
|
|
29
|
-
"openai": "^4.
|
|
29
|
+
"openai": "^4.87.3",
|
|
30
|
+
"openmeteo": "^1.2.0",
|
|
31
|
+
"random": "^5.3.0",
|
|
30
32
|
"zod": "^3.24.1"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
|
-
"@jaypie/types": "^0.1.
|
|
35
|
+
"@jaypie/types": "^0.1.3"
|
|
34
36
|
},
|
|
35
37
|
"publishConfig": {
|
|
36
38
|
"access": "public"
|
|
37
39
|
},
|
|
38
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "1026f2fc0b3f6ae0ca2e1b6495437364f1c4e6fe"
|
|
39
41
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|