@@ -73,6 +73,61 @@ describe("NativeOllamaHandler", () => {
7373 expect ( results [ 2 ] ) . toEqual ( { type : "usage" , inputTokens : 10 , outputTokens : 2 } )
7474 } )
7575
76+ it ( "should not include num_ctx by default" , async ( ) => {
77+ // Mock the chat response
78+ mockChat . mockImplementation ( async function * ( ) {
79+ yield { message : { content : "Response" } }
80+ } )
81+
82+ const stream = handler . createMessage ( "System" , [ { role : "user" as const , content : "Test" } ] )
83+
84+ // Consume the stream
85+ for await ( const _ of stream ) {
86+ // consume stream
87+ }
88+
89+ // Verify that num_ctx was NOT included in the options
90+ expect ( mockChat ) . toHaveBeenCalledWith (
91+ expect . objectContaining ( {
92+ options : expect . not . objectContaining ( {
93+ num_ctx : expect . anything ( ) ,
94+ } ) ,
95+ } ) ,
96+ )
97+ } )
98+
99+ it ( "should include num_ctx when explicitly set via ollamaNumCtx" , async ( ) => {
100+ const options : ApiHandlerOptions = {
101+ apiModelId : "llama2" ,
102+ ollamaModelId : "llama2" ,
103+ ollamaBaseUrl : "http://localhost:11434" ,
104+ ollamaNumCtx : 8192 , // Explicitly set num_ctx
105+ }
106+
107+ handler = new NativeOllamaHandler ( options )
108+
109+ // Mock the chat response
110+ mockChat . mockImplementation ( async function * ( ) {
111+ yield { message : { content : "Response" } }
112+ } )
113+
114+ const stream = handler . createMessage ( "System" , [ { role : "user" as const , content : "Test" } ] )
115+
116+ // Consume the stream
117+ for await ( const _ of stream ) {
118+ // consume stream
119+ }
120+
121+ // Verify that num_ctx was included with the specified value
122+ expect ( mockChat ) . toHaveBeenCalledWith (
123+ expect . objectContaining ( {
124+ options : expect . objectContaining ( {
125+ num_ctx : 8192 ,
126+ } ) ,
127+ } ) ,
128+ )
129+ } )
130+
76131 it ( "should handle DeepSeek R1 models with reasoning detection" , async ( ) => {
77132 const options : ApiHandlerOptions = {
78133 apiModelId : "deepseek-r1" ,
@@ -120,6 +175,49 @@ describe("NativeOllamaHandler", () => {
120175 } )
121176 expect ( result ) . toBe ( "This is the response" )
122177 } )
178+
179+ it ( "should not include num_ctx in completePrompt by default" , async ( ) => {
180+ mockChat . mockResolvedValue ( {
181+ message : { content : "Response" } ,
182+ } )
183+
184+ await handler . completePrompt ( "Test prompt" )
185+
186+ // Verify that num_ctx was NOT included in the options
187+ expect ( mockChat ) . toHaveBeenCalledWith (
188+ expect . objectContaining ( {
189+ options : expect . not . objectContaining ( {
190+ num_ctx : expect . anything ( ) ,
191+ } ) ,
192+ } ) ,
193+ )
194+ } )
195+
196+ it ( "should include num_ctx in completePrompt when explicitly set" , async ( ) => {
197+ const options : ApiHandlerOptions = {
198+ apiModelId : "llama2" ,
199+ ollamaModelId : "llama2" ,
200+ ollamaBaseUrl : "http://localhost:11434" ,
201+ ollamaNumCtx : 4096 , // Explicitly set num_ctx
202+ }
203+
204+ handler = new NativeOllamaHandler ( options )
205+
206+ mockChat . mockResolvedValue ( {
207+ message : { content : "Response" } ,
208+ } )
209+
210+ await handler . completePrompt ( "Test prompt" )
211+
212+ // Verify that num_ctx was included with the specified value
213+ expect ( mockChat ) . toHaveBeenCalledWith (
214+ expect . objectContaining ( {
215+ options : expect . objectContaining ( {
216+ num_ctx : 4096 ,
217+ } ) ,
218+ } ) ,
219+ )
220+ } )
123221 } )
124222
125223 describe ( "error handling" , ( ) => {
0 commit comments