Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
WorldEpcho
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ford
WorldEpcho
Commits
53068b6a
Commit
53068b6a
authored
Oct 11, 2024
by
Ford
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了WorldChat支持高并发,加了协程。
parent
889709d3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
171 additions
and
12 deletions
+171
-12
src/service/WorldChat.go
+160
-3
src/service/WorldChat_HighConcurrency.go_bak
+0
-0
src/service/WorldEchoAPIService.go
+11
-9
No files found.
src/service/WorldChat.go
View file @
53068b6a
...
@@ -60,7 +60,7 @@ type WorldClient struct {
...
@@ -60,7 +60,7 @@ type WorldClient struct {
//DpConversations *models.DpConversations
//DpConversations *models.DpConversations
WorldConversations
*
models
.
WorldConversation
WorldConversations
*
models
.
WorldConversation
Socket
*
websocket
.
Conn
Socket
*
websocket
.
Conn
Send
chan
*
WorldEchoRespon
es
Send
chan
*
WorldEchoRespon
se
WorldName
string
WorldName
string
AuthId
string
AuthId
string
UserSource
string
UserSource
string
...
@@ -989,7 +989,7 @@ func (c *WorldClient) WorldRead() {
...
@@ -989,7 +989,7 @@ func (c *WorldClient) WorldRead() {
// ExtractRating 从响应中提取整体评分
// ExtractRating 从响应中提取整体评分
func
ExtractRating
(
response
WorldEchoRespon
es
)
(
int
,
error
)
{
func
ExtractRating
(
response
WorldEchoRespon
se
)
(
int
,
error
)
{
endStr
,
ok
:=
response
.
WObj
[
"EndStr"
]
.
(
string
)
endStr
,
ok
:=
response
.
WObj
[
"EndStr"
]
.
(
string
)
if
!
ok
||
endStr
==
""
{
if
!
ok
||
endStr
==
""
{
return
0
,
nil
return
0
,
nil
...
@@ -1009,7 +1009,7 @@ func ExtractRating(response WorldEchoRespones) (int, error) {
...
@@ -1009,7 +1009,7 @@ func ExtractRating(response WorldEchoRespones) (int, error) {
return
0
,
fmt
.
Errorf
(
"未找到评分信息"
)
return
0
,
fmt
.
Errorf
(
"未找到评分信息"
)
}
}
func
ExtractRating1
(
response
WorldEchoRespon
es
)
string
{
func
ExtractRating1
(
response
WorldEchoRespon
se
)
string
{
endStr
,
ok
:=
response
.
WObj
[
"EndStr"
]
.
(
string
)
endStr
,
ok
:=
response
.
WObj
[
"EndStr"
]
.
(
string
)
if
!
ok
{
if
!
ok
{
...
@@ -1165,3 +1165,160 @@ func (c *WorldClient) WorldWrite() {
...
@@ -1165,3 +1165,160 @@ func (c *WorldClient) WorldWrite() {
}
}
/* ============================================================================================= */
/* ============================================================================================= */
// ParseEndStrAndReformat 重新结构化 WorldEchoRespones,以包含结论消息的详细拆分
func
ParseEndStrAndReformat1
(
response
*
WorldEchoResponse
)
{
if
response
==
nil
||
response
.
WObj
==
nil
{
return
}
endStr
,
ok
:=
response
.
WObj
[
"EndStr"
]
.
(
string
)
if
!
ok
||
endStr
==
""
{
return
}
// 解析 "EndStr" 中的详细字段
title
:=
strings
.
Split
(
endStr
,
"@"
)[
0
]
// 提取 '@' 前的标题
overallScore
:=
extractBetween
(
endStr
,
"【整体评分】:"
,
"
\n
"
)
// 提取整体评分
objectiveEvaluation
:=
extractBetween
(
endStr
,
"【客观评价】:"
,
"**言行举止**"
)
// 提取客观评价
// 将 "EndStr" 结构化为 JSON 对象
endStrObj
:=
map
[
string
]
interface
{}{
"title"
:
title
,
"OverallScore"
:
strings
.
TrimSpace
(
overallScore
),
"ObjectiveEvaluation"
:
strings
.
TrimSpace
(
objectiveEvaluation
),
}
response
.
WObj
[
"EndStr"
]
=
endStrObj
// 将格式化后的结论字符串对象重新赋值给响应
// 可选处理其他字段如 '地点' 和 '表情'
if
address
,
exists
:=
response
.
WObj
[
"地点"
];
exists
{
response
.
WObj
[
"address"
]
=
address
delete
(
response
.
WObj
,
"地点"
)
}
if
emotion
,
exists
:=
response
.
WObj
[
"表情"
];
exists
{
response
.
WObj
[
"emotion"
]
=
emotion
delete
(
response
.
WObj
,
"表情"
)
}
}
// ParseEndStrAndReformat 将 WorldSoulReplyMsg 中的 WObj 修改后返回一个新的 WorldSoulReplyMsg 结构体
func
ParseEndStrAndReformat2
(
response
*
WorldSoulReplyMsg
)
*
WorldSoulReplyMsg
{
if
response
==
nil
||
response
.
WObj
==
nil
{
return
nil
// 如果输入是nil,直接返回nil
}
newResponse
:=
*
response
// 创建一个新的响应副本以避免修改原始数据
endStr
,
ok
:=
newResponse
.
WObj
[
"EndStr"
]
.
(
string
)
if
!
ok
||
endStr
==
""
{
return
&
newResponse
// 如果没有 EndStr 或者为空,返回原始数据的副本
}
// 解析 "EndStr" 中的详细字段
title
:=
strings
.
Split
(
endStr
,
"@"
)[
0
]
// 提取 '@' 前的标题
overallScore
:=
extractBetween
(
endStr
,
"【整体评分】:"
,
"
\n
"
)
// 提取整体评分
objectiveEvaluation
:=
extractToEnd
(
endStr
,
"【客观评价】:"
)
// 提取客观评价
// 将 "EndStr" 结构化为 JSON 对象
endStrObj
:=
map
[
string
]
interface
{}{
"title"
:
title
,
"OverallScore"
:
strings
.
TrimSpace
(
overallScore
),
"ObjectiveEvaluation"
:
strings
.
TrimSpace
(
objectiveEvaluation
),
}
newResponse
.
WObj
[
"EndStr"
]
=
endStrObj
// 将格式化后的结论字符串对象重新赋值给响应
// 可选处理其他字段如 '地点' 和 '表情'
if
address
,
exists
:=
newResponse
.
WObj
[
"地点"
];
exists
{
newResponse
.
WObj
[
"address"
]
=
address
delete
(
newResponse
.
WObj
,
"地点"
)
}
if
emotion
,
exists
:=
newResponse
.
WObj
[
"表情"
];
exists
{
newResponse
.
WObj
[
"emotion"
]
=
emotion
delete
(
newResponse
.
WObj
,
"表情"
)
}
return
&
newResponse
// 返回修改后的新响应体
}
func
ParseEndStrAndReformat3
(
response
*
WorldSoulReplyMsg
)
*
WorldSoulReplyMsg
{
if
response
==
nil
||
response
.
WObj
==
nil
{
return
nil
// If the input is nil, return nil
}
newResponse
:=
*
response
// Create a copy of the response to modify
// Determine the message type based on the presence of specific keywords or structures
if
len
(
newResponse
.
WObj
)
==
0
&&
strings
.
Contains
(
newResponse
.
ISLIU
,
"【任务提示】"
)
{
newResponse
.
MessageStatusType
=
"开场白"
}
else
if
endStr
,
ok
:=
newResponse
.
WObj
[
"EndStr"
]
.
(
string
);
ok
&&
endStr
!=
""
{
newResponse
.
MessageStatusType
=
"结局"
}
else
{
newResponse
.
MessageStatusType
=
"会话中消息"
}
// Further reformatting based on the presence of "EndStr"
if
endStr
,
ok
:=
newResponse
.
WObj
[
"EndStr"
]
.
(
string
);
ok
{
if
endStr
!=
""
{
// Parse details from "EndStr"
title
:=
strings
.
Split
(
endStr
,
"@"
)[
0
]
overallScore
:=
extractBetween
(
endStr
,
"【整体评分】:"
,
"
\n
"
)
objectiveEvaluation
:=
extractToEnd
(
endStr
,
"【客观评价】:"
)
// Structurize "EndStr" into a JSON object
endStrObj
:=
map
[
string
]
interface
{}{
"title"
:
title
,
"overallScore"
:
strings
.
TrimSpace
(
overallScore
),
"objectiveEvaluation"
:
strings
.
TrimSpace
(
objectiveEvaluation
),
}
newResponse
.
WObj
[
"EndStr"
]
=
endStrObj
// Assign the reformatted conclusion string object back to the response
}
}
// Handle additional fields such as '地点' and '表情'
if
address
,
exists
:=
newResponse
.
WObj
[
"地点"
];
exists
{
newResponse
.
WObj
[
"address"
]
=
address
delete
(
newResponse
.
WObj
,
"地点"
)
}
if
emotion
,
exists
:=
newResponse
.
WObj
[
"表情"
];
exists
{
newResponse
.
WObj
[
"emotion"
]
=
emotion
delete
(
newResponse
.
WObj
,
"表情"
)
}
return
&
newResponse
// Return the modified response
}
// 使用例
func
ExampleSend
()
{
IsLiu_Id
:=
"d018fd63c598f4a13e31f7f8faf0ac15"
originalMsg
:=
WorldSoulReplyMsg
{
Code
:
1
,
WObj
:
map
[
string
]
interface
{}{
"EndStr"
:
"确定下单@
\n
## 【整体评分】: 90
\n\n
## 【客观评价】:
\n\n
这位业务经理在与客户沟通的过程中展现出了良好的专业素养和沟通技巧。他能清晰地介绍产品,并针对客户提出的问题和疑虑进行耐心解答,并根据客户的需求进行灵活调整,最终促成了交易。
\n\n
**言行举止**: 业务经理在与客户沟通的过程中保持着礼貌和专业的态度,没有出现任何不当言行。
\n\n
**优势**: 业务经理对产品知识掌握熟练,能够根据客户的需求进行灵活的方案调整,并展现出一定的谈判技巧,最终促成了交易。
\n\n
**不足与建议**: 在价格方面,业务经理可以尝试更早地了解客户的心理价位,以便制定更有针对性的报价策略。此外,在介绍产品时,可以更加突出云电脑相比传统电脑的优势,例如节省维护成本、方便升级等。
\n
"
,
"地点"
:
"老板办公室"
,
"表情"
:
"满意"
},
ISLIU
:
"Some text"
,
WorldName
:
"Example World"
,
IsLIUId
:
&
IsLiu_Id
,
}
// 转换消息
transformedMsg
:=
ParseEndStrAndReformat
(
&
originalMsg
)
// 序列化消息为JSON
jsonMsg
,
err
:=
json
.
Marshal
(
transformedMsg
)
if
err
!=
nil
{
log
.
Printf
(
"JSON编码失败: %v"
,
err
)
return
}
// 发送消息
//err = c.Socket.WriteMessage(websocket.TextMessage, jsonMsg)
//if err != nil {
// log.Println("发送WebSocket消息失败: ", err)
// WorldDestroyWs(c) // 关闭WebSocket连接
//}
fmt
.
Println
(
"jsonMsg ==> "
,
string
(
jsonMsg
))
}
src/service/WorldChat.go_bak
→
src/service/WorldChat
_HighConcurrency
.go_bak
View file @
53068b6a
This diff is collapsed.
Click to expand it.
src/service/WorldEchoAPIService.go
View file @
53068b6a
...
@@ -14,12 +14,14 @@ import (
...
@@ -14,12 +14,14 @@ import (
)
)
//创建世界API接口时候返回的响应体
//创建世界API接口时候返回的响应体
type
WorldEchoRespones
struct
{
type
WorldEchoResponse
struct
{
Code
int
`from:"code" json:"code"`
Code
int
`from:"code" json:"code"`
WObj
map
[
string
]
interface
{}
`json:"WObj"`
WObj
map
[
string
]
interface
{}
`json:"WObj"`
ISLIU
string
`from:"ISLIU" json:"ISLIU"`
ISLIU
string
`from:"ISLIU" json:"ISLIU"`
MuseValue
int
`json:"muse"`
MuseValue
int
`json:"muse"`
WorldName
string
`json:"worldName" `
WorldName
string
`json:"worldName" `
IsLIUId
*
string
`json:"IsLIUId,omitempty"`
// 使用指针类型,并添加 omitempty 标签,可选字段
MessageStatusType
string
`json:"messageStatusType,omitempty"`
// Optional field to indicate message type
}
}
//世界推演结局
//世界推演结局
...
@@ -29,7 +31,7 @@ type OutcomeContent struct {
...
@@ -29,7 +31,7 @@ type OutcomeContent struct {
}
}
// WorldClient
// WorldClient
func
(
client
*
WorldClient
)
WorldEchoAPI
(
msg
*
WorldSendMsg
)
(
*
WorldEchoRespon
es
,
error
)
{
func
(
client
*
WorldClient
)
WorldEchoAPI
(
msg
*
WorldSendMsg
)
(
*
WorldEchoRespon
se
,
error
)
{
/*
/*
创建一个请求参数对象
创建一个请求参数对象
*/
*/
...
@@ -70,7 +72,7 @@ func (client *WorldClient) WorldEchoAPI(msg *WorldSendMsg) (*WorldEchoRespones,
...
@@ -70,7 +72,7 @@ func (client *WorldClient) WorldEchoAPI(msg *WorldSendMsg) (*WorldEchoRespones,
return
nil
,
err
return
nil
,
err
}
}
// 解析JSON
// 解析JSON
var
response
WorldEchoRespon
es
var
response
WorldEchoRespon
se
err
=
json
.
Unmarshal
(
body
,
&
response
)
err
=
json
.
Unmarshal
(
body
,
&
response
)
// 将JSON打印为字符串
// 将JSON打印为字符串
...
@@ -135,7 +137,7 @@ func (client *WorldClient) WorldEchoAPI(msg *WorldSendMsg) (*WorldEchoRespones,
...
@@ -135,7 +137,7 @@ func (client *WorldClient) WorldEchoAPI(msg *WorldSendMsg) (*WorldEchoRespones,
}
}
func
AddWorldEchoEndStrRecord
(
worldId
,
userId
int64
,
response
*
WorldEchoRespon
es
)
{
func
AddWorldEchoEndStrRecord
(
worldId
,
userId
int64
,
response
*
WorldEchoRespon
se
)
{
// 检查是否存在结束标记 "EndStr"
// 检查是否存在结束标记 "EndStr"
if
endStr
,
ok
:=
response
.
WObj
[
"EndStr"
];
ok
{
if
endStr
,
ok
:=
response
.
WObj
[
"EndStr"
];
ok
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment