@@ -7,7 +7,7 @@ import { jwtDecode } from 'jwt-decode'
77import { getApiToken } from '@/renderer/utils'
88import type { ChatbotConfig } from '@/types/llm'
99
10- import { SamplingRequestParams } from '@/types/ipc'
10+ import { SamplingRequestParams , SamplingMessage } from '@/types/ipc'
1111
1212import type {
1313 AssistantMessage ,
@@ -188,28 +188,27 @@ export const createCompletion = async (
188188 const target = targetConversation
189189
190190 if ( ! sampling ) {
191-
192- const conversation = target . reduce ( ( newConversation : ChatCompletionRequestMessage [ ] , item ) => {
193- if ( item . role === 'assistant' ) {
194- const { reasoning_content, ...rest } = item
195- void reasoning_content
196- newConversation . push ( rest )
197- }
198- // (item.role === "user" && item.content[0].type === "image_url") {
199- // // Image is too large, only latest query could be kept
200- // newConversation = [item];
201- // }
202- else {
203- newConversation . push ( item )
204- }
205- return newConversation
206- } , [ ] )
207-
208- body . messages = promptMessage (
209- conversation ,
210- agentStore . getPrompt ( )
191+ const conversation = target . reduce (
192+ ( newConversation : ChatCompletionRequestMessage [ ] , item ) => {
193+ if ( item . role === 'assistant' ) {
194+ const { reasoning_content, ...rest } = item
195+ void reasoning_content
196+ newConversation . push ( rest )
197+ }
198+ // (item.role === "user" && item.content[0].type === "image_url") {
199+ // // Image is too large, only latest query could be kept
200+ // newConversation = [item];
201+ // }
202+ else {
203+ newConversation . push ( item )
204+ }
205+ return newConversation
206+ } ,
207+ [ ]
211208 )
212209
210+ body . messages = promptMessage ( conversation , agentStore . getPrompt ( ) )
211+
213212 if ( chatbotConfig . maxTokensValue ) {
214213 body [ chatbotConfig . maxTokensPrefix ] = parseInt ( chatbotConfig . maxTokensValue )
215214 }
@@ -229,11 +228,12 @@ export const createCompletion = async (
229228 }
230229 }
231230 } else {
232-
233- const msg = ( sampling . messages ) . map ( ( item ) => ( {
234- role : item . role ,
235- content : [ mcpStore . convertItem ( item . content ) ]
236- } ) )
231+ const msg : ChatCompletionRequestMessage [ ] = sampling . messages . map (
232+ ( item : SamplingMessage ) => ( {
233+ role : item . role ,
234+ content : [ mcpStore . convertItem ( item . content ) ]
235+ } )
236+ )
237237 body . messages = promptMessage ( msg , sampling . systemPrompt )
238238 body . temperature = sampling . temperature
239239 if ( sampling . maxTokens ) {
0 commit comments