260603更新
This commit is contained in:
parent
48e08eebb8
commit
4912303991
|
|
@ -10,7 +10,6 @@ from typing import List, Optional, Union, cast
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from mistralai.client.models import Op
|
|
||||||
from pydantic_ai import Agent as BaseAgent, AgentRunResult
|
from pydantic_ai import Agent as BaseAgent, AgentRunResult
|
||||||
from pydantic_ai.capabilities import AgentCapability
|
from pydantic_ai.capabilities import AgentCapability
|
||||||
from pydantic_ai.models.openai import OpenAIChatModel
|
from pydantic_ai.models.openai import OpenAIChatModel
|
||||||
|
|
@ -141,7 +140,7 @@ class Agent:
|
||||||
from pydantic_ai.ui.vercel_ai import VercelAIAdapter
|
from pydantic_ai.ui.vercel_ai import VercelAIAdapter
|
||||||
from pydantic_ai.capabilities import NativeTool
|
from pydantic_ai.capabilities import NativeTool
|
||||||
|
|
||||||
async def options(request: Request) -> Response:
|
async def chat_options(request: Request) -> Response:
|
||||||
"""处理跨域预检请求"""
|
"""处理跨域预检请求"""
|
||||||
return Response()
|
return Response()
|
||||||
|
|
||||||
|
|
@ -179,7 +178,7 @@ class Agent:
|
||||||
)
|
)
|
||||||
return JSONResponse(content=configurations.model_dump(by_alias=True))
|
return JSONResponse(content=configurations.model_dump(by_alias=True))
|
||||||
|
|
||||||
async def chat(request: Request) -> Response:
|
async def chat_post(request: Request) -> Response:
|
||||||
"""处理对话请求"""
|
"""处理对话请求"""
|
||||||
# 实例 Vercel AI 适配器
|
# 实例 Vercel AI 适配器
|
||||||
adapter = await VercelAIAdapter[
|
adapter = await VercelAIAdapter[
|
||||||
|
|
@ -216,10 +215,10 @@ class Agent:
|
||||||
|
|
||||||
return Starlette(
|
return Starlette(
|
||||||
routes=[
|
routes=[
|
||||||
Route("/chat", options, methods=["OPTIONS"]),
|
Route(path="/chat", endpoint=chat_options, methods=["OPTIONS"]),
|
||||||
Route("/configure", configurations, methods=["GET"]),
|
Route(path="/configure", endpoint=configurations, methods=["GET"]),
|
||||||
Route("/chat", chat, methods=["POST"]),
|
Route(path="/chat", endpoint=chat_post, methods=["POST"]),
|
||||||
Route("/health", health, methods=["GET"]),
|
Route(path="/health", endpoint=health, methods=["GET"]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -244,7 +243,7 @@ class Agent:
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
application.router.add_route("/", index, methods=["GET"])
|
application.router.add_route(path="/", endpoint=index, methods=["GET"])
|
||||||
application.router.add_route("/{id}", index, methods=["GET"])
|
application.router.add_route(path="/{id}", endpoint=index, methods=["GET"])
|
||||||
|
|
||||||
return application
|
return application
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ from base64 import b64decode, b64encode
|
||||||
from json import dumps, loads
|
from json import dumps, loads
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from secrets import token_bytes
|
from secrets import token_bytes
|
||||||
|
import sys
|
||||||
from time import time_ns
|
from time import time_ns
|
||||||
from typing import cast
|
from typing import cast
|
||||||
from typing import Any, Dict, Literal, Optional, Tuple
|
from typing import Any, Dict, Literal, Optional, Tuple
|
||||||
|
|
@ -21,10 +22,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
||||||
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append(Path(__file__).parent.parent.as_posix())
|
sys.path.append(Path(__file__).parent.parent.as_posix())
|
||||||
|
|
||||||
from utils.request import Request
|
from utils.request import Request
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -222,21 +220,24 @@ if __name__ == "__main__":
|
||||||
# 实例加密器
|
# 实例加密器
|
||||||
encryptor = Encryptor()
|
encryptor = Encryptor()
|
||||||
|
|
||||||
|
# 杭州汤然请求同步响应
|
||||||
|
# https://risk-gw.pangjukeji.com/api/v1/riskgateway/product/invokeSync.json
|
||||||
|
# 杭州汤然请求异步响应(创建任务)
|
||||||
|
# https://risk-gw.pangjukeji.com/api/v1/riskgateway/product/submitAsyncTask.json
|
||||||
|
# 杭州汤然请求异步响应(查询任务)
|
||||||
|
# https://risk-gw.pangjukeji.com/api/v1/riskgateway/result/queryAsyncResult.json
|
||||||
# 实例请求客户端
|
# 实例请求客户端
|
||||||
request = Request() # 不使用缓存
|
request = Request() # 不使用缓存
|
||||||
response = request.post(
|
response = request.post(
|
||||||
url="https://risk-gw.pangjukeji.com/api/v1/riskgateway/product/invokeSync.json",
|
url="https://risk-gw.pangjukeji.com/api/v1/riskgateway/result/queryAsyncResult.json",
|
||||||
headers={
|
headers={
|
||||||
"Authorization": "Bearer 337162980141699072",
|
"Authorization": "Bearer 337162980141699072",
|
||||||
"Content-Type": "application/json;charset=utf-8",
|
"Content-Type": "application/json;charset=utf-8",
|
||||||
},
|
},
|
||||||
json=encryptor.encrypt(
|
json=encryptor.encrypt(
|
||||||
payload={
|
payload={
|
||||||
"productId": "BANK_CARD_4",
|
"productId": "CAR_ACCIDENT_DETAIL",
|
||||||
"name": "刘弼仁",
|
"recordId": "337471805314961408",
|
||||||
"certNo": "131002198705024619",
|
|
||||||
"mobilephone": "18058798752",
|
|
||||||
"bankCardNo": "6214835712066453",
|
|
||||||
},
|
},
|
||||||
fields_mapping={
|
fields_mapping={
|
||||||
"aes_key_encoded": "encryptedAesKey",
|
"aes_key_encoded": "encryptedAesKey",
|
||||||
|
|
@ -267,8 +268,27 @@ if __name__ == "__main__":
|
||||||
"certNo": "131002196212124620"
|
"certNo": "131002196212124620"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
"productId": "BANK_CARD_4",
|
||||||
|
"name": "刘弼仁",
|
||||||
|
"certNo": "131002198705024619",
|
||||||
|
"mobilephone": "18058798752",
|
||||||
|
"bankCardNo": "6228480328744527172",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"productId": "SOCIAL_CAPACITY",
|
||||||
|
"name": "刘弼仁",
|
||||||
|
"certNo": "131002198705024619",
|
||||||
|
"mobilephone": "18058798752",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"productId": "CREDIT_RISK_PRE_SCREEN",
|
||||||
|
"mobilephone": "13833652939",
|
||||||
|
"certNo": "131002196212124620"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"productId": "CAR_ACCIDENT_DETAIL",
|
||||||
|
"vin": "L6T7712Z2GN076782",
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue