fix: change fetch to http service (#1577)

* fix: change fetch to http service
This commit is contained in:
Hexqi 2025-08-12 15:54:05 +08:00 committed by GitHub
parent a3059a7515
commit 01eb9f68e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 9 deletions

View File

@ -46,7 +46,7 @@ const preResponse = (res) => {
return Promise.reject(res.data.error)
}
return res.data?.data
return res.data?.data || res.data
}
const openLogin = () => {

View File

@ -19,7 +19,7 @@ const DEFAULT_MODELS = [{ label: 'DeepSeekDeepSeek-V3', value: 'deepseek-chat
export const getAIModelOptions = () => {
const aiRobotOptions = getOptions(meta.id)?.customCompatibleAIModels || []
return [...DEFAULT_MODELS, ...aiRobotOptions]
return aiRobotOptions.length ? aiRobotOptions : DEFAULT_MODELS
}
// 这里存放的是aichat的响应式数据

View File

@ -26,7 +26,7 @@ const defaultMarkdownItOptions = {
}
const props = defineProps<{
type: 'markdown' | 'text'
type?: 'markdown' | 'text'
content: string
options?: MarkdownItOptions
}>()

View File

@ -2,6 +2,7 @@ import { toRaw } from 'vue'
import useMcpServer from './useMcp'
import type { LLMMessage, RobotMessage } from './types'
import type { LLMRequestBody, LLMResponse, ReponseToolCall, RequestOptions, RequestTool } from './types'
import { META_SERVICE, getMetaApi } from '@opentiny/tiny-engine-meta-register'
let requestOptions: RequestOptions = {}
@ -14,13 +15,11 @@ const fetchLLM = async (messages: LLMMessage[], tools: RequestTool[], options: R
if (tools.length > 0) {
bodyObj.tools = toRaw(tools)
}
return fetch(options?.url || '/app-center/api/chat/completions', {
method: 'POST',
return getMetaApi(META_SERVICE.Http).post(options?.url || '/app-center/api/chat/completions', bodyObj, {
headers: {
'Content-Type': 'application/json',
...options?.headers
},
body: JSON.stringify(bodyObj)
}
})
}
@ -82,7 +81,7 @@ const handleToolCall = async (
result: toolCallResult.content
}
}
const newResp = await fetchLLM(toolMessages, tools).then((res) => res.json())
const newResp = await fetchLLM(toolMessages, tools)
const hasToolCall = newResp.choices[0].message.tool_calls?.length > 0
if (hasToolCall) {
await handleToolCall(newResp, tools, messages, toolMessages)
@ -103,7 +102,7 @@ export const sendMcpRequest = async (messages: LLMMessage[], options: RequestOpt
}
const tools = await useMcpServer().getLLMTools()
requestOptions = options
const res = await fetchLLM(messages.slice(0, -1), tools, options).then((res) => res.json())
const res = await fetchLLM(messages.slice(0, -1), tools, options)
const hasToolCall = res.choices[0].message.tool_calls?.length > 0
if (hasToolCall) {
await handleToolCall(res, tools, messages)