datawhale 教程
modelscope
poetry 换源
环境:
kubuntu
poetry
python3.10
camel
任务:
跑通 camel demo
demo code
- from camel.agents import ChatAgent
- from camel.models import ModelFactory
- from camel.types import ModelPlatformType
- from dotenv import load_dotenv
- import os
- load_dotenv()
- api_key = os.getenv('QWEN_API_KEY')
- model = ModelFactory.create(
- model_platform=ModelPlatformType.OPENAI_COMPATIBLE_MODEL,
- model_type="Qwen/Qwen2.5-72B-Instruct",
- url='https://api-inference.modelscope.cn/v1/',
- api_key=api_key
- )
- agent = ChatAgent(
- model=model,
- output_language='中文'
- )
- response = agent.step("你好,你是谁?")
- print(response.msgs[0].content)
复制代码- from colorama import Fore
- from camel.societies import RolePlaying
- from camel.utils import print_text_animated
- from camel.models import ModelFactory
- from camel.types import ModelPlatformType
- from dotenv import load_dotenv
- import os
- load_dotenv(dotenv_path='.env')
- api_key = os.getenv('QWEN_API_KEY')
- model = ModelFactory.create(
- model_platform=ModelPlatformType.OPENAI_COMPATIBLE_MODEL,
- model_type="Qwen/Qwen2.5-72B-Instruct",
- url='https://api-inference.modelscope.cn/v1/',
- api_key=api_key
- )
- def main(model=model, chat_turn_limit=50) -> None:
- task_prompt = "为股票市场开发一个交易机器人"#设置任务目标
- role_play_session = RolePlaying(
- assistant_role_name="Python 程序员",#设置AI助手角色名
- assistant_agent_kwargs=dict(model=model),
- user_role_name="股票交易员",#设置用户角色名,在roleplay中,user用于指导AI助手完成任务
- user_agent_kwargs=dict(model=model),
- task_prompt=task_prompt,
- with_task_specify=True,
- task_specify_agent_kwargs=dict(model=model),
- output_language='中文'#设置输出语言
- )
- print(
- Fore.GREEN
- + f"AI 助手系统消息:\n{role_play_session.assistant_sys_msg}\n"
- )
- print(
- Fore.BLUE + f"AI 用户系统消息:\n{role_play_session.user_sys_msg}\n"
- )
- print(Fore.YELLOW + f"原始任务提示:\n{task_prompt}\n")
- print(
- Fore.CYAN
- + "指定的任务提示:"
- + f"\n{role_play_session.specified_task_prompt}\n"
- )
- print(Fore.RED + f"最终任务提示:\n{role_play_session.task_prompt}\n")
- n = 0
- input_msg = role_play_session.init_chat()
- while n < chat_turn_limit:
- n += 1
- assistant_response, user_response = role_play_session.step(input_msg)
- if assistant_response.terminated:
- print(
- Fore.GREEN
- + (
- "AI 助手已终止。原因: "
- f"{assistant_response.info['termination_reasons']}."
- )
- )
- break
- if user_response.terminated:
- print(
- Fore.GREEN
- + (
- "AI 用户已终止。"
- f"原因: {user_response.info['termination_reasons']}."
- )
- )
- break
- print_text_animated(
- Fore.BLUE + f"AI 用户:\n\n{user_response.msg.content}\n"
- )
- print_text_animated(
- Fore.GREEN + "AI 助手:\n\n"
- f"{assistant_response.msg.content}\n"
- )
- if "CAMEL_TASK_DONE" in user_response.msg.content:
- break
- input_msg = assistant_response.msg
- if __name__ == "__main__":
- main()
复制代码 experience
在服务器上跑了 task1
挺顺利的
camel repo 好像还有 gradio demo 等示例
学习内容:
poetry
camel-ai 基本利用
modelscope
ark
siliconflow
平台多得很,看你怎么用
further explore
camel/examples/
https://docs.camel-ai.org/
https://github.com/camel-ai/owl
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |