Skip to content

Commit 256ba90

Browse files
committed
fix test and tsc error
1 parent 8dde655 commit 256ba90

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

packages/fluent-ai/examples/ollama-chat.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,30 @@ const models = await ollama().models().run();
55
console.log(models);
66

77
const response = await ollama()
8-
.chat(models[0].name)
8+
.chat(models[0].id)
99
.messages([
1010
{
1111
role: "user",
12-
content: "What is the capital of France?",
12+
text: "What is the capital of France?",
1313
},
1414
])
1515
.run();
1616

1717
console.log(response);
18+
19+
const streamResponse = await ollama()
20+
.chat(models[0].id)
21+
.messages([
22+
{
23+
role: "user",
24+
text: "What is the capital of Spain?",
25+
},
26+
])
27+
.stream()
28+
.run();
29+
30+
for await (const chunk of streamResponse) {
31+
if (chunk.message?.text) {
32+
process.stdout.write(chunk.message.text);
33+
}
34+
}

packages/fluent-ai/examples/openrouter-chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const job: Job = {
77
input: {
88
model: "google/gemini-2.5-flash",
99
messages: [
10-
{ role: "system", content: "You are a helpful assistant." },
11-
{ role: "user", content: "Hi" },
10+
{ role: "system", text: "You are a helpful assistant." },
11+
{ role: "user", text: "Hi" },
1212
],
1313
},
1414
};

packages/fluent-ai/src/agent/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ export class Agent<TContext = any> {
9090
? body.instructions()
9191
: body.instructions;
9292
const systemMessage = { role: "system", text: instructions };
93-
const messages = [systemMessage].concat(
93+
const messages = ([systemMessage] as Message[]).concat(
9494
initialMessages,
9595
newMessages,
96-
) as Message[];
96+
);
9797
const tools = body.tools.map((tool) => ({
9898
name: tool.name,
9999
description: tool.description,

packages/fluent-ai/src/job/openai.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ export const runner = {
3333

3434
return createHTTPJob(request, async (response: Response) => {
3535
if (input.stream) {
36-
return createStreamingGenerator(response);
36+
return createStreamingGenerator(response, (chunk: any) => {
37+
const choice = chunk.choices[0];
38+
const delta = choice.delta;
39+
return {
40+
text: delta.content,
41+
toolCalls: delta.tool_calls,
42+
usage: transformUsageData(chunk.usage),
43+
};
44+
});
3745
}
3846

3947
const data = await response.json();

packages/fluent-ai/src/job/openrouter.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ export const runner = {
3333

3434
return createHTTPJob(request, async (response: Response) => {
3535
if (input.stream) {
36-
return createStreamingGenerator(response);
36+
return createStreamingGenerator(response, (chunk: any) => {
37+
const choice = chunk.choices[0];
38+
const delta = choice.delta;
39+
return {
40+
text: delta.content,
41+
toolCalls: delta.tool_calls,
42+
usage: transformUsageData(chunk.usage),
43+
};
44+
});
3745
}
3846

3947
const data = await response.json();

packages/fluent-ai/src/job/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const chatToolSchema = z.object({
7070

7171
const chatInputSchema = z.object({
7272
model: z.string(),
73-
messages: z.array(z.any()), // TODO: fix any
73+
messages: z.array(messagesSchema),
7474
temperature: z.number().optional(),
7575
maxTokens: z.number().optional(),
7676
stream: z.boolean().optional(),

packages/fluent-ai/test/job.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
openai,
66
fal,
77
type Job,
8-
user,
98
voyage,
109
} from "~/src/index";
1110
import { Runner } from "~/src/job/runner";
@@ -16,7 +15,7 @@ test("chat job", () => {
1615
type: "chat",
1716
input: {
1817
model: "test-model",
19-
messages: [{ role: "user", content: "hello" }],
18+
messages: [{ role: "user", text: "hello" }],
2019
},
2120
};
2221

@@ -27,7 +26,7 @@ test("chat job", () => {
2726
expect(job).toEqual(
2827
openrouter()
2928
.chat("test-model")
30-
.messages([user("hello")])
29+
.messages([{ role: "user", text: "hello" }])
3130
.build(),
3231
);
3332
});
@@ -96,7 +95,7 @@ test("runner", () => {
9695
type: "chat",
9796
input: {
9897
model: "test-model",
99-
messages: [{ role: "user", content: "hello" }],
98+
messages: [{ role: "user", text: "hello" }],
10099
},
101100
};
102101

0 commit comments

Comments
 (0)