kagg886 2 месяцев назад
Родитель
Сommit
a678435356
3 измененных файлов с 28 добавлено и 9 удалено
  1. 2 0
      src/api/assist/index.ts
  2. 10 3
      src/api/assist/type.ts
  3. 16 6
      src/views/assistant/index.vue

+ 2 - 0
src/api/assist/index.ts

@@ -156,6 +156,7 @@ export default {
 									const toolcallResponse: ChatResponse = {
 										type: 'toolcall',
 										request: {
+											id: tools["tool_call_id"],
 											name: tools["name"],
 											data: tools["arguments"]
 										}
@@ -169,6 +170,7 @@ export default {
 									const toolresResponse: ChatResponse = {
 										type: 'toolres',
 										response: {
+											id: tools["tool_call_id"],
 											name: tools["name"],
 											data: tools["response"]
 										},

+ 10 - 3
src/api/assist/type.ts

@@ -16,15 +16,20 @@
 
 // 消息类型定义
 export type Message = {
-	id: number
-	role: 'user' | 'assistant' | 'system' | 'meta'
+	id: string
+	role: 'user' | 'assistant' | 'system' | 'meta' | 'tool'
 	//仅markdown渲染器需要
 	render_content: string
 	//实际传给AI的内容
 	content: string
 	timestamp: number
 
-	tools_calls?: FunctionCall[]
+	//仅role为tool时需要
+	name?: string,
+	//仅role为tool时需要
+	tool_call_id?: string
+	//仅role为assistant时需要
+	tool_calls?: FunctionCall[]
 }
 
 export type FunctionCall = {
@@ -54,6 +59,7 @@ export type Text = ChatResponseBase<'message'> & {
 
 export type ToolCallRequest = ChatResponseBase<'toolcall'> & {
 	request: {
+		id: string
 		name: string,
 		data: string
 	}
@@ -61,6 +67,7 @@ export type ToolCallRequest = ChatResponseBase<'toolcall'> & {
 
 export type ToolCallResponse = ChatResponseBase<'toolres'> & {
 	response: {
+		id: string
 		name: string,
 		data: string
 	}

+ 16 - 6
src/views/assistant/index.vue

@@ -110,7 +110,7 @@ const sendMessage = () => {
 	if (!inputMessage.value.trim()) return
 
 	messages.value.push({
-		id: Date.now(),
+		id: `${Date.now()}`,
 		role: 'user',
 		render_content: inputMessage.value,
 		content: inputMessage.value,
@@ -118,12 +118,12 @@ const sendMessage = () => {
 	})
 
 	const rtn = reactive<Message>({
-		id: Date.now(),
+		id: `${Date.now()}`,
 		role: 'assistant',
 		render_content: '',
 		content: '',
 		timestamp: Date.now(),
-		tools_calls: [],
+		tool_calls: [],
 	})
 
 	const fn = watch(
@@ -141,7 +141,7 @@ const sendMessage = () => {
 			message: prompt.value
 				? [
 						{
-							id: 0,
+							id: `${Date.now()}`,
 							role: 'system',
 							render_content: prompt.value,
 							content: prompt.value,
@@ -167,6 +167,16 @@ ${resp.response.data.replace('\n', '')}
 \`\`\`
 
 `
+					messages.value.push({
+						id: resp.response.id,
+						tool_call_id: resp.response.id,
+						role: 'tool',
+						render_content: '',
+						name: resp.response.name,
+						content: resp.response.data,
+						timestamp: Date.now(),
+						tool_calls: []
+					})
 					break
 				}
 
@@ -179,8 +189,8 @@ ${resp.request.data.replace('\n', '')}
 \`\`\`
 
 `
-					rtn.tools_calls?.push({
-						id: 'qwq',
+					rtn.tool_calls?.push({
+						id: resp.request.id,
 						type: 'function',
 						function: {
 							name: resp.request.name,