Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
LAE
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
文靖昊
LAE
Commits
b38bc992
Commit
b38bc992
authored
4 months ago
by
文靖昊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
地区编码工具bug修复
parent
afda82ab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
31 deletions
+42
-31
code.py
src/agent/code.py
+33
-29
tool_rate.py
src/agent/tool_rate.py
+8
-1
agent_rate.py
src/server/agent_rate.py
+1
-1
No files found.
src/agent/code.py
View file @
b38bc992
...
...
@@ -23,15 +23,18 @@ class AreaCodeTool:
self
.
_build_name_maps
()
def
_build_name_maps
(
self
):
"""构建区域名称到代码的映射"""
"""
构建区域名称到代码的映射
目前读取excel表格就能获取省市县的映射,也可能市省、省市的映射
我们可以直接以省过滤,就能得到市级、市县的映射、
再根据市级过滤、得到县级映射
"""
self
.
full_name_map
=
dict
(
zip
(
self
.
df
[
'name'
],
self
.
df
[
'code'
]))
# 构建省级映射
self
.
province_map
=
{}
# 构建市级映射
self
.
city_map
=
{}
# 构建区县级映射
self
.
district_map
=
{}
# 构建二级映射
self
.
second_map
=
{}
# 构建三级映射
self
.
third_map
=
{}
for
_
,
row
in
self
.
df
.
iterrows
():
name
=
row
[
'name'
]
.
strip
()
...
...
@@ -39,22 +42,25 @@ class AreaCodeTool:
parts
=
name
.
split
(
'省'
if
'省'
in
name
else
'市'
)
if
'省'
in
name
:
province
=
parts
[
0
]
+
'省'
self
.
province_map
[
province
]
=
code
if
len
(
parts
)
>
1
and
parts
[
1
]:
city_parts
=
parts
[
1
]
.
split
(
'市'
)
if
city_parts
[
0
]:
city
=
city_parts
[
0
]
+
'市'
self
.
city_map
[
city
]
=
code
self
.
second_map
[
parts
[
1
]]
=
code
#考虑直辖县的情况
if
'市'
in
name
:
city_parts
=
parts
[
1
]
.
split
(
'市'
)
if
len
(
city_parts
)
>
1
and
city_parts
[
1
]:
district
=
city_parts
[
1
]
self
.
third_map
[
district
]
=
code
if
'自治州'
in
name
:
city_parts
=
parts
[
1
]
.
split
(
'自治州'
)
if
len
(
city_parts
)
>
1
and
city_parts
[
1
]:
district
=
city_parts
[
1
]
self
.
district_map
[
district
]
=
code
self
.
third_map
[
district
]
=
code
else
:
# 处理直辖市等特殊情况
if
parts
[
0
]:
self
.
city_map
[
parts
[
0
]
+
'市'
]
=
code
if
len
(
parts
)
>
1
and
parts
[
1
]:
self
.
third_map
[
parts
[
1
]]
=
code
def
find_code
(
self
,
area_name
:
str
)
->
List
[
Tuple
[
str
,
str
]]:
"""
...
...
@@ -72,18 +78,16 @@ class AreaCodeTool:
if
area_name
in
self
.
full_name_map
:
results
.
append
((
area_name
,
self
.
full_name_map
[
area_name
]))
return
results
# 尝试省级匹配
if
area_name
.
endswith
(
'省'
)
and
area_name
in
self
.
province_map
:
results
.
append
((
area_name
,
self
.
province_map
[
area_name
]))
# 尝试市级匹配
if
area_name
.
endswith
(
'市'
)
and
area_name
in
self
.
city_map
:
results
.
append
((
area_name
,
self
.
city_map
[
area_name
]))
# 尝试二级匹配
if
area_name
.
endswith
(
'市'
)
and
area_name
in
self
.
second_map
:
results
.
append
((
area_name
,
self
.
second_map
[
area_name
]))
return
results
# 尝试区县级匹配
if
area_name
in
self
.
district_map
:
results
.
append
((
area_name
,
self
.
district_map
[
area_name
]))
# 尝试三级级匹配
if
area_name
in
self
.
third_map
:
results
.
append
((
area_name
,
self
.
third_map
[
area_name
]))
return
results
# 模糊匹配
if
not
results
:
...
...
This diff is collapsed.
Click to expand it.
src/agent/tool_rate.py
View file @
b38bc992
import
time
from
typing
import
Dict
,
List
,
Tuple
,
Any
,
Optional
from
pydantic
import
BaseModel
,
Field
from
typing
import
Type
...
...
@@ -78,6 +79,7 @@ class RegionRateTool(BaseRateTool):
def
get_region_online_rate
(
self
,
start_time
:
str
,
end_time
:
str
,
region_name
:
str
=
""
)
->
Dict
[
str
,
Any
]:
# 查询数据
agent_start
=
time
.
time
()
print
(
f
"查询地区在线率: {region_name}, 时间范围: {start_time} 至 {end_time}"
)
code
=
""
if
region_name
!=
""
:
...
...
@@ -88,7 +90,11 @@ class RegionRateTool(BaseRateTool):
'message'
:
f
'未找到匹配的区域代码: {region_name}'
}
code
=
codes
[
0
][
1
]
print
(
code
)
start
=
time
.
time
()
df
=
self
.
client
.
query_rates_sync
(
code
,
start_time
,
end_time
)
end
=
time
.
time
()
print
(
f
"query_rates_sync client spent time:{end-start}"
)
print
(
f
"地区在线率接口调用结果: {df}"
)
# 准备数据
if
df
.
type
!=
1
or
len
(
df
.
resultdata
)
==
0
:
...
...
@@ -106,7 +112,8 @@ class RegionRateTool(BaseRateTool):
'end'
:
end_time
}
}
end
=
time
.
time
()
print
(
f
"once agent spent time:{end - agent_start}"
)
return
data
class
RankingRateArgs
(
BaseModel
):
...
...
This diff is collapsed.
Click to expand it.
src/server/agent_rate.py
View file @
b38bc992
...
...
@@ -139,7 +139,7 @@ class RateAgentV2:
agent
=
create_structured_chat_agent
(
llm
,
tools
,
prompt
)
self
.
agent_executor
=
AgentExecutor
(
agent
=
agent
,
tools
=
tools
,
verbose
=
verbose
,
return_intermediate_steps
=
True
)
self
.
agent_executor
=
AgentExecutor
(
agent
=
agent
,
tools
=
tools
,
verbose
=
verbose
,
return_intermediate_steps
=
True
,
handle_parsing_errors
=
True
)
def
exec
(
self
,
prompt_args
:
dict
=
{},
stream
:
bool
=
False
):
return
self
.
agent_executor
.
invoke
(
input
=
prompt_args
)
...
...
This diff is collapsed.
Click to expand it.
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