From c0ddb03ab2078b584fcdc213b0fe6a2ae58dea70 Mon Sep 17 00:00:00 2001 From: Thyrst Date: Fri, 11 Oct 2024 18:27:54 +0200 Subject: [PATCH 1/2] option to append template --- src/getOpenAIBody.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/getOpenAIBody.ts b/src/getOpenAIBody.ts index 332e62b..50e1e48 100644 --- a/src/getOpenAIBody.ts +++ b/src/getOpenAIBody.ts @@ -33,20 +33,23 @@ export function getOpenAIBody( parsedBody: IncomingBodyType, threadParams?: { threadMessages?: PlaygroundMessage[] - } + }, + options?: { appendTemplate?: boolean }, ): ChatCompletionsCreateParams { const completionArgs = completionConfig.state.args const template = parsedBody.template ?? completionConfig.state.template - const inputMessages = [ - ...compileMessages(template, Object.assign( - completionConfig.chatInput, - parsedBody.variables ?? {}, - )), + const compiledTemplate = compileMessages(template, Object.assign( + completionConfig.chatInput, + parsedBody.variables ?? {}, + )) + const bodyMessages = [ ...[...(threadParams?.threadMessages ?? []) as ChatCompletionMessageParam[]], ...(parsedBody.messages ?? []) as ChatCompletionMessageParam[] ] + const inputMessages = options?.appendTemplate ? [...bodyMessages, ...compiledTemplate] : [...compiledTemplate, ...bodyMessages] + const openAIbody: OpenAI.Chat.ChatCompletionCreateParams = { model: parsedBody.model ?? completionArgs.model, temperature: parsedBody.temperature ?? completionArgs.temperature, From ff1c4f20758d0d67907563933f061f52d24a8805 Mon Sep 17 00:00:00 2001 From: Thyrst Date: Tue, 29 Oct 2024 14:19:44 +0100 Subject: [PATCH 2/2] Fix IntelliSense for tools when using Vercel AI SDK --- CHANGELOG.md | 10 ++++++++++ README.md | 9 ++++----- package.json | 2 +- src/bin/langtailTools.ts.template | 8 ++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afc08b9..071b695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +# 0.13.5 +- Option to append template to the end in `getOpenAIBody`. +- Fix IntelliSense for tools when using Vercel AI SDK. + +# 0.13.4 +- add parallelToolCalls option to pass it to the API + +# 0.13.3 +- Support for Langtail hosted tools + # 0.5.4 - Fix: don't send `stop` parameter if it's empty (this causes validation error in OpenAI in some cases) diff --git a/README.md b/README.md index a367f8c..9ec2d66 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,9 @@ const joke = await openai.chat.completions.create(openAiBody) This way you are still using langtail prompts without exposing potentially sensitive data in your variables. +## Typed inputs + +You can override input types to improve IntelliSense for the `prompt`, `environment`, `version` and `variables` when calling a prompt. Use the command `npx langtail generate-types`. ## Vercel AI provider @@ -249,7 +252,7 @@ const result = await generateText({ ### Using tools from Langtail -If your prompts in Langtail contain tools, you can generate a file containing tool parameters for every prompt deployment in your project. Run `npx langtail generate-tools --out [output_filepath]` to generate the file. +If your prompts in Langtail contain tools, you can generate a file containing tool parameters for every prompt deployment in your project. Run `npx langtail generate-tools --out [output_filepath]` to generate the file. For typings of the `tools` helper to work correctly, you also need to [generate types](#typed-inputs). After the file is generated, you can provide the Langtail tools to AI SDK like this: ```typescript @@ -284,10 +287,6 @@ tools(ltModel, { }) ``` -## Typed inputs - -You can override input types to improve IntelliSense for the `prompt`, `environment`, `version` and `variables` when calling a prompt. Use the command `npx langtail generate-types`. - ## Stream helpers The AI streams are delivered as JSON objects, which are split into chunks. This can pose a challenge because JSON objects might be distributed across multiple chunks. We have provide you with helper functions to manage these JSON streams more effectively. diff --git a/package.json b/package.json index afef989..ebde95c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "langtail", - "version": "0.13.4", + "version": "0.13.5", "description": "", "main": "./Langtail.js", "packageManager": "pnpm@8.15.6", diff --git a/src/bin/langtailTools.ts.template b/src/bin/langtailTools.ts.template index 402156d..47992b2 100644 --- a/src/bin/langtailTools.ts.template +++ b/src/bin/langtailTools.ts.template @@ -1,10 +1,14 @@ // @ts-ignore -import { CoreTool } from 'ai' import { z } from 'zod' type Streamable = unknown; type Renderer> = (...args: T) => Streamable | Generator | AsyncGenerator; -interface VercelAITool extends CoreTool { +interface VercelAITool { + parameters: PARAMETERS; + description?: string; + execute?: (args: z.infer, options: { + abortSignal?: AbortSignal; + }) => PromiseLike; generate?: Renderer<[ z.infer, {