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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
tags:
- "*"
pull_request:
branches: [main]
branches: [main, "v0.16.x"]

jobs:
build:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.16.22

- Finish Vercel AI SDK streams when a complete `[DONE]` event arrives, preserving tool calls and usage without waiting for the HTTP connection to close.
- Handle split SSE records and a leading UTF-8 BOM; cancel the response body without delaying completion when cancellation stalls or fails.

## 0.16.21

- Add Meta's `meta-responses-v1` to the `reasoning_details` format union. It was missing, and since `ReasoningDetailArraySchema` drops entries it cannot parse, Meta reasoning details (e.g. from Muse Spark 1.2) were silently discarded instead of erroring — losing reasoning continuity across turns.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "langtail",
"version": "0.16.21",
"version": "0.16.22",
"description": "",
"main": "./Langtail.js",
"packageManager": "pnpm@8.15.6",
Expand Down Expand Up @@ -41,7 +41,7 @@
"copyfiles": "^2.4.1",
"fs-extra": "^11.2.0",
"jsdom": "^24.1.0",
"nock": "14.0.0-beta.5",
"nock": "14.0.17",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"typescript": "^5.7.3",
Expand Down
50 changes: 45 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/LangtailPrompts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ describe.skipIf(!liveTesting)(
const completion = await lt.invoke({
prompt,
environment: "staging",
// Override the deployed fixture's retired model for live inference.
model: "gpt-6-luna",
temperature: 1,
reasoning_effort: "low",
max_tokens: 512,
variables: {
about: "cowboy Bebop",
},
Expand All @@ -91,6 +96,11 @@ describe.skipIf(!liveTesting)(
const completion = await lt.invoke({
prompt: "short-story-teller",
environment: "staging",
// Override the deployed fixture's retired model for live inference.
model: "gpt-6-luna",
temperature: 1,
reasoning_effort: "low",
max_tokens: 512,
variables: {
about: "Aragorn",
},
Expand All @@ -107,6 +117,11 @@ describe.skipIf(!liveTesting)(
const proxyCompletion = await lt.invoke({
prompt,
environment: "staging",
// Override the deployed fixture's retired model for live inference.
model: "gpt-6-luna",
temperature: 1,
reasoning_effort: "low",
max_tokens: 512,
variables: {
about: "napoleon",
},
Expand Down
56 changes: 30 additions & 26 deletions src/openai.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,45 @@ import nock from "nock"
import { ChatCompletionChunkSchema } from "./dataSchema"
import OpenAI from "openai"


const lt = createOpenAIProxy(new OpenAI({ apiKey: process.env.LANGTAIL_API_KEY }))
const lt = createOpenAIProxy(
new OpenAI({ apiKey: process.env.LANGTAIL_API_KEY || "local-test" }),
)

describe("Langtail Proxy", () => {
it("should support streaming", async () => {
const proxyCompletion = await lt.chat.completions.create({
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the weather like?" },
],
stream: true,
model: "gpt-3.5-turbo",
doNotRecord: false,
metadata: {
"custom-field": "1",
},
})
let partCount = 0
for await (const part of proxyCompletion) {
partCount++
it.skipIf(process.env.TEST_LIVE !== "true")(
"should support streaming",
async () => {
const proxyCompletion = await lt.chat.completions.create({
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the weather like?" },
],
stream: true,
model: "gpt-6-luna",
reasoning_effort: "low",
max_tokens: 512,
doNotRecord: false,
metadata: {
"custom-field": "1",
},
})
let partCount = 0
for await (const part of proxyCompletion) {
partCount++

ChatCompletionChunkSchema.parse(part)
}
ChatCompletionChunkSchema.parse(part)
}

expect(partCount > 1).toBe(true)
})
expect(partCount > 1).toBe(true)
},
)

it("should not record", async (t) => {
nock(baseURL) // nock works by intercepting requests at the network level, if open AI switches to undici we will need to intercept differently
.post("/chat/completions")
.reply(200, function (uri, req) {
expect(this.req.headers["x-langtail-do-not-record"][0]).toBe("true")
expect(this.req.headers["x-langtail-metadata-custom-field"][0]).toBe(
"1",
)
expect(this.req.headers["x-langtail-do-not-record"]).toBe("true")
expect(this.req.headers["x-langtail-metadata-custom-field"]).toBe("1")

// check that body has no metadata or doNotRecord
expect(req).toMatchInlineSnapshot(`
Expand Down
Loading
Loading