File tree Expand file tree Collapse file tree 7 files changed +45
-13
lines changed
Expand file tree Collapse file tree 7 files changed +45
-13
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,30 @@ const models = await ollama().models().run();
55console . log ( models ) ;
66
77const 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
1717console . 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+ }
Original file line number Diff line number Diff 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} ;
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ const chatToolSchema = z.object({
7070
7171const 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 ( ) ,
Original file line number Diff line number Diff line change 55 openai ,
66 fal ,
77 type Job ,
8- user ,
98 voyage ,
109} from "~/src/index" ;
1110import { 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
You can’t perform that action at this time.
0 commit comments