feat(agent): add input variable validation

This commit is contained in:
Eternity
2026-03-05 11:17:56 +08:00
parent 0d8f4c76e7
commit 16c1cbe24f
13 changed files with 330 additions and 882 deletions

View File

@@ -9,6 +9,8 @@ load_dotenv()
# 读取web_search环境变量
web_search_value = os.getenv('web_search')
def Search(query):
url = "https://qianfan.baidubce.com/v2/ai_search/chat/completions"
api_key = web_search_value
@@ -18,23 +20,24 @@ def Search(query):
"role": "user",
"content": query
}
], #搜索输入
"edition":"standard", #搜索版本。默认为standard。可选值standard完整版本。lite标准版本对召回规模和精排条数简化后的版本时延表现更好效果略弱于完整版。
"search_source": "baidu_search_v2", #使用的搜索引擎版本
"resource_type_filter": [{"type": "web","top_k": 20}], #支持设置网页、视频、图片、阿拉丁搜索模态网页top_k最大取值为50视频top_k最大为10图片top_k最大为30阿拉丁top_k最大为5
], # 搜索输入
"edition": "standard", # 搜索版本。默认为standard。可选值standard完整版本。lite标准版本对召回规模和精排条数简化后的版本时延表现更好效果略弱于完整版。
"search_source": "baidu_search_v2", # 使用的搜索引擎版本
"resource_type_filter": [{"type": "web", "top_k": 20}],
# 支持设置网页、视频、图片、阿拉丁搜索模态网页top_k最大取值为50视频top_k最大为10图片top_k最大为30阿拉丁top_k最大为5
"search_filter": {
"range": {
"page_time": {
"gte": "now-1w/d", #时间查询参数,大于或等于
"lt": "now/d", #时间查询参数,小于
"gt": "", #时间查询参数,大于
"lte": "" #时间查询参数,小于或等于
"gte": "now-1w/d", # 时间查询参数,大于或等于
"lt": "now/d", # 时间查询参数,小于
"gt": "", # 时间查询参数,大于
"lte": "" # 时间查询参数,小于或等于
}
}
},
"block_websites":["tieba.baidu.com"], #需要屏蔽的站点列表
"search_recency_filter":"week", #根据网页发布时间进行筛选可填值为week,month,semiyear,year
"enable_full_content":True #是否输出网页完整原文
"block_websites": ["tieba.baidu.com"], # 需要屏蔽的站点列表
"search_recency_filter": "week", # 根据网页发布时间进行筛选可填值为week,month,semiyear,year
"enable_full_content": True # 是否输出网页完整原文
}, ensure_ascii=False)
headers = {
'Content-Type': 'application/json',
@@ -42,10 +45,10 @@ def Search(query):
}
response = requests.request("POST", url, headers=headers, data=payload.encode("utf-8")).json()
content=[]
content = []
for i in response['references']:
title=i['title']
snippet=i['snippet']
content.append(title+';'+snippet)
content=''.join(content)
return content
title = i['title']
snippet = i['snippet']
content.append(title + ';' + snippet)
content = ''.join(content)
return content