@@ -5,19 +5,6 @@ import { Anthropic } from '@anthropic-ai/sdk'
55
66// Mock dependencies
77jest . mock ( 'openai' )
8- jest . mock ( '../../../shared/api' , ( ) => ( {
9- ...jest . requireActual ( '../../../shared/api' ) ,
10- deepSeekModels : {
11- 'deepseek-chat' : {
12- maxTokens : 1000 ,
13- contextWindow : 2000 ,
14- supportsImages : false ,
15- supportsPromptCache : false ,
16- inputPrice : 0.014 ,
17- outputPrice : 0.28 ,
18- }
19- }
20- } ) )
218
229describe ( 'DeepSeekHandler' , ( ) => {
2310
@@ -46,8 +33,8 @@ describe('DeepSeekHandler', () => {
4633 expect ( result ) . toEqual ( {
4734 id : mockOptions . deepSeekModelId ,
4835 info : expect . objectContaining ( {
49- maxTokens : 1000 ,
50- contextWindow : 2000 ,
36+ maxTokens : 8192 ,
37+ contextWindow : 64000 ,
5138 supportsPromptCache : false ,
5239 supportsImages : false ,
5340 inputPrice : 0.014 ,
@@ -61,7 +48,7 @@ describe('DeepSeekHandler', () => {
6148 const result = handler . getModel ( )
6249
6350 expect ( result . id ) . toBe ( 'deepseek-chat' )
64- expect ( result . info . maxTokens ) . toBe ( 1000 )
51+ expect ( result . info . maxTokens ) . toBe ( 8192 )
6552 } )
6653
6754 test ( 'createMessage handles string content correctly' , async ( ) => {
@@ -109,7 +96,7 @@ describe('DeepSeekHandler', () => {
10996 ] ,
11097 temperature : 0 ,
11198 stream : true ,
112- max_tokens : 1000 ,
99+ max_tokens : 8192 ,
113100 stream_options : { include_usage : true }
114101 } ) )
115102 } )
@@ -155,83 +142,6 @@ describe('DeepSeekHandler', () => {
155142 } ) )
156143 } )
157144
158- test ( 'createMessage truncates messages when exceeding context window' , async ( ) => {
159- const handler = new DeepSeekHandler ( mockOptions )
160- const longString = 'a' . repeat ( 1000 ) // ~300 tokens
161- const shortString = 'b' . repeat ( 100 ) // ~30 tokens
162-
163- const systemPrompt = 'test system prompt'
164- const messages : Anthropic . Messages . MessageParam [ ] = [
165- { role : 'user' , content : longString } , // Old message
166- { role : 'assistant' , content : 'short response' } ,
167- { role : 'user' , content : shortString } // Recent message
168- ]
169-
170- const mockStream = {
171- async * [ Symbol . asyncIterator ] ( ) {
172- yield {
173- choices : [ {
174- delta : {
175- content : '(Note: Some earlier messages were truncated to fit within the model\'s context window)\n\n'
176- }
177- } ]
178- }
179- yield {
180- choices : [ {
181- delta : {
182- content : 'test response'
183- }
184- } ]
185- }
186- }
187- }
188-
189- const mockCreate = jest . fn ( ) . mockResolvedValue ( mockStream )
190- ; ( OpenAI as jest . MockedClass < typeof OpenAI > ) . prototype . chat = {
191- completions : { create : mockCreate }
192- } as any
193-
194- const generator = handler . createMessage ( systemPrompt , messages )
195- const chunks = [ ]
196- for await ( const chunk of generator ) {
197- chunks . push ( chunk )
198- }
199-
200- // Should get two chunks: truncation notice and response
201- expect ( chunks ) . toHaveLength ( 2 )
202- expect ( chunks [ 0 ] ) . toEqual ( {
203- type : 'text' ,
204- text : expect . stringContaining ( 'truncated' )
205- } )
206- expect ( chunks [ 1 ] ) . toEqual ( {
207- type : 'text' ,
208- text : 'test response'
209- } )
210-
211- // Verify API call includes system prompt and recent messages, but not old message
212- expect ( mockCreate ) . toHaveBeenCalledWith ( expect . objectContaining ( {
213- messages : expect . arrayContaining ( [
214- { role : 'system' , content : systemPrompt } ,
215- { role : 'assistant' , content : 'short response' } ,
216- { role : 'user' , content : shortString }
217- ] )
218- } ) )
219-
220- // Verify truncation notice was included
221- expect ( chunks [ 0 ] ) . toEqual ( {
222- type : 'text' ,
223- text : expect . stringContaining ( 'truncated' )
224- } )
225-
226- // Verify the messages array contains the expected messages
227- const calledMessages = mockCreate . mock . calls [ 0 ] [ 0 ] . messages
228- expect ( calledMessages ) . toHaveLength ( 4 )
229- expect ( calledMessages [ 0 ] ) . toEqual ( { role : 'system' , content : systemPrompt } )
230- expect ( calledMessages [ 1 ] ) . toEqual ( { role : 'user' , content : longString } )
231- expect ( calledMessages [ 2 ] ) . toEqual ( { role : 'assistant' , content : 'short response' } )
232- expect ( calledMessages [ 3 ] ) . toEqual ( { role : 'user' , content : shortString } )
233- } )
234-
235145 test ( 'createMessage handles API errors' , async ( ) => {
236146 const handler = new DeepSeekHandler ( mockOptions )
237147 const mockStream = {
0 commit comments