Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langtail",
"version": "0.13.4",
"version": "0.13.5",
"description": "",
"main": "./Langtail.js",
"packageManager": "pnpm@8.15.6",
Expand Down
8 changes: 6 additions & 2 deletions src/bin/langtailTools.ts.template
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// @ts-ignore
import { CoreTool } from 'ai'
import { z } from 'zod'

type Streamable = unknown;
type Renderer<T extends Array<any>> = (...args: T) => Streamable | Generator<Streamable, Streamable, void> | AsyncGenerator<Streamable, Streamable, void>;
interface VercelAITool<PARAMETERS extends z.ZodTypeAny = any, RESULT = any> extends CoreTool<PARAMETERS, RESULT> {
interface VercelAITool<PARAMETERS extends z.ZodTypeAny = any, RESULT = any> {
parameters: PARAMETERS;
description?: string;
execute?: (args: z.infer<PARAMETERS>, options: {
abortSignal?: AbortSignal;
}) => PromiseLike<RESULT>;
generate?: Renderer<[
z.infer<PARAMETERS>,
{
Expand Down
15 changes: 9 additions & 6 deletions src/getOpenAIBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down