mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 05:39:05 +08:00
refactor(ApiService): 重构 fetchChatCompletion 参数类型定义
将参数类型提取为独立的类型定义,支持 messages 或 prompt 两种参数形式
This commit is contained in:
parent
d4a22d3b0c
commit
84f920e54e
@ -81,21 +81,36 @@ export type FetchChatCompletionOptions = {
|
|||||||
headers?: Record<string, string>
|
headers?: Record<string, string>
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchChatCompletion({
|
type BaseParams = {
|
||||||
messages,
|
|
||||||
assistant,
|
|
||||||
options,
|
|
||||||
onChunkReceived,
|
|
||||||
topicId
|
|
||||||
}: {
|
|
||||||
messages: StreamTextParams['messages']
|
|
||||||
assistant: Assistant
|
assistant: Assistant
|
||||||
options: FetchChatCompletionOptions
|
options: FetchChatCompletionOptions
|
||||||
onChunkReceived: (chunk: Chunk) => void
|
onChunkReceived: (chunk: Chunk) => void
|
||||||
topicId?: string // 添加 topicId 参数
|
topicId?: string // 添加 topicId 参数
|
||||||
}) {
|
}
|
||||||
|
|
||||||
|
type MessagesParams = BaseParams & {
|
||||||
|
messages: StreamTextParams['messages']
|
||||||
|
prompt?: never
|
||||||
|
}
|
||||||
|
|
||||||
|
type PromptParams = BaseParams & {
|
||||||
|
messages?: never
|
||||||
|
prompt: StreamTextParams['prompt']
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FetchChatCompletionParams = MessagesParams | PromptParams
|
||||||
|
|
||||||
|
export async function fetchChatCompletion({
|
||||||
|
messages,
|
||||||
|
prompt,
|
||||||
|
assistant,
|
||||||
|
options,
|
||||||
|
onChunkReceived,
|
||||||
|
topicId
|
||||||
|
}: FetchChatCompletionParams) {
|
||||||
logger.info('fetchChatCompletion called with detailed context', {
|
logger.info('fetchChatCompletion called with detailed context', {
|
||||||
messageCount: messages?.length || 0,
|
messageCount: messages?.length || 0,
|
||||||
|
prompt: prompt,
|
||||||
assistantId: assistant.id,
|
assistantId: assistant.id,
|
||||||
topicId,
|
topicId,
|
||||||
hasTopicId: !!topicId,
|
hasTopicId: !!topicId,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user