@@ -5,9 +5,22 @@ import type { IDatasetRow } from "./types";
55describe ( "ChatTemplateFormatter" , ( ) => {
66 const formatter = new ChatTemplateFormatter ( ) ;
77
8- it ( "should transform tools to OpenAI format" , ( ) => {
9- const row : IDatasetRow = {
8+ const createMockRow = (
9+ overrides : Partial < IDatasetRow > = { }
10+ ) : IDatasetRow => ( {
11+ messages : [ ] ,
12+ tools : [ ] ,
13+ schema : {
14+ metadata : { } ,
1015 messages : [ ] ,
16+ tools : [ ] ,
17+ } ,
18+ meta : { } ,
19+ ...overrides ,
20+ } ) ;
21+
22+ it ( "should transform tools to OpenAI format" , ( ) => {
23+ const row = createMockRow ( {
1124 tools : [
1225 {
1326 name : "calculator" ,
@@ -20,9 +33,7 @@ describe("ChatTemplateFormatter", () => {
2033 output : { } ,
2134 } ,
2235 ] ,
23- schema : { } as any ,
24- meta : { } as any ,
25- } ;
36+ } ) ;
2637
2738 const result = formatter . format ( row ) ;
2839 expect ( result . tools ) . toHaveLength ( 1 ) ;
@@ -41,18 +52,15 @@ describe("ChatTemplateFormatter", () => {
4152 } ) ;
4253
4354 it ( "should transform user messages" , ( ) => {
44- const row : IDatasetRow = {
55+ const row = createMockRow ( {
4556 messages : [
4657 {
4758 role : "user" ,
4859 content : "Hello" ,
4960 generationId : "1" ,
5061 } ,
5162 ] ,
52- tools : [ ] ,
53- schema : { } as any ,
54- meta : { } as any ,
55- } ;
63+ } ) ;
5664
5765 const result = formatter . format ( row ) ;
5866 expect ( result . messages ) . toHaveLength ( 1 ) ;
@@ -63,7 +71,7 @@ describe("ChatTemplateFormatter", () => {
6371 } ) ;
6472
6573 it ( "should transform assistant messages with tool calls" , ( ) => {
66- const row : IDatasetRow = {
74+ const row = createMockRow ( {
6775 messages : [
6876 {
6977 role : "assistant" ,
@@ -77,12 +85,9 @@ describe("ChatTemplateFormatter", () => {
7785 } ,
7886 ] ,
7987 generationId : "1" ,
80- } as any , // Casting because IDatasetMessage content type is strict in tests
88+ } ,
8189 ] ,
82- tools : [ ] ,
83- schema : { } as any ,
84- meta : { } as any ,
85- } ;
90+ } ) ;
8691
8792 const result = formatter . format ( row ) ;
8893 expect ( result . messages ) . toHaveLength ( 1 ) ;
@@ -102,8 +107,31 @@ describe("ChatTemplateFormatter", () => {
102107 } ) ;
103108 } ) ;
104109
110+ it ( "should transform assistant messages with reasoning" , ( ) => {
111+ const row = createMockRow ( {
112+ messages : [
113+ {
114+ role : "assistant" ,
115+ content : [
116+ { type : "reasoning" , text : "I should check the weather." } ,
117+ { type : "text" , text : "Checking weather..." } ,
118+ ] ,
119+ generationId : "1" ,
120+ } ,
121+ ] ,
122+ } ) ;
123+
124+ const result = formatter . format ( row ) ;
125+ expect ( result . messages ) . toHaveLength ( 1 ) ;
126+ expect ( result . messages [ 0 ] ) . toEqual ( {
127+ role : "assistant" ,
128+ content : "Checking weather..." ,
129+ reasoning : "I should check the weather." ,
130+ } ) ;
131+ } ) ;
132+
105133 it ( "should flatten tool result messages" , ( ) => {
106- const row : IDatasetRow = {
134+ const row = createMockRow ( {
107135 messages : [
108136 {
109137 role : "tool" ,
@@ -112,24 +140,19 @@ describe("ChatTemplateFormatter", () => {
112140 type : "tool-result" ,
113141 toolCallId : "call_1" ,
114142 toolName : "calc" ,
115- result : 2 ,
116- output : 2 , // dataset.ts populates output
143+ output : { type : "text" , value : "2" } , // dataset.ts populates output
117144 } ,
118145 {
119146 type : "tool-result" ,
120147 toolCallId : "call_2" ,
121148 toolName : "calc" ,
122- result : 4 ,
123- output : 4 ,
149+ output : { type : "text" , value : "4" } ,
124150 } ,
125151 ] ,
126152 generationId : "1" ,
127- } as any ,
153+ } ,
128154 ] ,
129- tools : [ ] ,
130- schema : { } as any ,
131- meta : { } as any ,
132- } ;
155+ } ) ;
133156
134157 const result = formatter . format ( row ) ;
135158 expect ( result . messages ) . toHaveLength ( 2 ) ;
0 commit comments