@@ -2,6 +2,7 @@ import { toRaw } from 'vue'
22import useMcpServer from './useMcp'
33import type { LLMMessage , RobotMessage } from './types'
44import type { LLMRequestBody , LLMResponse , ReponseToolCall , RequestOptions , RequestTool } from './types'
5+ import { META_SERVICE , getMetaApi } from '@opentiny/tiny-engine-meta-register'
56
67let requestOptions : RequestOptions = { }
78
@@ -14,13 +15,11 @@ const fetchLLM = async (messages: LLMMessage[], tools: RequestTool[], options: R
1415 if ( tools . length > 0 ) {
1516 bodyObj . tools = toRaw ( tools )
1617 }
17- return fetch ( options ?. url || '/app-center/api/chat/completions' , {
18- method : 'POST' ,
18+ return getMetaApi ( META_SERVICE . Http ) . post ( options ?. url || '/app-center/api/chat/completions' , bodyObj , {
1919 headers : {
2020 'Content-Type' : 'application/json' ,
2121 ...options ?. headers
22- } ,
23- body : JSON . stringify ( bodyObj )
22+ }
2423 } )
2524}
2625
@@ -82,7 +81,7 @@ const handleToolCall = async (
8281 result : toolCallResult . content
8382 }
8483 }
85- const newResp = await fetchLLM ( toolMessages , tools ) . then ( ( res ) => res . json ( ) )
84+ const newResp = await fetchLLM ( toolMessages , tools )
8685 const hasToolCall = newResp . choices [ 0 ] . message . tool_calls ?. length > 0
8786 if ( hasToolCall ) {
8887 await handleToolCall ( newResp , tools , messages , toolMessages )
@@ -103,7 +102,7 @@ export const sendMcpRequest = async (messages: LLMMessage[], options: RequestOpt
103102 }
104103 const tools = await useMcpServer ( ) . getLLMTools ( )
105104 requestOptions = options
106- const res = await fetchLLM ( messages . slice ( 0 , - 1 ) , tools , options ) . then ( ( res ) => res . json ( ) )
105+ const res = await fetchLLM ( messages . slice ( 0 , - 1 ) , tools , options )
107106 const hasToolCall = res . choices [ 0 ] . message . tool_calls ?. length > 0
108107 if ( hasToolCall ) {
109108 await handleToolCall ( res , tools , messages )
0 commit comments