Skip to content

Commit bb982cb

Browse files
committed
Import SamplingMessage type
1 parent 51d8238 commit bb982cb

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

src/renderer/components/common/SamplingCard.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import type { ChatCompletionResponseMessage } from '@/renderer/types/message'
1212
1313
import { IpcSamplingRequestCallback, SamplingRequestParams, SamplingResponse } from '@/types/ipc'
1414
15-
16-
1715
const snackbarStore = useSnackbarStore()
1816
1917
const allChatbotStore = useChatbotStore()

src/renderer/composables/chatCompletions.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { jwtDecode } from 'jwt-decode'
77
import { getApiToken } from '@/renderer/utils'
88
import type { ChatbotConfig } from '@/types/llm'
99

10-
import { SamplingRequestParams } from '@/types/ipc'
10+
import { SamplingRequestParams, SamplingMessage } from '@/types/ipc'
1111

1212
import 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) {

src/renderer/types/message.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { z, ZodTypeAny } from 'zod'
22

33
import {
44
TextContentSchema as TextContentPartSchema,
5-
PromptMessage,
5+
PromptMessage
66
} from '@modelcontextprotocol/sdk/types'
77

88
type Primitive = string | number | boolean | bigint | null | undefined

src/types/ipc.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import type {
1010

1111
import { McpProgressCallbackObject } from '@/main/mcp/types'
1212

13+
import { SamplingMessage } from '@modelcontextprotocol/sdk/types'
14+
1315
export type {
1416
SamplingRequest,
1517
SamplingResponse,
18+
SamplingMessage,
1619
ElicitRequest,
1720
ElicitResponse,
1821
CommandResponse,

0 commit comments

Comments
 (0)