Skip to content

Commit d49ccca

Browse files
authored
Merge pull request #77 from langtail/vercel_ai_update
update vercel ai code
2 parents ce7aaaa + fb3240b commit d49ccca

18 files changed

+600
-2363
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 0.14.0
4+
5+
- Update `openai` version
6+
- Fix tool calls issues for Vercel AI SDK integration
7+
- Remove `useChatStream` (moved to separate repo)
8+
39
## 0.13.9
410

511
- Fix for browser runtime

README.md

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const rawCompletion = await lt.chat.completions.create({
3636
prompt: "<prompt-slug>",
3737
doNotRecord: false, // false will ensure logs do not contain any info about payloads. You can still see the request in the logs, but you cannot see the variables etc.
3838
metadata: {
39-
"custom-field": 1,
39+
"custom-field": "1",
4040
},
4141
})
4242
```
@@ -319,75 +319,3 @@ runner.on("chunk", (chunk: ChatCompletionChunk) => {
319319
// NOTE: chunk here is always a proper JSON even with parts of the message
320320
})
321321
```
322-
323-
## useChatStream React hook
324-
325-
"You can leverage our React hook to handle AI streams more easily. We have developed a hook called `useChatStream`, which can be imported from `langtail/react/useChatStream`.
326-
327-
Here's an example:
328-
329-
```ts
330-
// NOTE: your FE code
331-
import { useChatStream } from "langtail/react/useChatStream";
332-
333-
function YourComponent() {
334-
const { isLoading, messages, send } = useChatStream({
335-
fetcher: (message) =>
336-
fetch(`/api/langtail`, {
337-
method: "POST",
338-
body: JSON.stringify({ messages: [message] }),
339-
headers: {
340-
"Content-Type": "application/json",
341-
},
342-
}).then((res) => res.body),
343-
onToolCall: async (toolCall: ChatCompletionMessageToolCall, fullMessage) => {
344-
if (toolCall.function.name === "weather") {
345-
return "Sunny 22 degrees"
346-
}
347-
348-
return "Unknown data"
349-
}
350-
});
351-
352-
useEffect(() => {
353-
// Call send wherever you like with any content
354-
send({ role: 'user' , content: "Can you hear me?"})
355-
}, [])
356-
357-
// NOTE: the `messages` array is updated within the react providing you with live stream of the messages
358-
return (
359-
<>
360-
{messages.map((message) => (
361-
<p>
362-
{message.role}: {message.content}
363-
</p>
364-
))}
365-
</>
366-
)
367-
}
368-
```
369-
370-
```ts
371-
// NOTE: your next.js BE code, assuming that this is the route /api/langtail
372-
import { Langtail } from "langtail"
373-
import { NextRequest } from "next/server"
374-
375-
export const runtime = "edge"
376-
377-
export const lt = new Langtail({
378-
apiKey: process.env.LANGTAIL_API_KEY ?? "",
379-
})
380-
381-
// Create a new assistant
382-
export async function POST(request: NextRequest) {
383-
const messages = (await request.json()).messages
384-
385-
const result = await lt.prompts.invoke({
386-
prompt: "weather",
387-
messages,
388-
stream: true,
389-
})
390-
391-
return new Response(result.toReadableStream())
392-
}
393-
```

package.json

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "langtail",
3-
"version": "0.13.9",
3+
"version": "0.14.0",
44
"description": "",
55
"main": "./Langtail.js",
66
"packageManager": "[email protected]",
@@ -35,17 +35,12 @@
3535
],
3636
"license": "MIT",
3737
"devDependencies": {
38-
"@testing-library/dom": "^10.0.0",
39-
"@testing-library/react": "^16.0.0",
4038
"@types/node": "^20.12.11",
41-
"@types/react": "^18.3.3",
4239
"copyfiles": "^2.4.1",
4340
"fs-extra": "^11.2.0",
4441
"jsdom": "^24.1.0",
4542
"nock": "14.0.0-beta.5",
4643
"prettier": "^3.2.5",
47-
"react": "18.2.0",
48-
"react-dom": "^18.0.0",
4944
"tsup": "^8.0.2",
5045
"typescript": "^5.4.5",
5146
"vitest": "^1.6.0"
@@ -83,11 +78,6 @@
8378
"import": "./stream/index.mjs",
8479
"types": "./stream/index.d.ts"
8580
},
86-
"./react/useChatStream": {
87-
"require": "./react/useChatStream.js",
88-
"import": "./react/useChatStream.mjs",
89-
"types": "./react/useChatStream.d.ts"
90-
},
9181
"./vercel-ai": {
9282
"require": "./vercel-ai/index.js",
9383
"import": "./vercel-ai/index.mjs",
@@ -99,18 +89,15 @@
9989
"types": "./customTypes.d.ts"
10090
}
10191
},
102-
"peerDependencies": {
103-
"react": ">=18.2.0"
104-
},
10592
"dependencies": {
106-
"@ai-sdk/provider": "^0.0.24",
107-
"@ai-sdk/provider-utils": "^1.0.20",
93+
"@ai-sdk/provider": "^1.0.1",
94+
"@ai-sdk/provider-utils": "^2.0.3",
10895
"@langtail/handlebars-evalless": "^0.1.2",
10996
"commander": "^12.1.0",
11097
"date-fns": "^3.6.0",
11198
"dotenv-flow": "^4.1.0",
11299
"json-schema-to-zod": "^2.1.0",
113-
"openai": "^4.43.0",
100+
"openai": "^4.76.0",
114101
"query-string": "^7.1.3",
115102
"zod": "^3.23.8"
116103
},
@@ -131,8 +118,7 @@
131118
"src/vercel-ai/index.ts",
132119
"src/bin/entry.ts",
133120
"src/schemas.ts",
134-
"src/stream/index.ts",
135-
"src/react/useChatStream.ts"
121+
"src/stream/index.ts"
136122
],
137123
"external": [
138124
"dotenv-flow",

0 commit comments

Comments
 (0)