From 815418cb547a532cf82c042c4fe9370797f6b6ce Mon Sep 17 00:00:00 2001 From: DCloud__JSON Date: Sat, 6 May 2023 15:49:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=92=8C=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _redme.md | 21 ++++++++++--------- .../reward-video-callback/index.js | 8 +++---- .../cloudfunctions/uni-ai-chat/index.obj.js | 6 +++--- .../uni-config-center/uni-ai-chat/config.json | 7 ++++--- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/_redme.md b/_redme.md index 3542f85..be317d5 100644 --- a/_redme.md +++ b/_redme.md @@ -53,10 +53,11 @@ | 字段 | 类型 | 默认值| 描述 | | :-------- | :-------- | :--- | :-------------------- | | contentSecurity | Boolean | false | 开启内容安全识别 | -| ad | object | - | 广告配置 | -|   |- rewardScore | Number | 3 | 看一次广告奖励多少积分 | -| needReduceScore | Number | 0 | 对话一次需要消耗的积分数 | -| chatCompletionOptions | Object | - | 支持配置:`model`,`tokensToGenerate`(默认值:512),`temperature`,`topP`,详情查看:[https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#chat-completion](https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#chat-completion)| +| spentScore | Number | 0 | 对话一次所需消耗的积分数 | +| earnedScore | object | - | 配置积分的获取策略 | +|   |- ad | Number | 3 | 观看1次广告可获得的积分数量 | +|   |- price | Number | 3 | 支付1元可获得的积分数量(暂未支持) | +| chatCompletionOptions | Object | - | 支持配置:`model`,`tokensToGenerate`(默认值:512),`temperature`,`topP`
详情查看:[https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#chat-completion](https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#chat-completion)| | llm | Object | - | 大语言模型配置,详情查看:[https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#get-llm-manager](https://uniapp.dcloud.net.cn/uniCloud/uni-ai.html#get-llm-manager) | @@ -66,7 +67,7 @@ 注意:如果对ai返回结果进行内容安全检查,会导致stream流式响应失效。 -## 营运专题@ad +## 营运专题 @ad v1.0.3起支持:启用与uni-ai对话消耗积分(积分通过看[激励视频广告](https://uniapp.dcloud.net.cn/component/ad-rewarded-video.html)获得)的模式。 **平台差异说明** @@ -80,17 +81,17 @@ v1.0.3起支持:启用与uni-ai对话消耗积分(积分通过看[激励视 2. 创建激励视频广告位;在[应用列表](https://uniad.dcloud.net.cn/list/app)点击`应用详情`再点击`新建广告位`;如下图:广告类型选`激励视频广告`,配置服务器回调,选uni-ai-chat部署的uniCloud服务空间,回调云函数名称选:`reward-video-callback` -微信小程序端注意: -- 参考:[uniAD微信小程序广告开通指南](https://ask.dcloud.net.cn/article/39928)开通广告后会自动创建广告位 -- 广告服务器回调,提前条件:详情查看[https://uniapp.dcloud.net.cn/uni-ad/ad-rewarded-video.html#callbackweixin](https://uniapp.dcloud.net.cn/uni-ad/ad-rewarded-video.html#callbackweixin) + **微信小程序端注意**: + - 参考:[uniAD微信小程序广告开通指南](https://ask.dcloud.net.cn/article/39928)开通广告后会自动创建广告位 + - 广告服务器回调,提前条件:详情查看[https://uniapp.dcloud.net.cn/uni-ad/ad-rewarded-video.html#callbackweixin](https://uniapp.dcloud.net.cn/uni-ad/ad-rewarded-video.html#callbackweixin) 3. 配置广告位唯一标识(adpid) - 客户端,配置路径:`/config.js` - 服务端,配置路径:`uniCloud/cloudfunctions/common/uni-config-center/uni-ad/config.json` -4. 一般的营运模式,会给予新注册的用户少量的默认积分(即:新注册用户有n次免费对话次数),在`uni-id/hooks`配置。路径:`uniCloud/cloudfunctions/common/uni-config-center/uni-id/hooks/index.js` +4. 一般情况下,新注册的用户将获得少量初始积分(即:对于新注册用户,系统将给予其n次免费对话机会);在`uni-id/hooks`配置。路径:`uniCloud/cloudfunctions/common/uni-config-center/uni-id/hooks/index.js` 5. 配置对话一次需要消耗多少积分`needReduceScore`[详情查看](#config) -6. 配置看一次广告获得多少积分`ad.rewardScore`[详情查看](#config) +6. 配置看一次广告获得多少积分`earnedScore.ad`[详情查看](#config) 注意:因为广告服务器回调走的是云端,以上配置项,配置完成后记得上传。 diff --git a/uniCloud-aliyun/cloudfunctions/reward-video-callback/index.js b/uniCloud-aliyun/cloudfunctions/reward-video-callback/index.js index d5b782d..fc0a6da 100644 --- a/uniCloud-aliyun/cloudfunctions/reward-video-callback/index.js +++ b/uniCloud-aliyun/cloudfunctions/reward-video-callback/index.js @@ -17,23 +17,23 @@ async function nextFn(data) { } if(typeof data.extra == 'object' && data.extra.unique_type == "uni-ai-chat"){ - await uniAiChatRewardScore(data) + await uniAiChatEarnedScoreByAd(data) } // uni-ai-chat 看广告奖励积分 - async function uniAiChatRewardScore(data){ + async function uniAiChatEarnedScoreByAd(data){ const uniAiChatConfig = require('uni-config-center')({ pluginId: 'uni-ai-chat' }).config() console.log('uniAiChatConfig',uniAiChatConfig); - if(!uniAiChatConfig || !uniAiChatConfig.ad || !uniAiChatConfig.ad.rewardScore){ + if(!uniAiChatConfig || !uniAiChatConfig.ad || !uniAiChatConfig.earnedScore.ad){ throw new Error('请先完成uni-ai-chat的广告奖励配置') } if(!data.extra.user_id){ return console.error('userId 不能为空'); } - let score = db.command.inc(uniAiChatConfig.ad.rewardScore) + let score = db.command.inc(uniAiChatConfig.earnedScore.ad) let res = await db.collection('uni-id-users').doc(data.extra.user_id).update({score}) console.log('update res',res) } diff --git a/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js b/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js index 9ed7e47..33428af 100644 --- a/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js +++ b/uniCloud-aliyun/cloudfunctions/uni-ai-chat/index.obj.js @@ -22,7 +22,7 @@ module.exports = { if(this.getMethodName() == 'send'){ // 从配置中心获取是否需要销毁积分 - if(config.needReduceScore){ + if(config.spentScore){ /*先校验token(用户身份令牌)是否有效,并获得用户的_id*/ // 获取客户端信息 @@ -49,7 +49,7 @@ module.exports = { } await userscollection.doc(this.current_uid) .update({ - score:db.command.inc(-1 * config.needReduceScore) + score:db.command.inc(-1 * config.spentScore) }) } @@ -63,7 +63,7 @@ module.exports = { this.textSecCheck = async (content)=>{ let {SSEChannel} = this.getParams()[0]||{} if(SSEChannel){ - return console.log('提示:流式响应模式,内容安全识别功能无效'); + throw "流式响应模式,内容安全识别功能无效" } // 检测文本 const checkRes = await uniSecCheck.textSecCheck({ diff --git a/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-ai-chat/config.json b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-ai-chat/config.json index 1ae9d50..aba8beb 100644 --- a/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-ai-chat/config.json +++ b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-ai-chat/config.json @@ -1,9 +1,10 @@ { "contentSecurity":false, - "ad":{ - "rewardScore":3 + "spentScore":0, + "earnedScore":{ + "ad":3, + "price":3 }, - "needReduceScore":0, "llm":{}, "chatCompletionOptions":{ "tokensToGenerate":512 -- GitLab