Commit 03e12793 by Ford

修改了WorldChat支持高并发,加了协程。

parent 53068b6a
...@@ -172,7 +172,43 @@ ...@@ -172,7 +172,43 @@
"cn_name": "郭德纲" "cn_name": "郭德纲"
} }
},
"business_manager_assessment_config_translations": {
"SceneInformation": "场景信息",
"location": "地点",
"name": "名称",
"security": "有保安",
"client": "客户",
"appearance": "外观",
"attitude": "对用户的态度",
"personality": "性格",
"introduction": "简介",
"roleName": "角色名",
"opener": "开场白",
"promotion": "推介项目",
"projectDescription": "项目介绍",
"projectName": "项目名",
"username": "用户名",
"userBackground": "用户背景信息",
"CustomTraining": "定制训练",
"sceneRulesCustom": "场景规则定制",
"ruleOne": "规则一",
"ruleTwo": "规则二",
"ruleThree": "规则三",
"outcomeSet": "结局集",
"date": "date",
"id": "id",
"result": "result",
"difficulty": "难易程度",
"AssessmentWeights": "考核权重",
"professionalism": "专业程度",
"adaptability": "应变能力",
"communicationSkills": "沟通能力",
"socialEtiquette": "社交礼仪"
} }
} }
...@@ -62,6 +62,10 @@ type AppConfig struct { ...@@ -62,6 +62,10 @@ type AppConfig struct {
JwtSecret string `json:"jwt_secret"` JwtSecret string `json:"jwt_secret"`
MiGuAuthId string `json:"miGuAuthId"` MiGuAuthId string `json:"miGuAuthId"`
// 增加 BusinessManagerAssessmentConfigTranslations 字段
BusinessManagerAssessmentConfigTranslations map[string]string `json:"business_manager_assessment_config_translations"` //英文转中文
ReverseTranslations map[string]string // 反向映射,中文转英文,不需要从JSON解码
SoulUrl string `json:"soul_url"` SoulUrl string `json:"soul_url"`
SoulAuth string `json:"soul_auth"` SoulAuth string `json:"soul_auth"`
TranscribeUrl string `json:"transcribe_url"` TranscribeUrl string `json:"transcribe_url"`
...@@ -129,8 +133,10 @@ func InitConfig() *AppConfig { ...@@ -129,8 +133,10 @@ func InitConfig() *AppConfig {
} }
*/ */
if err != nil { if err != nil {
println("error is :", err.Error()) fmt.Println("Error opening config file:", err)
return nil
} }
defer file.Close()
decoder := json.NewDecoder(file) decoder := json.NewDecoder(file)
...@@ -138,10 +144,18 @@ func InitConfig() *AppConfig { ...@@ -138,10 +144,18 @@ func InitConfig() *AppConfig {
err = decoder.Decode(&conf) err = decoder.Decode(&conf)
if err != nil { if err != nil {
fmt.Println("Error decoding config:", err)
return nil
}
println("error is :", err.Error()) // 创建世界配置信息json反向映射字典
reverseTranslations := make(map[string]string)
for k, v := range conf.BusinessManagerAssessmentConfigTranslations {
reverseTranslations[v] = k
} }
// 将反向映射存储为全局变量,或添加到配置结构中
conf.ReverseTranslations = reverseTranslations // 假设你在AppConfig中添加了这个字段
Conf = &conf Conf = &conf
return &conf return &conf
......
package main
import (
"encoding/json"
"fmt"
)
// translations 是英文到中文的键名映射
var translations = map[string]string{
"SceneInformation": "场景信息",
"location": "地点",
"name": "名称",
"security": "有保安",
"client": "客户",
"appearance": "外观",
"attitude": "对用户的态度",
"personality": "性格",
"introduction": "简介",
"roleName": "角色名",
"opener": "开场白",
"promotion": "推介项目",
"projectDescription": "项目介绍",
"projectName": "项目名",
"username": "用户名",
"userBackground": "用户背景信息",
"CustomTraining": "定制训练",
"sceneRulesCustom": "场景规则定制",
"ruleOne": "规则一",
"ruleTwo": "规则二",
"ruleThree": "规则三",
"outcomeSet": "结局集",
"date": "date",
"id": "id",
"result": "result",
"difficulty": "难易程度",
"AssessmentWeights": "考核权重",
"professionalism": "专业程度",
"adaptability": "应变能力",
"communicationSkills": "沟通能力",
"socialEtiquette": "社交礼仪",
}
// translateKeys 是递归函数,用于转换JSON对象的键
func translateKeys(data interface{}) interface{} {
switch obj := data.(type) {
case map[string]interface{}:
newMap := make(map[string]interface{})
for k, v := range obj {
newKey := k
if val, ok := translations[k]; ok {
newKey = val
}
newMap[newKey] = translateKeys(v)
}
return newMap
case []interface{}:
for i, v := range obj {
obj[i] = translateKeys(v)
}
}
return data
}
func main() {
jsonStr := `{
"ConfigData": {
"SceneInformation": {
"location": {
"name": "南京市移动办公大楼",
"security": false
},
"client": [
{
"appearance": "和蔼可亲,穿着朴素",
"attitude": "温和、耐心",
"personality": "温和、耐心",
"introduction": "来移动想要给家里办宽带的客户,赵文生,教育水平:中专,职业背景:退休\n - 目的性:家里要办宽带,来移动大厅想看看为家庭提供稳定的网络环境。\n已知信息:对宽带费用没概念,只知道自己要手机刷短视频快的,最好可以有话费套餐方便联系子女的,但是每个月预算不超过100元,在这个区间都是可以考虑的预算,对态度好的服务别有青睐。 \n知识库背景:\no对宽带的了解较少,主要用于观看电视、视频通话等。\no可能需要子女或工作人员的帮助来了解和使用宽带。\n3.消费心理预期:\no希望宽带费用不高,操作简单易懂。主要想依赖宽带,对通话和流量的要求不高,可有可无\no对网络速度的要求相对较低,主要关注稳定性。\n4.心理特征:\no目的性:与家人保持联系,丰富退休生活。\no心理活动预期:担心操作复杂,遇到问题时希望能得到及时的帮助。\n5.性格特征:\no决策风格:依赖他人的建议,比较保守。\no风险偏好:极低风险,追求稳定和安心。\no个性:节俭,注重实用性。\n6.服务偏好:\no偏好上门服务和面对面的指导。\no对客服的耐心和细心程度青睐程度较高。",
"roleName": "赵文生"
}
],
"opener": "您的身份是南京移动的宽带业务经理,请以您专业的知识和热情的服务,开始您的营销任务,为他带来更加便捷和快速的互联网生活体验。坐在柜台对面的,是一位和蔼可亲,穿着朴素的南京市民,您正准备向他展开宽带业务的推广",
"promotion": {
"projectDescription": "面向个人或者企业提供高质量的宽带业务",
"projectName": "南京移动宽带活动"
},
"username": "经理",
"userBackground": "中国移动南京宽带业务经理"
},
"CustomTraining": {
"sceneRulesCustom": {
"ruleOne": "客户服务对所有客户的提问和反馈要及时响应,确保在24小时内回复,处理客户投诉时保持礼貌和耐心,积极解决问题并记录每个案例。提供清晰准确的信息,避免引起客户的混淆",
"ruleThree": "数据保护:严格保密客户和公司的敏感信息,防止未经授权的访问和泄露。所有的电子数据必须备份,并采取适当的安全措施保护。遵守相关的数据保护法律和法规,例如GDPR。",
"ruleTwo": "财务管理,所有的财务交易必须记录在案,确保账目清晰透明。严格遵守预算,不得擅自超支或改变用途。定期进行财务审计,确保没有违规行为。"
},
"outcomeSet": [
{
"date": "所有项目目标按时完成,超出预期表现",
"id": 0,
"result": "达成协议"
},
{
"date": "项目目标基本达成,存在小幅度延迟",
"id": 1,
"result": "下次再议"
},
{
"date": "项目目标未达成,表现不佳",
"id": 2,
"result": "遗憾收场"
}
],
"difficulty": "简单"
},
"AssessmentWeights": {
"professionalism": "20",
"adaptability": "40",
"communicationSkills": "90",
"socialEtiquette": "80"
}
}
}
`
var data map[string]interface{}
err := json.Unmarshal([]byte(jsonStr), &data)
if err != nil {
fmt.Println("Error parsing JSON:", err)
return
}
// 转换键名
translatedData := translateKeys(data)
translatedJSON, err := json.MarshalIndent(translatedData, "", " ")
if err != nil {
fmt.Println("Error marshalling JSON:", err)
return
}
fmt.Println(string(translatedJSON))
}
...@@ -43,6 +43,15 @@ func AddWorldInfo(session *xorm.Session, worldInfo *WorldInfo) (int64, error) { ...@@ -43,6 +43,15 @@ func AddWorldInfo(session *xorm.Session, worldInfo *WorldInfo) (int64, error) {
} }
func CreateWorldInfo(session *xorm.Session, worldInfo *WorldInfo) (*WorldInfo, error) {
_, err := session.Insert(worldInfo)
if err != nil {
return nil, err // Return 0 if there's an error since ID cannot be negative
}
return worldInfo, nil // Return the new world's ID
}
//根据世界id查询世界信息 //根据世界id查询世界信息
func GetWorld(session *xorm.Session, id int64) (*WorldInfo, error) { func GetWorld(session *xorm.Session, id int64) (*WorldInfo, error) {
world := &WorldInfo{} world := &WorldInfo{}
......
...@@ -6,24 +6,17 @@ import ( ...@@ -6,24 +6,17 @@ import (
"WorldEpcho/src/datasource" "WorldEpcho/src/datasource"
"WorldEpcho/src/models" "WorldEpcho/src/models"
"WorldEpcho/src/utils" "WorldEpcho/src/utils"
"github.com/gin-contrib/sessions"
"os"
"strconv"
"strings"
"time"
//"time"
//"chat/cache"
//"chat/conf"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"log" "log"
"net/http" "net/http"
//"strconv" "os"
//"time" "strconv"
"strings"
"time"
) )
//const month = 60 * 60 * 24 * 30 // 按照30天算一个月 //const month = 60 * 60 * 24 * 30 // 按照30天算一个月
...@@ -1050,9 +1043,9 @@ func ParseEndStrAndReformat(response *WorldSoulReplyMsg) *WorldSoulReplyMsg { ...@@ -1050,9 +1043,9 @@ func ParseEndStrAndReformat(response *WorldSoulReplyMsg) *WorldSoulReplyMsg {
if ok { if ok {
if endStr != "" { if endStr != "" {
// 解析 "EndStr" 中的详细字段 // 解析 "EndStr" 中的详细字段
title := strings.Split(endStr, "@")[0] // 提取 '@' 前的标题 title := strings.Split(endStr, "@")[0] // 提取 '@' 前的标题
overallScore := extractBetween(endStr, "【整体评分】:", "\n") // 提取整体评分 overallScore := extractBetween(endStr, "【整体评分】:", "\n") // 提取整体评分
objectiveEvaluation := extractToEnd(endStr, "【客观评价】:") // 提取客观评价至字符串末尾 objectiveEvaluation := extractBetween(endStr, "【客观评价】:", "## 【整体评分】") // 提取客观评价至字符串末尾
// 将 "EndStr" 结构化为 JSON 对象 // 将 "EndStr" 结构化为 JSON 对象
endStrObj := map[string]interface{}{ endStrObj := map[string]interface{}{
...@@ -1077,7 +1070,10 @@ func ParseEndStrAndReformat(response *WorldSoulReplyMsg) *WorldSoulReplyMsg { ...@@ -1077,7 +1070,10 @@ func ParseEndStrAndReformat(response *WorldSoulReplyMsg) *WorldSoulReplyMsg {
newResponse.WObj["emotion"] = emotion newResponse.WObj["emotion"] = emotion
delete(newResponse.WObj, "表情") delete(newResponse.WObj, "表情")
} }
if chatTime, exists := newResponse.WObj["时间"]; exists {
newResponse.WObj["time"] = chatTime
delete(newResponse.WObj, "时间")
}
return &newResponse // 返回修改后的新响应体 return &newResponse // 返回修改后的新响应体
} }
......
...@@ -62,6 +62,9 @@ func (manager *WorldClientManager) WorldWebSocketStart() { ...@@ -62,6 +62,9 @@ func (manager *WorldClientManager) WorldWebSocketStart() {
log.Printf("消息发送失败: %v", err) log.Printf("消息发送失败: %v", err)
continue continue
} }
if conn.Send != nil {
close(conn.Send)
}
delete(WorldManager.Client, utils.Strval(conn.WorldConversations.Uid)) delete(WorldManager.Client, utils.Strval(conn.WorldConversations.Uid))
} }
} }
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment