فهرست منبع

update chapter 6 example of camel

jjyaoao 5 ماه پیش
والد
کامیت
f91c600848
2فایلهای تغییر یافته به همراه36 افزوده شده و 0 حذف شده
  1. 18 0
      docs/chapter6/Chapter6-Framework-Development-Practice.md
  2. 18 0
      docs/chapter6/第六章 框架开发实践.md

+ 18 - 0
docs/chapter6/Chapter6-Framework-Development-Practice.md

@@ -756,6 +756,23 @@ First, we need to clarify the common goal of the two AI experts. We define this
 from colorama import Fore
 from colorama import Fore
 from camel.societies import RolePlaying
 from camel.societies import RolePlaying
 from camel.utils import print_text_animated
 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()
+LLM_API_KEY = os.getenv("LLM_API_KEY")
+LLM_BASE_URL = os.getenv("LLM_BASE_URL")
+LLM_MODEL = os.getenv("LLM_MODEL")
+
+# Create model, using Qwen as an example, calling Alibaba Cloud Bailian platform API
+model = ModelFactory.create(
+    model_platform=ModelPlatformType.QWEN,
+    model_type=LLM_MODEL,
+    url=LLM_BASE_URL,
+    api_key=LLM_API_KEY
+)
 
 
 # Define collaboration task
 # Define collaboration task
 task_prompt = """
 task_prompt = """
@@ -785,6 +802,7 @@ role_play_session = RolePlaying(
     assistant_role_name="Psychologist",
     assistant_role_name="Psychologist",
     user_role_name="Writer",
     user_role_name="Writer",
     task_prompt=task_prompt,
     task_prompt=task_prompt,
+    model=model,
     with_task_specify=False, # In this example, we directly use the given task_prompt
     with_task_specify=False, # In this example, we directly use the given task_prompt
 )
 )
 
 

+ 18 - 0
docs/chapter6/第六章 框架开发实践.md

@@ -759,6 +759,23 @@ CAMEL 实现自主协作的基石是两大核心概念:<strong>角色扮演 (R
 from colorama import Fore
 from colorama import Fore
 from camel.societies import RolePlaying
 from camel.societies import RolePlaying
 from camel.utils import print_text_animated
 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()
+LLM_API_KEY = os.getenv("LLM_API_KEY")
+LLM_BASE_URL = os.getenv("LLM_BASE_URL")
+LLM_MODEL = os.getenv("LLM_MODEL")
+
+#创建模型,在这里以Qwen为例,调用的百炼大模型平台API
+model = ModelFactory.create(
+    model_platform=ModelPlatformType.QWEN,
+    model_type=LLM_MODEL,
+    url=LLM_BASE_URL,
+    api_key=LLM_API_KEY
+)
 
 
 # 定义协作任务
 # 定义协作任务
 task_prompt = """
 task_prompt = """
@@ -788,6 +805,7 @@ role_play_session = RolePlaying(
     assistant_role_name="心理学家",
     assistant_role_name="心理学家",
     user_role_name="作家",
     user_role_name="作家",
     task_prompt=task_prompt,
     task_prompt=task_prompt,
+    model=model,
     with_task_specify=False, # 在本例中,我们直接使用给定的task_prompt
     with_task_specify=False, # 在本例中,我们直接使用给定的task_prompt
 )
 )