Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-ai-chat
提交
2a5d4ce4
U
uni-ai-chat
项目概览
DCloud
/
uni-ai-chat
通知
893
Star
11
Fork
8
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-ai-chat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2a5d4ce4
编写于
5月 08, 2023
作者:
DCloud_JSON
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
替换 SSEChannel 为 sseChannel
上级
fe468eca
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
403 addition
and
421 deletion
+403
-421
manifest.json
manifest.json
+1
-1
pages/chat/chat.vue
pages/chat/chat.vue
+344
-344
uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js
uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js
+12
-12
uniCloud-aliyun/database/opendb-app-client-key.schema.json
uniCloud-aliyun/database/opendb-app-client-key.schema.json
+0
-34
uniCloud-aliyun/database/uni-ai-chat.schema.json
uniCloud-aliyun/database/uni-ai-chat.schema.json
+0
-30
uniCloud-aliyun/database/uni-id-scores.schema.json
uniCloud-aliyun/database/uni-id-scores.schema.json
+46
-0
未找到文件。
manifest.json
浏览文件 @
2a5d4ce4
...
...
@@ -88,7 +88,7 @@
"vueVersion"
:
"3"
,
"h5"
:
{
"unipush"
:
{
"enable"
:
fals
e
"enable"
:
tru
e
}
},
"fallbackLocale"
:
"zh-Hans"
...
...
pages/chat/chat.vue
浏览文件 @
2a5d4ce4
...
...
@@ -323,11 +323,11 @@
console
.
log
(
'
send to ai messages:
'
,
messages
);
let
SSE
Channel
=
false
;
let
sse
Channel
=
false
;
if
(
this
.
stream
){
SSE
Channel
=
new
uniCloud
.
SSEChannel
()
// 创建消息通道
// console.log('
SSEChannel',SSE
Channel);
SSE
Channel
.
on
(
'
message
'
,
(
message
)
=>
{
// 监听message事件
sse
Channel
=
new
uniCloud
.
SSEChannel
()
// 创建消息通道
// console.log('
sseChannel',sse
Channel);
sse
Channel
.
on
(
'
message
'
,
(
message
)
=>
{
// 监听message事件
// console.log('on message', message);
if
(
this
.
sseIndex
===
0
)
{
this
.
msgList
.
push
({
...
...
@@ -344,7 +344,7 @@
}
this
.
sseIndex
++
})
SSE
Channel
.
on
(
'
end
'
,
(
e
)
=>
{
// 监听end事件,如果云端执行end时传了message,会在客户端end事件内收到传递的消息
sse
Channel
.
on
(
'
end
'
,
(
e
)
=>
{
// 监听end事件,如果云端执行end时传了message,会在客户端end事件内收到传递的消息
// console.log('on end', e);
if
(
e
&&
(
e
.
summarize
||
e
.
insufficientPoints
)){
this
.
updateLastMsg
(
lastMsg
=>
{
...
...
@@ -358,7 +358,7 @@
this
.
sseIndex
=
0
this
.
showLastMsg
()
})
await
SSE
Channel
.
open
()
// 等待通道开启
await
sse
Channel
.
open
()
// 等待通道开启
}
...
...
@@ -367,11 +367,11 @@
})
uniAiChat
.
send
({
messages
,
SSE
Channel
sse
Channel
})
.
then
(
res
=>
{
this
.
updateLastMsg
({
state
:
100
})
if
(
!
SSEChannel
)
{
if
(
!
sseChannel
)
{
// console.log(res, res.reply);
this
.
msgList
.
push
({
isAi
:
true
,
...
...
uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js
浏览文件 @
2a5d4ce4
...
...
@@ -61,8 +61,8 @@ module.exports = {
requestId
:
this
.
getUniCloudRequestId
()
})
this
.
textSecCheck
=
async
(
content
)
=>
{
let
{
SSE
Channel
}
=
this
.
getParams
()[
0
]
||
{}
if
(
SSE
Channel
){
let
{
sse
Channel
}
=
this
.
getParams
()[
0
]
||
{}
if
(
sse
Channel
){
throw
"
流式响应模式,内容安全识别功能无效
"
}
// 检测文本
...
...
@@ -109,9 +109,9 @@ module.exports = {
}
}
else
if
(
error
==
'
insufficientPoints
'
){
let
reply
=
"
积分不足,请看完激励视频广告后再试
"
let
{
SSE
Channel
}
=
this
.
getParams
()[
0
]
||
{}
if
(
SSE
Channel
){
const
channel
=
uniCloud
.
deserializeSSEChannel
(
SSE
Channel
)
let
{
sse
Channel
}
=
this
.
getParams
()[
0
]
||
{}
if
(
sse
Channel
){
const
channel
=
uniCloud
.
deserializeSSEChannel
(
sse
Channel
)
await
channel
.
write
(
reply
)
await
channel
.
end
({
"
insufficientPoints
"
:
true
...
...
@@ -147,7 +147,7 @@ module.exports = {
},
async
send
({
messages
,
SSE
Channel
sse
Channel
})
{
// 初次调试时,可不从客户端获取数据,直接使用下面写死在云函数里的数据
// messages = [{
...
...
@@ -165,13 +165,13 @@ module.exports = {
let
{
llm
,
chatCompletionOptions
}
=
config
return
await
chatCompletion
({
messages
,
//消息内容
SSE
Channel
,
//sse渠道对象
sse
Channel
,
//sse渠道对象
llm
})
async
function
chatCompletion
({
messages
,
summarize
=
false
,
SSE
Channel
=
false
,
sse
Channel
=
false
,
llm
})
{
...
...
@@ -179,13 +179,13 @@ module.exports = {
let
res
=
await
llmManager
.
chatCompletion
({
...
chatCompletionOptions
,
messages
,
stream
:
SSE
Channel
!==
false
stream
:
sse
Channel
!==
false
})
if
(
SSE
Channel
)
{
if
(
sse
Channel
)
{
let
reply
=
""
return
new
Promise
((
resolve
,
reject
)
=>
{
const
channel
=
uniCloud
.
deserializeSSEChannel
(
SSE
Channel
)
const
channel
=
uniCloud
.
deserializeSSEChannel
(
sse
Channel
)
res
.
on
(
'
message
'
,
async
(
message
)
=>
{
// await channel.write(message)
// console.log('---message----', message)
...
...
@@ -256,7 +256,7 @@ module.exports = {
messages
,
summarize
:
true
,
stream
:
false
,
SSE
Channel
:
false
sse
Channel
:
false
})
return
res
.
reply
}
...
...
uniCloud-aliyun/database/opendb-app-client-key.schema.json
已删除
100644 → 0
浏览文件 @
fe468eca
{
"bsonType"
:
"object"
,
"required"
:
[
"_id"
,
"value"
],
"properties"
:
{
"_id"
:
{
"bsonType"
:
"string"
,
"description"
:
"自动生成的id"
},
"app_id"
:
{
"bsonType"
:
"string"
,
"description"
:
"客户端DCloud AppId"
},
"device_id"
:
{
"bsonType"
:
"string"
,
"description"
:
"客户端设备id"
},
"private_key"
:
{
"bsonType"
:
"string"
,
"description"
:
"私钥,仅保存在云端"
},
"public_key"
:
{
"bsonType"
:
"string"
,
"description"
:
"公钥,下发给客户端使用"
},
"create_date"
:
{
"bsonType"
:
"timestamp"
,
"description"
:
"创建时间"
}
},
"version"
:
"0.0.1"
}
\ No newline at end of file
uniCloud-aliyun/database/uni-ai-chat.schema.json
已删除
100644 → 0
浏览文件 @
fe468eca
//
文档教程:
https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType"
:
"object"
,
"required"
:
[],
"permission"
:
{
"read"
:
false
,
"create"
:
false
,
"update"
:
false
,
"delete"
:
false
},
"properties"
:
{
"_id"
:
{
"description"
:
"ID,系统自动生成"
},
"user_id"
:{
"bsonType"
:
"string"
,
"description"
:
"用户id"
},
"balance"
:{
"bsonType"
:
"int"
,
"description"
:
"剩余可对话的次数"
},
"update_time"
:{
"bsonType"
:
"timestamp"
,
"forceDefaultValue"
:{
"$env"
:
"now"
}
}
}
}
\ No newline at end of file
uniCloud-aliyun/database/uni-id-scores.schema.json
0 → 100644
浏览文件 @
2a5d4ce4
{
"bsonType"
:
"object"
,
"required"
:
[
"user_id"
,
"score"
,
"balance"
],
"properties"
:
{
"_id"
:
{
"description"
:
"ID,系统自动生成"
},
"user_id"
:
{
"bsonType"
:
"string"
,
"description"
:
"用户id,参考uni-id-users表"
},
"score"
:
{
"bsonType"
:
"int"
,
"description"
:
"本次变化的积分"
},
"type"
:
{
"bsonType"
:
"int"
,
"enum"
:
[
1
,
2
],
"description"
:
"积分类型 1:收入 2:支出"
},
"balance"
:
{
"bsonType"
:
"int"
,
"description"
:
"变化后的积分余额"
},
"comment"
:
{
"bsonType"
:
"string"
,
"description"
:
"备注,说明积分新增、消费的缘由"
,
"trim"
:
"both"
},
"create_date"
:
{
"bsonType"
:
"timestamp"
,
"description"
:
"创建时间"
,
"forceDefaultValue"
:
{
"$env"
:
"now"
}
}
},
"version"
:
"0.0.1"
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录