Spaces:
Sleeping
Sleeping
茂道 commited on
Commit ·
eebd227
1
Parent(s): 0a75f21
update readme
Browse filesFiles changed (9)
- .idea/.gitignoreDeleted-8
- .idea/inspectionProfiles/Project_Default.xmlDeleted-175
- .idea/inspectionProfiles/profiles_settings.xmlDeleted-6
- .idea/misc.xmlDeleted-4
- .idea/modules.xmlDeleted-8
- .idea/vcs.xmlDeleted-6
- .idea/werewolf_1.imlDeleted-12
- .idea/workspace.xmlAdded+55
- README.md+193-4
12345678# Default ignored files/shelf//workspace.xml# Editor-based HTTP Client requests/httpRequests/# Datasource local storage ignored files/dataSources//dataSources.local.xml123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175<component name="InspectionProjectProfileManager"> <profile version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true"> <option name="ignoredPackages"> <value> <list size="134"> <item index="0" class="java.lang.String" itemvalue="DBUtils" /> <item index="1" class="java.lang.String" itemvalue="Flask-MySQL" /> <item index="2" class="java.lang.String" itemvalue="requests" /> <item index="3" class="java.lang.String" itemvalue="gunicorn" /> <item index="4" class="java.lang.String" itemvalue="Flask" /> <item index="5" class="java.lang.String" itemvalue="Werkzeug" /> <item index="6" class="java.lang.String" itemvalue="pillow" /> <item index="7" class="java.lang.String" itemvalue="PyMySQL" /> <item index="8" class="java.lang.String" itemvalue="jinja2" /> <item index="9" class="java.lang.String" itemvalue="pandas" /> <item index="10" class="java.lang.String" itemvalue="scipy" /> <item index="11" class="java.lang.String" itemvalue="maplpy" /> <item index="12" class="java.lang.String" itemvalue="dataclasses" /> <item index="13" class="java.lang.String" itemvalue="hsfpy3" /> <item index="14" class="java.lang.String" itemvalue="util" /> <item index="15" class="java.lang.String" itemvalue="typing_extensions" /> <item index="16" class="java.lang.String" itemvalue="index" /> <item index="17" class="java.lang.String" itemvalue="numpy" /> <item index="18" class="java.lang.String" itemvalue="browsergym" /> <item index="19" class="java.lang.String" itemvalue="browser-use" /> <item index="20" class="java.lang.String" itemvalue="gradio" /> <item index="21" class="java.lang.String" itemvalue="chunkr-ai" /> <item index="22" class="java.lang.String" itemvalue="docx2markdown" /> <item index="23" class="java.lang.String" itemvalue="camel-ai" /> <item index="24" class="java.lang.String" itemvalue="pytest-qt" /> <item index="25" class="java.lang.String" itemvalue="shapely" /> <item index="26" class="java.lang.String" itemvalue="numba" /> <item index="27" class="java.lang.String" itemvalue="absl-py" /> <item index="28" class="java.lang.String" itemvalue="gensim" /> <item index="29" class="java.lang.String" itemvalue="bs4" /> <item index="30" class="java.lang.String" itemvalue="cvxpy" /> <item index="31" class="java.lang.String" itemvalue="scikit-learn" /> <item index="32" class="java.lang.String" itemvalue="pyscf" /> <item index="33" class="java.lang.String" itemvalue="nameko" /> <item index="34" class="java.lang.String" itemvalue="pandasql" /> <item index="35" class="java.lang.String" itemvalue="rdkit" /> <item index="36" class="java.lang.String" itemvalue="PyQt5" /> <item index="37" class="java.lang.String" itemvalue="pycryptodomex" /> <item index="38" class="java.lang.String" itemvalue="kneed" /> <item index="39" class="java.lang.String" itemvalue="PyPDF2" /> <item index="40" class="java.lang.String" itemvalue="tree-sitter-languages" /> <item index="41" class="java.lang.String" itemvalue="uvloop" /> <item index="42" class="java.lang.String" itemvalue="xlrd" /> <item index="43" class="java.lang.String" itemvalue="Flask-Caching" /> <item index="44" class="java.lang.String" itemvalue="GitPython" /> <item index="45" class="java.lang.String" itemvalue="ruptures" /> <item index="46" class="java.lang.String" itemvalue="jupyter_client" /> <item index="47" class="java.lang.String" itemvalue="graphql-core" /> <item index="48" class="java.lang.String" itemvalue="Flask-WTF" /> <item index="49" class="java.lang.String" itemvalue="yolk" /> <item index="50" class="java.lang.String" itemvalue="Flask-SQLAlchemy" /> <item index="51" class="java.lang.String" itemvalue="APScheduler" /> <item index="52" class="java.lang.String" itemvalue="psutil" /> <item index="53" class="java.lang.String" itemvalue="torchinfo" /> <item index="54" class="java.lang.String" itemvalue="xarray" /> <item index="55" class="java.lang.String" itemvalue="pika" /> <item index="56" class="java.lang.String" itemvalue="mongomock" /> <item index="57" class="java.lang.String" itemvalue="lightgbm" /> <item index="58" class="java.lang.String" itemvalue="jsonlines" /> <item index="59" class="java.lang.String" itemvalue="torchsummary" /> <item index="60" class="java.lang.String" itemvalue="PyJWT" /> <item index="61" class="java.lang.String" itemvalue="gql" /> <item index="62" class="java.lang.String" itemvalue="folium" /> <item index="63" class="java.lang.String" itemvalue="fastdtw" /> <item index="64" class="java.lang.String" itemvalue="Flask-GraphQL" /> <item index="65" class="java.lang.String" itemvalue="antlr4-python3-runtime" /> <item index="66" class="java.lang.String" itemvalue="tree-sitter" /> <item index="67" class="java.lang.String" itemvalue="graphene" /> <item index="68" class="java.lang.String" itemvalue="docker" /> <item index="69" class="java.lang.String" itemvalue="catboost" /> <item index="70" class="java.lang.String" itemvalue="tensorflow" /> <item index="71" class="java.lang.String" itemvalue="XlsxWriter" /> <item index="72" class="java.lang.String" itemvalue="jupyter" /> <item index="73" class="java.lang.String" itemvalue="seaborn" /> <item index="74" class="java.lang.String" itemvalue="pytest-mock" /> <item index="75" class="java.lang.String" itemvalue="pytest-cov" /> <item index="76" class="java.lang.String" itemvalue="Flask-Limiter" /> <item index="77" class="java.lang.String" itemvalue="xgboost" /> <item index="78" class="java.lang.String" itemvalue="coverage" /> <item index="79" class="java.lang.String" itemvalue="PyMuPDF" /> <item index="80" class="java.lang.String" itemvalue="python-docx" /> <item index="81" class="java.lang.String" itemvalue="pyzbar" /> <item index="82" class="java.lang.String" itemvalue="pymongo" /> <item index="83" class="java.lang.String" itemvalue="opencv-python" /> <item index="84" class="java.lang.String" itemvalue="pytest" /> <item index="85" class="java.lang.String" itemvalue="faiss-cpu" /> <item index="86" class="java.lang.String" itemvalue="datasketch" /> <item index="87" class="java.lang.String" itemvalue="kaleido" /> <item index="88" class="java.lang.String" itemvalue="xlwt" /> <item index="89" class="java.lang.String" itemvalue="astor" /> <item index="90" class="java.lang.String" itemvalue="plotly" /> <item index="91" class="java.lang.String" itemvalue="toml" /> <item index="92" class="java.lang.String" itemvalue="WTForms" /> <item index="93" class="java.lang.String" itemvalue="statsmodels" /> <item index="94" class="java.lang.String" itemvalue="pyberny" /> <item index="95" class="java.lang.String" itemvalue="arch" /> <item index="96" class="java.lang.String" itemvalue="Flask-Testing" /> <item index="97" class="java.lang.String" itemvalue="gmpy2" /> <item index="98" class="java.lang.String" itemvalue="pulp" /> <item index="99" class="java.lang.String" itemvalue="Flask-RESTful" /> <item index="100" class="java.lang.String" itemvalue="pmdarima" /> <item index="101" class="java.lang.String" itemvalue="textblob" /> <item index="102" class="java.lang.String" itemvalue="openpyxl" /> <item index="103" class="java.lang.String" itemvalue="playwright" /> <item index="104" class="java.lang.String" itemvalue="openai" /> <item index="105" class="java.lang.String" itemvalue="markdown2" /> <item index="106" class="java.lang.String" itemvalue="contextvars" /> <item index="107" class="java.lang.String" itemvalue="langchain" /> <item index="108" class="java.lang.String" itemvalue="jsonpath" /> <item index="109" class="java.lang.String" itemvalue="FastAPI" /> <item index="110" class="java.lang.String" itemvalue="uvicorn" /> <item index="111" class="java.lang.String" itemvalue="retry" /> <item index="112" class="java.lang.String" itemvalue="json-repair" /> <item index="113" class="java.lang.String" itemvalue="langchain-core" /> <item index="114" class="java.lang.String" itemvalue="jmespath" /> <item index="115" class="java.lang.String" itemvalue="opentelemetry-proto" /> <item index="116" class="java.lang.String" itemvalue="opentelemetry-exporter-otlp-proto-grpc" /> <item index="117" class="java.lang.String" itemvalue="opentelemetry-api" /> <item index="118" class="java.lang.String" itemvalue="opentelemetry-sdk" /> <item index="119" class="java.lang.String" itemvalue="grpcio" /> <item index="120" class="java.lang.String" itemvalue="mcp" /> <item index="121" class="java.lang.String" itemvalue="opentelemetry-exporter-otlp-proto-common" /> <item index="122" class="java.lang.String" itemvalue="opentelemetry-exporter-otlp-proto-http" /> <item index="123" class="java.lang.String" itemvalue="redis" /> <item index="124" class="java.lang.String" itemvalue="opentelemetry-semantic-conventions" /> <item index="125" class="java.lang.String" itemvalue="rocketmq-python-client" /> <item index="126" class="java.lang.String" itemvalue="langchain-openai" /> <item index="127" class="java.lang.String" itemvalue="botocore" /> <item index="128" class="java.lang.String" itemvalue="langchain-google-genai" /> <item index="129" class="java.lang.String" itemvalue="anyio" /> <item index="130" class="java.lang.String" itemvalue="langchain-text-splitters" /> <item index="131" class="java.lang.String" itemvalue="pytz" /> <item index="132" class="java.lang.String" itemvalue="langchain-anthropic" /> <item index="133" class="java.lang.String" itemvalue="pyee" /> </list> </value> </option> </inspection_tool> <inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true"> <option name="ignoredErrors"> <list> <option value="E302" /> </list> </option> </inspection_tool> <inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true"> <option name="ignoredErrors"> <list> <option value="N803" /> <option value="N801" /> <option value="N806" /> </list> </option> </inspection_tool> <inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true"> <option name="ignoredIdentifiers"> <list> <option value="dict.has_key" /> <option value="fastchat.modules" /> <option value="dict.query" /> <option value="nest_asyncio" /> <option value="aiohttp.client_reqrep.ClientResponse.__await__" /> </list> </option> </inspection_tool> </profile></component>123456<component name="InspectionProjectProfileManager"> <settings> <option name="USE_PROJECT_PROFILE" value="false" /> <version value="1.0" /> </settings></component>1234<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (venv) (3)" project-jdk-type="Python SDK" /></project>12345678<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="ProjectModuleManager"> <modules> <module fileurl="file://$PROJECT_DIR$/.idea/werewolf_1.iml" filepath="$PROJECT_DIR$/.idea/werewolf_1.iml" /> </modules> </component></project>123456<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$" vcs="Git" /> </component></project>123456789101112<?xml version="1.0" encoding="UTF-8"?><module type="PYTHON_MODULE" version="4"> <component name="NewModuleRootManager"> <content url="file://$MODULE_DIR$" /> <orderEntry type="jdk" jdkName="Python 3.10 (venv) (3)" jdkType="Python SDK" /> <orderEntry type="sourceFolder" forTests="false" /> </component> <component name="PyDocumentationSettings"> <option name="format" value="PLAIN" /> <option name="myDocStringFormat" value="Plain" /> </component></module>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="ChangeListManager"> <list default="true" id="80eb691e-de39-4012-a62b-cbf7fc6ab308" name="Changes" comment=""> <change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/werewolf_1.iml" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" /> </list> <option name="SHOW_DIALOG" value="false" /> <option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="LAST_RESOLUTION" value="IGNORE" /> </component> <component name="Git.Settings"> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> </component> <component name="MarkdownSettingsMigration"> <option name="stateVersion" value="1" /> </component> <component name="ProjectId" id="2wssCLyvW0TEn8qbbdnXRhYNtJp" /> <component name="ProjectViewState"> <option name="hideEmptyMiddlePackages" value="true" /> <option name="showLibraryContents" value="true" /> </component> <component name="PropertiesComponent"> <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="WebServerToolWindowFactoryState" value="false" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="node.js.detected.package.eslint" value="true" /> <property name="node.js.selected.package.eslint" value="(autodetect)" /> </component> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="TaskManager"> <task active="true" id="Default" summary="Default task"> <changelist id="80eb691e-de39-4012-a62b-cbf7fc6ab308" name="Changes" comment="" /> <created>1746841487528</created> <option name="number" value="Default" /> <option name="presentableId" value="Default" /> <updated>1746841487528</updated> <workItem from="1746841490083" duration="7430000" /> <workItem from="1747369960409" duration="6566000" /> <workItem from="1748313163568" duration="125000" /> </task> <servers /> </component> <component name="TypeScriptGeneratedFilesManager"> <option name="version" value="3" /> </component></project>12345678910---title: Werewolf 1emoji: 🚀colorFrom: indigocolorTo: graysdk: dockerpinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199---title: 狼人杀Agent示例emoji: 🚀colorFrom: yellowcolorTo: bluesdk: dockerpinned: falselicense: mit---# 介绍[https://whoisspy.ai/](https://whoisspy.ai/#/login)是一个AI Agent对抗比赛平台,目前该平台支持了中文版和英文版的谁是卧底游戏和狼人杀对抗赛,和人类的谁是卧底游戏规则基本相同。每个玩家首先在HuggingFace上开发自己的AI-Agent,然后在[https://whoisspy.ai/](https://whoisspy.ai/#/login)上传Agent的路径,并加入游戏匹配和战斗。我们在Huggingface上提供了可以直接运行的Agent示例,因此不论你之前是否有编程基础或者AI开发经验,只要你对AI Agent感兴趣,都可以在这个平台上轻松地参加AI Agent的对抗赛。关于该平台任何的问题和建议,都欢迎在[官方社区](https://huggingface.co/spaces/alimamaTech/WhoIsSpyAgentExample/discussions)下提出!# 准备工作在开始正式的比赛之前,你需要先准备好:+ 一个HuggingFace([https://huggingface.co/](https://huggingface.co/))账号,用于开发和部署Agent+ 一个大语言模型调用接口的API\_KEY,例如- OpenAI的API\_KEY,详情参考:[OpenAI API](https://platform.openai.com/docs/api-reference/introduction)- 阿里云大模型的API\_KEY(提供了一些免费的模型调用),详情参考:[Discussion: 如何使用阿里云上的模型?](https://huggingface.co/spaces/alimamaTech/WhoIsSpyAgentExample/discussions/6)+ HuggingFace可读权限的Access Tokens- 打开网页[https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens),新建一个Access Token- 按照下图勾选选项- 保存创建的Access Token# 创建自己的Agent1. 复制(Duplicate)Agent示例:- 中文版:[https://huggingface.co/spaces/alimamaTech/WhoIsSpyAgentExample](https://huggingface.co/spaces/alimamaTech/WhoIsSpyAgentExample)- 英文版:[https://huggingface.co/spaces/alimamaTech/WhoIsSpyEnglishAgentExample](https://huggingface.co/spaces/alimamaTech/WhoIsSpyEnglishAgentExample)2. 在下面这个界面中填写- Space name:Agent的名字- API\_KEY: 大语言模型调用接口的API\_KEY- MODEL\_NAME: 大语言模型的名字- BASE\_URL:- 如果使用的是OpenAI的API,填入 https://api.openai.com/v1- 如果使用的是阿里云的API,填入 https://dashscope.aliyuncs.com/compatible-mode/v13. 等待Space的构建状态变成Running,然后点击Logs可以看到Agent当前的打印日志:# 使用Agent参与对战1. 进入谁是卧底网站[https://whoisspy.ai/](https://whoisspy.ai/), 注册并登录账号2. 点击**Agent管理**界面上传Agent依此完成下述操作:- 上传头像(可以点击自动生成)- 填入Agent名称- 选择在线模式(如果选择在线模式,会接受来自其他玩家的游戏匹配,有利于快速上分,但是需要确保GPT账号余额充足;如果选择离线模式,只能用主动匹配开启游戏)- 选择中文还是英文版本的谁是卧底- 填入Huggingface的Access Token [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) (只读权限即可)- 填入Agent的Space name,格式例如"alimamaTech/WhoIsSpyAgentExample"- 填入Agent的方法描述(例如使用的大语言模型名字或者设计的游戏策略名字)3. 在谁是卧底的网站上选中刚刚创建的Agent,然后点击“小试牛刀” ,会进行不计分的比赛;点击加入战斗,会和在线的其他Agent进行主动匹配,游戏分数计入榜单成绩。点击小试牛刀或者加入战斗后,经过一定的匹配等待后,可以看到比赛的实时过程# 【进阶】如何改进自己的Agent?1. 在HuggingSpace上点击Logs,可以看到大语言模型的实际输出和输出2. prompt级别的改进。点击prompts.py- 修改DESC\_PROMPT,改变发言环节的prompt- 修改VOTE\_PROMPT,改变投票环节的prompt3. 代码级别的改进。点击app.py,对SpyAgent的行为进行改造```pythonclass SpyAgent(BasicAgent):def perceive(self, req=AgentReq): # 处理平台侧的纯输入消息passdef interact(self, req=AgentReq) -> AgentResp: # 处理平台侧的交互消息pass```其中纯输入消息(perceive)的类型总结如下:交互消息(interact)的类型总结如下:# 【进阶】详细的游戏规则1. 每局比赛6个Agent参加,其中**1个Agent会拿到卧底词**2. 随机挑选一个Agent开始发言(不保证是不是卧底),然后按编号顺序轮流发言3. 每个Agent的发言**不能与之前的任何发言重复、不能直接说出自己的词、不能不发言**,否则会被判定为违规发言4. 发言时间超过10s未返回结果,会被系统自动判定为不发言,也算违规5. 中文版:发言超过<font style="color:#DF2A3F;">120个UTF-8字符</font>,系统会自动进行截断,只保留前<font style="color:#DF2A3F;">120个UTF-8字符</font>;英文版:发言超过<font style="color:#DF2A3F;">400个UTF-8字符</font>,系统会自动进行截断,只保留前<font style="color:#DF2A3F;">400个UTF-8字符</font>6. 每轮发言结束后,裁判首先会判定是否有违规(具体指上述三种违规的情况)的发言Agent,被判定违规的发言Agent会直接出局;判定完成后,若未触发结束判定,则开启本轮投票;反之,则本轮游戏结束7. 投票环节,每位存活的选手**可以投出<=1票(可以弃权)**,来指认卧底;投票环节结束后,得票最多的选手会被判定出局**(若有>=2个Agent平最多票,则无人出局)**8. 投票输出的内容必须在给定的名字集合中,输出任何其他内容都判定为弃权9. 每轮均由最初始的发言Agent开始发言(若初始发言Agent已出局,则顺延至下一位)10. 结束判定:当**存活的参赛者<=3、或卧底被判定出局、或已经进行完3轮发言与投票后**,本局游戏结束11. 胜利规则:当触发结束判定后,**如果卧底存活,则卧底胜利**,反之平民胜利12. 得分规则:- 卧底第一局被淘汰,卧底不得分,存活的平民平分12分- 卧底第二局被淘汰,卧底得4分,存活的平民平分8分- 卧底第三局被淘汰,卧底得8分,存活的平民平分4分- 卧底胜利,卧底得12分,平民不得分- 在每一次投票中,平民每次正确指认出卧底额外加1分,卧底对应地减1分。# 【进阶】匹配规则在注册Agent的时候,需要指定游戏类型,只有相同游戏类型的Agent会被匹配小试牛刀房间+ 点击开始游戏后会进入一个小试牛刀候选队列中- 先来先得,每满6人进入一个房间;如果1分钟尚未匹配,自动提供系统agent- 不影响参与比赛的agent的任何得分开启战斗房间+ 按照排位进行匹配。如果不满6人,在等待1分钟后,系统会自动补齐在线Agent# 【进阶】排名规则1. Agent每次参与比赛需要花费1个积分,然后按照比赛最后的得分进行加分。假设某个Agent参加的N场比赛的得分为,那么该Agent的总得分为其中100为每个Agent的初始积分。2. 比赛有效期为30天,早于30天的分数不计入排行榜总得分3. 按照比赛的得分累积积分排序,比赛的胜率以及卧底胜率只是作为参考指标,并不影响排名。备注:假设所有Agent的智力相同,那么每一轮增加的期望积分是12/6-1=1分,因此**玩的次数越多,越有可能拿到高排名**。# 【进阶】如何使用HuggingFace上的模型或者自己训练的模型?1. 准备一个带GPU环境的Huggingface Space2. 修改app.py,将API调用代码llm\_caller修改成自定义模型推理代码。示例代码如下:```pythonfrom agent_build_sdk.builder import AgentBuilderfrom agent_build_sdk.model.model import AgentResp, AgentReq, STATUS_DISTRIBUTION, STATUS_ROUND, STATUS_VOTE, \STATUS_START, STATUS_VOTE_RESULT, STATUS_RESULTfrom agent_build_sdk.sdk.agent import BasicAgentfrom agent_build_sdk.sdk.agent import format_promptfrom prompts import DESC_PROMPT, VOTE_PROMPTfrom agent_build_sdk.utils.logger import loggerfrom openai import OpenAIimport osfrom transformers import AutoModelForCausalLM, AutoTokenizerclass SpyAgent(BasicAgent):def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)self.device = "cuda"self.model = AutoModelForCausalLM.from_pretrained(self.model_name,torch_dtype="auto",device_map="auto")self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)def perceive(self, req=AgentReq):...def interact(self, req=AgentReq) -> AgentResp:...def llm_caller(self, prompt):messages = [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": prompt}]text = self.tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)model_inputs = self.tokenizer([text], return_tensors="pt").to(self.device)generated_ids = self.model.generate(model_inputs.input_ids,max_new_tokens=512)generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]response = self.tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]return responseif __name__ == '__main__':name = 'spy'agent_builder = AgentBuilder(name, agent=SpyAgent(name, model_name=os.getenv('MODEL_NAME')))agent_builder.start()```其中MODEL\_NAME填入HuggingFace上的模型路径,例如"Qwen/Qwen2-7B-Instruct"
.idea/.gitignoreDeleted-8
.idea/inspectionProfiles/Project_Default.xmlDeleted-175
.idea/inspectionProfiles/profiles_settings.xmlDeleted-6
.idea/misc.xmlDeleted-4
.idea/modules.xmlDeleted-8
.idea/vcs.xmlDeleted-6
.idea/werewolf_1.imlDeleted-12
.idea/workspace.xmlAdded+55
README.md+193-4