Spaces:
Build error
Build error
| # Copyright 2025 Google LLC | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| import argparse | |
| import os | |
| from agent import BrowserAgent | |
| from computers import BrowserbaseComputer, PlaywrightComputer | |
| PLAYWRIGHT_SCREEN_SIZE = (1440, 900) | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description="Run the browser agent with a query.") | |
| parser.add_argument( | |
| "--query", | |
| type=str, | |
| required=True, | |
| help="The query for the browser agent to execute.", | |
| ) | |
| parser.add_argument( | |
| "--env", | |
| type=str, | |
| choices=("playwright", "browserbase"), | |
| default="playwright", | |
| help="The computer use environment to use.", | |
| ) | |
| parser.add_argument( | |
| "--initial_url", | |
| type=str, | |
| default="https://www.google.com", | |
| help="The inital URL loaded for the computer.", | |
| ) | |
| parser.add_argument( | |
| "--highlight_mouse", | |
| action="store_true", | |
| default=False, | |
| help="If possible, highlight the location of the mouse.", | |
| ) | |
| parser.add_argument( | |
| "--model", | |
| default='gemini-2.5-computer-use-preview-10-2025', | |
| help="Set which main model to use.", | |
| ) | |
| args = parser.parse_args() | |
| if args.env == "playwright": | |
| env = PlaywrightComputer( | |
| screen_size=PLAYWRIGHT_SCREEN_SIZE, | |
| initial_url=args.initial_url, | |
| highlight_mouse=args.highlight_mouse, | |
| ) | |
| elif args.env == "browserbase": | |
| env = BrowserbaseComputer( | |
| screen_size=PLAYWRIGHT_SCREEN_SIZE, | |
| initial_url=args.initial_url | |
| ) | |
| else: | |
| raise ValueError("Unknown environment: ", args.env) | |
| with env as browser_computer: | |
| agent = BrowserAgent( | |
| browser_computer=browser_computer, | |
| query=args.query, | |
| model_name=args.model, | |
| ) | |
| agent.agent_loop() | |
| return 0 | |
| def run_genflow(): | |
| env = PlaywrightComputer( | |
| screen_size=PLAYWRIGHT_SCREEN_SIZE, | |
| initial_url="https://wenku.baidu.com/ndcore/browse/aiunion?fr=options_AIcard_1&_wkts_=1761290807747&bdQuery=genflow&t=1761290807744&tabType=genflow&aiCreat=genflow", | |
| # initial_url="https://www.doubao.com/chat/", | |
| highlight_mouse=True, # 如果指定,代理将尝试在屏幕截图中突出显示鼠标光标的位置。这对于可视化调试很有用。 | |
| ) | |
| # query="在提示文本为'输入问题,交给GenFlow的'搜索条中输入‘百度’,点击发送按钮", | |
| search_query = [ | |
| "《劳动法》中关于加班与调休的相关规定解读", | |
| "不到喀什游不算到新疆,不到古城游不算到喀什,最后一天来一场深度的早到晚古城游!", | |
| "为何说地球正处在5大灾难性生态临界点?", | |
| "为什么要进行展示设计案例分析", | |
| "镜子为什么不能正对床?", | |
| "鹅绒羽绒服比鸭绒羽绒服好在哪?", | |
| "如何从根本解决宿舍问题,改善职工住宿条件?", | |
| "独生子女为什么不能全部继承父母遗产?", | |
| "写一篇忧郁文艺小诗 一节六句话", | |
| "9.3阅兵有哪些国家参加", | |
| "今年戛纳电影节有哪些国家的影片参展", | |
| "最近的世界移动通信大会有哪些国家的企业参会", | |
| "今年日本东京国际动漫节吸引了哪些国家的动漫团队参与", | |
| "今年年大阪·关西世界园艺博览会有哪些国家设立展馆", | |
| "最近德国法兰克福国际车展有哪些国家的汽车品牌亮相", | |
| "第九届世界无人机大会有哪些国家的企业和团队参加", | |
| "最近亚洲物流展CeMAT有哪些国家的物流企业参展", | |
| "最近世界教育创新峰会有哪些国家的教育机构代表出席", | |
| "2025年意大利美食节有哪些国家带来特色美食展示" | |
| ] | |
| query = "帮我生成一份关于新能源领域的投资报告" | |
| citerion = """ | |
| 核心评价维度: | |
| 1. 内容与逻辑 (灵魂) | |
| - 清晰的投资论点: 报告是否有明确、可验证的“买入/卖出”观点及目标价?观点是否新颖,提供了市场尚未察觉的洞察? | |
| - 严谨的逻辑链条: 从行业分析到公司研究,再到财务估值,所有论据是否像积木一样牢固支撑核心论点?推理过程是否严密,无逻辑跳跃? | |
| - 研究的深度与广度: 是否覆盖了行业(格局、驱动)、公司(模式、护城河)、财务(三张表、比率)和估值(假设合理性)? | |
| 2. 数据与事实 (基石) | |
| - 准确性与时效性: 数据是否准确?来源(年报、权威统计)是否可靠?信息是否最新? | |
| - 相关性与解读: 数据是否与论点强相关?是否对数据背后的业务含义进行了深入解读,而非简单罗列? | |
| 3. 结构与表达 (骨架) | |
| - 结构清晰: 是否有清晰的摘要、目录和逻辑流程?(例如:摘要->行业->公司->财务->估值->风险->结论) | |
| - 语言专业: 语言是否精炼、客观、准确?专业术语使用是否恰当? | |
| - 可视化: 图表是否清晰、直观?排版是否专业,重点突出? | |
| 4. 客观性与风险意识 (灵魂试金石) | |
| - 客观中立: 是否同时呈现了正反论据?是否存在明显偏见? | |
| - 全面的风险分析: 是否识别并深入分析了关键的下行风险(行业、公司、宏观、估值)?是否讨论了风险对投资论点的影响?""" | |
| query = "查找5个简历模板链接" | |
| citerion = "通过访问链接确保每一条都是有效的, 并且资源链接的数量是否满足5条。有时候链接通过页面卡片提供,你需要通过点击卡片进行链接跳转。" | |
| prompt = f""" | |
| GenFlow是一个AI聊天机器人。对于给定的问题,他会执行'任务规划','任务执行','输出结果'三个步骤。 | |
| 在GenFlow执行每个步骤时,'任务规划','任务执行','输出结果'会分别呈现黑色或灰色。黑色代表该步骤完成,灰色代表该步骤未完成。 | |
| 你需要作为测试员,在它的网页底部搜索栏中输入用户提交的问题,在GenFlow执行完三个任务后,客观地判断其最终是否按照给定标准:{citerion} 回答了问题。 | |
| GenFlow返回的内容可能比较长,你可以多次执行'scroll_at'操作来查看网页中它返回的上下文。 | |
| GenFlow有时会呈现左边主页面,右边预览区域。在这种情况下执行'scroll_at'的时候你要注意鼠标位置。 | |
| 通过反复的滚动,确保主页面和预览区域已经滚动到底。预览区域往往很长,所以你需要多次执行'scroll_at'操作,确保2次滚动操作看到的网页完全一样为止, 给出最终客观评价. | |
| GenFlow一定会给出'输出结果',请保持足够的耐心! | |
| Regardless of the input language, you need to output in Chinese. | |
| """ | |
| citerion = """提交任务"1+1,2+3和4+5",判断结果分别是不是2,5,9""" | |
| query = f"""比较genflow和doubao哪个在数学计算上的能力更好。标准: {citerion}""" | |
| prompt = f""" | |
| GenFlow和DouBao是2个AI聊天机器人。 | |
| 你需要作为测试员,根据用户需求在它们的网页端搜索栏中输入问题,评测它们的能力 | |
| 初始状态你处于DouBao的首页,在测试完毕后,你需要切换到GenFlow的首页进行测试。然后给出最终结论 | |
| DouBao的url是 <url>https://www.doubao.com/chat/</url> | |
| GenFlow的url是 <url>https://wenku.baidu.com/ndcore/browse/aiunion?fr=options_AIcard_1&_wkts_=1761290807747&bdQuery=genflow&t=1761290807744&tabType=genflow&aiCreat=genflow"</url> | |
| AI返回的内容可能比较长,你可以多次执行'scroll_at'操作来查看网页中它们返回的上下文。 | |
| 你需要多次执行'scroll_at'操作,确保2次滚动操作看到的网页完全一样为止, 给出最终客观评价. | |
| Regardless of the input language, you need to output in Chinese. | |
| """ | |
| with env as browser_computer: | |
| agent = BrowserAgent( | |
| browser_computer=browser_computer, | |
| query=query, | |
| system_prompt=prompt, | |
| model_name='gemini-2.5-computer-use-preview-10-2025', | |
| ) | |
| agent.agent_loop() | |
| # pass | |
| if __name__ == "__main__": | |
| run_genflow() | |