提交 97d01542 authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 ceddc3d6
......@@ -8,7 +8,6 @@
"name": "skyagents",
"version": "0.0.0",
"dependencies": {
"@baiducloud/qianfan": "^0.0.8",
"@floating-ui/vue": "^1.0.6",
"@microsoft/fetch-event-source": "^2.0.1",
"@vueuse/core": "^10.9.0",
......@@ -77,10 +76,32 @@
"vue": "^3.1.0"
}
},
"node_modules/@babel/helper-string-parser": {
"version": "7.24.8",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz",
"integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.24.7",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz",
"integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/parser": {
"version": "7.24.0",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.0.tgz",
"integrity": "sha512-QuP/FxEAzMSjXygs8v4N9dvdXzEHN4W1oF3PxuWAtPo08UdM17u89RDMgjLn/mlc56iM0HlLmVkO/wgR+rDgHg==",
"version": "7.25.3",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.3.tgz",
"integrity": "sha512-iLTJKDbJ4hMvFPgQwwsVoxtHyWpKKPBrxkANrSYewDPaPpT5py5yeVkgPIJ7XYXhndxJpaA3PyALSXQ7u8e/Dw==",
"license": "MIT",
"dependencies": {
"@babel/types": "^7.25.2"
},
"bin": {
"parser": "bin/babel-parser.js"
},
......@@ -88,28 +109,18 @@
"node": ">=6.0.0"
}
},
"node_modules/@baiducloud/qianfan": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/@baiducloud/qianfan/-/qianfan-0.0.8.tgz",
"integrity": "sha512-xSkbLsnmLkM5Agk98FVFwcT3j1ajo5O+pT613WivjjL5ciE+VBFG7XJABAP7gWEk3Rp2vH6g32vygawfJp3a+Q==",
"node_modules/@babel/types": {
"version": "7.25.2",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.2.tgz",
"integrity": "sha512-YTnYtra7W9e6/oAZEHj0bJehPRUlLH9/fbpT5LfB0NhQXyALCRkRs3zH9v07IYhkgpqX6Z78FnuccZr/l4Fs4Q==",
"license": "MIT",
"dependencies": {
"async-mutex": "^0.5.0",
"bottleneck": "^2.19.5",
"debug": "^3.1.0",
"dotenv": "^16.4.1",
"rollup": "^4.9.6",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"underscore": "^1.9.1",
"urlencode": "^1.1.0"
}
},
"node_modules/@baiducloud/qianfan/node_modules/debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dependencies": {
"ms": "^2.1.1"
"@babel/helper-string-parser": "^7.24.8",
"@babel/helper-validator-identifier": "^7.24.7",
"to-fast-properties": "^2.0.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@ctrl/tinycolor": {
......@@ -748,6 +759,7 @@
"cpu": [
"arm"
],
"dev": true,
"optional": true,
"os": [
"android"
......@@ -760,6 +772,7 @@
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"android"
......@@ -772,6 +785,7 @@
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"darwin"
......@@ -784,6 +798,7 @@
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"darwin"
......@@ -796,6 +811,7 @@
"cpu": [
"arm"
],
"dev": true,
"optional": true,
"os": [
"linux"
......@@ -808,6 +824,7 @@
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"linux"
......@@ -820,6 +837,7 @@
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"linux"
......@@ -832,6 +850,7 @@
"cpu": [
"riscv64"
],
"dev": true,
"optional": true,
"os": [
"linux"
......@@ -844,6 +863,7 @@
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"linux"
......@@ -856,6 +876,7 @@
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"linux"
......@@ -868,6 +889,7 @@
"cpu": [
"arm64"
],
"dev": true,
"optional": true,
"os": [
"win32"
......@@ -880,6 +902,7 @@
"cpu": [
"ia32"
],
"dev": true,
"optional": true,
"os": [
"win32"
......@@ -892,6 +915,7 @@
"cpu": [
"x64"
],
"dev": true,
"optional": true,
"os": [
"win32"
......@@ -900,7 +924,8 @@
"node_modules/@types/estree": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw=="
"integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==",
"dev": true
},
"node_modules/@types/lodash": {
"version": "4.14.202",
......@@ -915,6 +940,18 @@
"@types/lodash": "*"
}
},
"node_modules/@types/node": {
"version": "22.5.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.0.tgz",
"integrity": "sha512-DkFrJOe+rfdHTqqMg0bSNlGlQ85hSoh2TPzZyhHsXnMtligRWpxUySiyw8FY14ITt24HVCiQPWxS3KO/QlGmWg==",
"dev": true,
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"undici-types": "~6.19.2"
}
},
"node_modules/@types/web-bluetooth": {
"version": "0.0.20",
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.20.tgz",
......@@ -1285,14 +1322,6 @@
"util": "^0.12.5"
}
},
"node_modules/async-mutex": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz",
"integrity": "sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA==",
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/async-validator": {
"version": "4.2.5",
"resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.2.5.tgz",
......@@ -1392,11 +1421,6 @@
"integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==",
"dev": true
},
"node_modules/bottleneck": {
"version": "2.19.5",
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
},
"node_modules/bowser": {
"version": "1.9.4",
"resolved": "https://registry.npmjs.org/bowser/-/bowser-1.9.4.tgz",
......@@ -2031,17 +2055,6 @@
"url": "https://bevry.me/fund"
}
},
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
......@@ -2680,6 +2693,7 @@
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
"dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
......@@ -2913,6 +2927,7 @@
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"dev": true,
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
......@@ -3499,7 +3514,8 @@
"node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"node_modules/mz": {
"version": "2.7.0",
......@@ -3900,9 +3916,10 @@
}
},
"node_modules/picocolors": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
"integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz",
"integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==",
"license": "ISC"
},
"node_modules/picomatch": {
"version": "2.3.1",
......@@ -4240,6 +4257,7 @@
"version": "4.13.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.13.0.tgz",
"integrity": "sha512-3YegKemjoQnYKmsBlOHfMLVPPA5xLkQ8MHLLSw/fBrFaVkEayL51DilPpNNLq1exr98F2B1TzrV0FUlN3gWRPg==",
"dev": true,
"dependencies": {
"@types/estree": "1.0.5"
},
......@@ -4299,7 +4317,8 @@
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"dev": true
},
"node_modules/sax": {
"version": "1.3.0",
......@@ -4613,6 +4632,15 @@
"integrity": "sha512-okFlQcoGTi4LQBG/PgSYblw9VOyptsz2KJZqc6qtgGdes8VktzUQkj4BI2blit072iS8VODNcMA+tvnS9dnuMA==",
"dev": true
},
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
"integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
"license": "MIT",
"engines": {
"node": ">=4"
}
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
......@@ -4625,11 +4653,6 @@
"node": ">=8.0"
}
},
"node_modules/tslib": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
},
"node_modules/tty-browserify": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.1.tgz",
......@@ -4664,6 +4687,8 @@
"version": "5.4.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz",
"integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==",
"optional": true,
"peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
......@@ -4678,10 +4703,14 @@
"integrity": "sha512-Hhy+BhRBleFjpJ2vchUNN40qgkh0366FWJGqVLYBHev0vpHTrXSA0ryT+74UiW6KWsldNurQMKGqCm1M2zBciQ==",
"dev": true
},
"node_modules/underscore": {
"version": "1.13.6",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz",
"integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A=="
"node_modules/undici-types": {
"version": "6.19.8",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
"dev": true,
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/unescape": {
"version": "1.0.1",
......@@ -4905,14 +4934,6 @@
"integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==",
"dev": true
},
"node_modules/urlencode": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/urlencode/-/urlencode-1.1.0.tgz",
"integrity": "sha512-OOAOh9owHXr/rCN1tteSnYwIvsrGHamSz0hafMhmQa7RcS4+Ets6/2iVClVGjt9jkDW84UqoMw/Gmpc7QolX6A==",
"dependencies": {
"iconv-lite": "~0.4.11"
}
},
"node_modules/urllib": {
"version": "2.41.0",
"resolved": "https://registry.npmjs.org/urllib/-/urllib-2.41.0.tgz",
......
......@@ -12,7 +12,6 @@
"release": "npm run build && npm run deploy"
},
"dependencies": {
"@baiducloud/qianfan": "^0.0.8",
"@floating-ui/vue": "^1.0.6",
"@microsoft/fetch-event-source": "^2.0.1",
"@vueuse/core": "^10.9.0",
......
import { ChatCompletion } from '@baiducloud/qianfan'
// 手动传 AK/SK
const client = new ChatCompletion({ QIANFAN_AK: 'wY7bvMpkWeZbDVq9w3EDvpjU', QIANFAN_SK: 'XJwpiJWxs5HXkOtbo6tQrvYPZFJAWdAy' })
async function main() {
const resp = await client.chat(
{
messages: [
{
role: 'user',
content: '今天深圳天气'
}
]
},
'ERNIE-4.0-8K'
)
console.log(resp)
}
main()
import { ChatCompletion } from '@baiducloud/qianfan'
// 手动传 AK/SK
const client = new ChatCompletion({ QIANFAN_AK: 'wY7bvMpkWeZbDVq9w3EDvpjU', QIANFAN_SK: 'XJwpiJWxs5HXkOtbo6tQrvYPZFJAWdAy' })
async function main() {
const resp = await client.chat(
{
messages: [
{
role: 'user',
content: '今天深圳天气'
}
]
},
'ERNIE-4.0-8K'
)
console.log(resp)
}
main()
import md5 from 'blueimp-md5'
import { fetchEventSource } from '@microsoft/fetch-event-source'
import { fetchAgents } from '@/api/chat'
import axios from 'axios'
// import { fetchEventSource } from '@microsoft/fetch-event-source'
export function useChat() {
const authKey = 'f3846153ba784b6d86bdcd5533259c88'
const authSecret = 'HO4IyLEwEOHpeOXBxaLQUOqWslJRGs1M'
const AK = 'wY7bvMpkWeZbDVq9w3EDvpjU'
const SK = 'XJwpiJWxs5HXkOtbo6tQrvYPZFJAWdAy'
const messages = ref([])
const chatId = ref(null)
const isLoading = ref(false)
async function post(data) {
const timestamp = Date.now()
const sign = md5(`${authKey}${authSecret}${timestamp}`)
isLoading.value = true
await fetchEventSource('/api/ai/openapi/agent/chat/stream/v1', {
method: 'POST',
headers: { authKey, timestamp, sign, 'Content-Type': 'application/json' },
body: JSON.stringify({ ...data, chatId: chatId.value, agentId: 'f3846153ba784b6d86bdcd5533259c88' }),
async onopen(response) {
if (response.ok) {
return response
} else {
throw response
}
},
onmessage(res) {
console.log(res.data)
const message = JSON.parse(res.data)
chatId.value = message.chatId
const conversationId = message.conversationId
const messageIndex = messages.value.findIndex(session => session.conversationId === conversationId)
let content = message.content || ''
if (message.content === '\n') content = '<br/>'
if (messageIndex === -1) {
messages.value.push({ conversationId, role: 'bot', content })
} else {
messages.value[messageIndex].content = messages.value[messageIndex].content + content
}
isLoading.value = false
},
onerror(err) {
isLoading.value = false
throw err
}
const res = await axios.post('/api/qianfan/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=' + (await getAccessToken()), {
messages: [{ role: 'user', content: data.userChatInput }]
})
messages.value.push({ role: 'assistant', content: res.data.result.replaceAll('\n', '<br/>') })
isLoading.value = false
// await fetchEventSource('/api/qianfan/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token=' + (await getAccessToken()), {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({
// messages: [{ role: 'user', content: data.userChatInput }],
// stream: true
// }),
// async onopen(response) {
// if (response.ok) {
// return response
// } else {
// throw response
// }
// },
// onmessage(res) {
// console.log(res.data)
// const message = JSON.parse(res.data)
// chatId.value = message.chatId
// const id = message.id
// const messageIndex = messages.value.findIndex(session => session.id === id)
// let content = message.result || ''
// if (message.result === '\n') content = '<br/>'
// if (messageIndex === -1) {
// messages.value.push({ id, role: 'bot', content })
// } else {
// messages.value[messageIndex].content = messages.value[messageIndex].content + content
// }
// isLoading.value = false
// },
// onerror(err) {
// isLoading.value = false
// throw err
// }
// })
}
async function getAgents() {
await fetchAgents()
async function getAccessToken() {
const res = await axios.post('/api/qianfan/oauth/2.0/token?grant_type=client_credentials&client_id=' + AK + '&client_secret=' + SK)
return res.data.access_token
}
return { chatId, messages, post, getAgents, isLoading }
return { chatId, messages, post, isLoading }
}
import axios from 'axios'
// import { fetchEventSource } from '@microsoft/fetch-event-source'
export function useChat() {
const AK = 'wY7bvMpkWeZbDVq9w3EDvpjU'
const SK = 'XJwpiJWxs5HXkOtbo6tQrvYPZFJAWdAy'
const messages = ref([])
const chatId = ref(null)
const isLoading = ref(false)
async function post(data) {
isLoading.value = true
const res = await axios.post('/api/qianfan/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=' + (await getAccessToken()), {
messages: [{ role: 'user', content: data.userChatInput }]
})
messages.value.push({ role: 'assistant', content: res.data.result.replaceAll('\n', '<br/>') })
isLoading.value = false
// await fetchEventSource('/api/qianfan/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=' + (await getAccessToken()), {
// method: 'POST',
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({
// messages: [{ role: 'user', content: data.userChatInput }],
// stream: true
// }),
// async onopen(response) {
// if (response.ok) {
// return response
// } else {
// throw response
// }
// },
// onmessage(res) {
// console.log(res.data)
// const message = JSON.parse(res.data)
// chatId.value = message.chatId
// const id = message.id
// const messageIndex = messages.value.findIndex(session => session.id === id)
// let content = message.result || ''
// if (message.result === '\n') content = '<br/>'
// if (messageIndex === -1) {
// messages.value.push({ id, role: 'bot', content })
// } else {
// messages.value[messageIndex].content = messages.value[messageIndex].content + content
// }
// isLoading.value = false
// },
// onerror(err) {
// isLoading.value = false
// throw err
// }
// })
}
async function getAccessToken() {
const res = await axios.post('/api/qianfan/oauth/2.0/token?grant_type=client_credentials&client_id=' + AK + '&client_secret=' + SK)
return res.data.access_token
}
return { chatId, messages, post, isLoading }
}
import { ChatCompletion } from '@baiducloud/qianfan'
export function useChat() {
const AK = 'wY7bvMpkWeZbDVq9w3EDvpjU'
const SK = 'XJwpiJWxs5HXkOtbo6tQrvYPZFJAWdAy'
const client = new ChatCompletion({ QIANFAN_AK: AK, QIANFAN_SK: SK })
const messages = ref([])
const chatId = ref(null)
const isLoading = ref(false)
async function post(data) {
isLoading.value = true
const res = await client.chat({
messages: [{ role: 'user', content: data.userChatInput }],
disable_search: false,
enable_citation: false
})
messages.value.push({ role: 'assistant', content: res.data.result.replaceAll('\n', '<br/>') })
isLoading.value = false
}
return { chatId, messages, post, isLoading }
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论