Toggle navigation
Toggle navigation
This project
Loading...
Sign in
zhouhui.jiang
/
Test_LangGraph
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
zhouhui.jiang
2025-11-15 13:28:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c315e53ac3d79f1a98ac6c13fe06af1c6b7cd700
c315e53a
1 parent
5a8f3de7
update
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
1 deletions
API/api_config.py
API/paperless_api.py
API/waybill_api.py
langgraph_examples/api_agent.py
API/api_config.py
View file @
c315e53
...
...
@@ -13,7 +13,7 @@ API_CONFIG = {
"headers"
:
{
"accept"
:
"*/*"
,
"Content-Type"
:
"application/json"
,
"Authorization"
:
os
.
getenv
(
"API_AUTHORIZATION"
,
"Bearer 2.
21e3deecca904c7697ab891b8276cf3
6"
),
"Authorization"
:
os
.
getenv
(
"API_AUTHORIZATION"
,
"Bearer 2.
bd593d8f36c4468fbf02ee95c473cbb
6"
),
"Ver"
:
os
.
getenv
(
"API_VER"
,
"033BD94B1168D7E4F0D644C3C95E35BF.D73E33B659AD1D6B7D181D1DF8D05760"
),
"Referer"
:
os
.
getenv
(
"API_REFERER"
,
"http://192.168.1.251/"
)
}
...
...
API/paperless_api.py
View file @
c315e53
...
...
@@ -103,3 +103,79 @@ def upload_clearance_file(
return
f
"上传清关文件失败: {str(e)}"
def
upload_file_for_ocr
(
pdf_path
:
str
,
Authorization
:
Optional
[
str
]
=
None
,
)
->
str
:
"""上传文件进行OCR识别
Args:
pdf_path: 本地 PDF 文件路径(必填)
Authorization: 授权令牌,如果提供则使用该值,否则使用 API_CONFIG 中的默认值
Returns:
文本:成功/失败信息
"""
if
not
os
.
path
.
isfile
(
pdf_path
):
return
f
"参数错误: 文件不存在 - {pdf_path}"
# 从文件路径提取文件名
file_name
=
os
.
path
.
basename
(
pdf_path
)
# 构建URL(不包含查询参数)
url
=
f
"{API_CONFIG['base_url']}/API/ocrDemo/pushDemo"
# 封装参数到 params_payload
params_payload
=
{
"fileName01"
:
file_name
,
"fileNumber"
:
1
}
# form-data: params 是 JSON 字符串,fileUpload 是文件
data
=
{
"params"
:
json
.
dumps
(
params_payload
,
ensure_ascii
=
False
),
}
files
=
{
"file"
:
(
file_name
,
open
(
pdf_path
,
"rb"
),
"application/pdf"
),
}
# 构建 headers,优先使用传入的 Authorization
headers
=
dict
(
API_CONFIG
.
get
(
"headers"
,
{}))
if
Authorization
:
headers
[
'Authorization'
]
=
Authorization
# 移除 Content-Type(由 requests 根据 multipart 自动设置)
headers
.
pop
(
"Content-Type"
,
None
)
try
:
resp
=
requests
.
post
(
url
,
headers
=
headers
,
data
=
data
,
files
=
files
,
timeout
=
60
)
# 确保文件句柄尽快关闭
try
:
files
[
"file"
][
1
]
.
close
()
except
Exception
:
pass
if
resp
.
status_code
==
200
:
# 解析响应JSON
result
=
resp
.
json
()
# 提取指定字段,只返回 status、message、chmCode、chmId
filtered_result
=
{}
if
"status"
in
result
:
filtered_result
[
"status"
]
=
result
[
"status"
]
if
"message"
in
result
:
filtered_result
[
"message"
]
=
result
[
"message"
]
if
"chmCode"
in
result
:
filtered_result
[
"chmCode"
]
=
result
[
"chmCode"
]
if
"chmId"
in
result
:
filtered_result
[
"chmId"
]
=
result
[
"chmId"
]
# 返回过滤后的JSON字符串
return
json
.
dumps
(
filtered_result
,
ensure_ascii
=
False
)
return
f
"上传失败: HTTP {resp.status_code}, 错误信息: {resp.text}"
except
requests
.
exceptions
.
RequestException
as
e
:
return
f
"网络请求失败: {str(e)}"
except
Exception
as
e
:
return
f
"上传文件进行OCR识别失败: {str(e)}"
...
...
API/waybill_api.py
View file @
c315e53
...
...
@@ -133,6 +133,70 @@ def create_waybill_d(consignmentCode: str, Authorization: str = None) -> str:
return
f
"❌ 创建D类运单失败: {str(e)}"
def
create_waybill_d_with_id
(
consignmentCode
:
str
,
consignmentId
:
str
,
loginName
:
str
,
userId
:
int
,
Authorization
:
str
=
None
,
)
->
str
:
"""根据运单ID及运单号创建D类运单
Args:
consignmentCode: 运单号(必填)
consignmentId: 运单ID(必填)
loginName: 登录名(必填)
userId: 用户ID(必填)
Authorization: 授权令牌,如果提供则使用该值,否则使用 API_CONFIG 中的默认值
Returns:
创建结果,成功时返回序列化的JSON,失败时返回错误信息
"""
try
:
url
=
f
"{API_CONFIG['base_url']}/Exp/bus-customer/consignment/createChmConsignmentD/demo"
# 构建请求数据
data
=
{
"consignmentCode"
:
consignmentCode
,
"consignmentId"
:
consignmentId
,
"isAIRecognition"
:
1
,
# 写死为1
"loginName"
:
loginName
,
"userId"
:
userId
}
# 构建 headers,优先使用传入的 Authorization
headers
=
dict
(
API_CONFIG
[
'headers'
])
if
Authorization
:
headers
[
'Authorization'
]
=
Authorization
# 发送POST请求
response
=
requests
.
post
(
url
,
headers
=
headers
,
json
=
data
,
timeout
=
30
)
# 检查响应状态
if
response
.
status_code
==
200
:
result
=
response
.
json
()
# 提取运单ID
data
=
result
.
get
(
'data'
)
or
{}
extra
=
data
.
get
(
'extra'
)
or
{}
waybill_id
=
extra
.
get
(
'id'
)
if
waybill_id
is
not
None
:
return
waybill_id
# 返回数字格式的运单ID
return
f
"❌ 创建失败: 响应中未找到运单ID"
return
f
"❌ 创建失败: HTTP {response.status_code}, 错误信息: {response.text}"
except
requests
.
exceptions
.
RequestException
as
e
:
return
f
"❌ 网络请求失败: {str(e)}"
except
json
.
JSONDecodeError
as
e
:
return
f
"❌ 响应解析失败: {str(e)}"
except
Exception
as
e
:
return
f
"❌ 创建D类运单失败: {str(e)}"
def
query_waybill_info
(
consignmentCode
:
str
,
Authorization
:
str
=
None
)
->
str
:
"""根据运单编号查询运单信息
...
...
langgraph_examples/api_agent.py
View file @
c315e53
This diff is collapsed. Click to expand it.
Please
register
or
login
to post a comment