1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
| import os import dotenv import construct import prompts as prompts
from pydantic import BaseModel from typing import List from camel.models import ModelFactory from camel.types import ModelPlatformType, ModelType, TaskType, RoleType from camel.configs import ChatGPTConfig from camel.agents import ChatAgent, TaskPlannerAgent from camel.messages import BaseMessage from camel.prompts import TextPrompt from camel.societies import RolePlaying from camel.societies.workforce import Workforce from camel.toolkits import ThinkingToolkit, SearchToolkit, HumanToolkit, FunctionTool from camel.tasks import Task
dotenv.load_dotenv() OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") BASE_URL = os.getenv("BASE_URL")
system_message = prompts.total_system_message base_model = ModelFactory.create( model_platform=ModelPlatformType.OPENAI, model_type=ModelType.GPT_4O_MINI, model_config_dict=ChatGPTConfig().as_dict(), api_key=OPENAI_API_KEY, url=BASE_URL, )
single_agent = ChatAgent( system_message=system_message, model=base_model, message_window_size=10, tools=[ ], )
topic_message = BaseMessage( role_name="User", role_type=RoleType.USER, content=f"The text topic is {prompts.text_topic}", meta_dict={}, )
initial_reuqirements = BaseMessage( role_name="User", role_type=RoleType.USER, content=f"The Initial requirements are as follows: {prompts.requirements}", meta_dict={}, )
original_text = construct.read_file("data/Original.txt")
original_passage = BaseMessage( role_name="User", role_type=RoleType.USER, content=f"""the text of my argumentative essay is given below:\n\n\ =================ORIGINAL passage BEGIN================\n\ {original_text}\n\ =================ORIGINAL passage END================ """, meta_dict={}, )
class ResponseFormat(BaseModel): whole_text_after_edited: str Modification_summary: str
max_length = 250
def run_single_agents(): single_agent.record_message(initial_reuqirements) single_agent.record_message(topic_message) single_agent.record_message(original_passage) UserMessage = "Start revising the essay and generate a report" response = single_agent.step(UserMessage, response_format=ResponseFormat) print(response.msgs[0].content)
work_force = Workforce( description="Automated English Essay Revision", new_worker_agent_kwargs={"model": base_model}, coordinator_agent_kwargs={"model": base_model}, task_agent_kwargs={"model": base_model}, )
task_agent = ChatAgent( model=base_model, system_message=f""" The total task: {prompts.total_prompt}
You are an expert in task decomposition. Your responsibilities: 1. Analyze requirements: \n{prompts.requirements}\n 2. Read the original passage, the passage is shown below\n:{original_text}\n 3. You need to provide a more specific modification plan based on the requirements, combining it with the original text, but without making specific changes. For example: the relative clause in a certain sentence does not conform to specific grammatical rules and needs to be revised; or the word choice in a certain part is too simplistic and needs to be optimized; or the logic in a certain section needs to be further strengthened. 4. More detailed modification requirements are needed, covering all aspects such as grammar, logic, word choice, and sentence structure.
Response format: ### Specific Requirements [Return specified and modified requirements]
""", message_window_size=10, )
conservative_agent = ChatAgent( system_message=f"""
{prompts.total_prompt}\n You will receive the specific requirements from the previous agents.\n The original text: {original_text}\n
Attention!!!, particularly for you, as a more meticulous writer, your revisions should focus on the logic and organizational structure of the article, making it more coherent. Provide complete edited text and brief feedback (<50 words). Ensure native English usage and <{1.2 * max_length} word limit. Response format: ### Version ### [full edited text] ### Feedback ### [comments] """, model=base_model, message_window_size=10, )
imaginative_agent = ChatAgent( system_message=f"""
{prompts.total_prompt}\n You will receive the specific requirements from the previous agents.\n The original text: {original_text}\n
Attention!!!, particularly for you, as a more meticulous writer, your revisions should focus on the logic and organizational structure of the article, making it more coherent. Provide complete edited text and brief feedback (<50 words). Ensure native English usage and <{1.2 * max_length} word limit. Response format: ### Version ### [full edited text] ### Feedback ### [comments] """, model=base_model, message_window_size=10, )
integrator_agent = ChatAgent( system_message=f""" {prompts.total_prompt}\n You are the final integrator. Your responsibilities: 1.You will receive three documents: the original article and two modified articles by two editors(one conservative and one creative) 2.You need to take an overall perspective to compare the highlights of the two revised drafts against the original manuscript, and integrate the two articles, taking the strengths from each. 3.!!Attention: You need to make sure your passage (after integrated) is no more than {1.5 * max_length} words.
Response format: ### Final Version ### [text after integrated] ### Feedback ### [comments] """, model=base_model, message_window_size=10, )
reporter_agent = ChatAgent( system_message=f""" {prompts.total_prompt},\n The original article is: {original_text}\n You are the final reporter, you will receive the final scripts modified, and make the last modifications: 1. Make sure all your modifications adhere to the English Usage. 2. Make sure the total length is no more than {max_length} words. Response format: ### Final version ### [final text]
### Feedback ### In this section, you are asked to generate a report about the modifications between the final version and the original version. """, model=base_model, message_window_size=10, )
work_force.add_single_agent_worker( description="Specify the task into subtasks", worker=task_agent, ).add_single_agent_worker( description="Make some modifications conservatively", worker=conservative_agent, ).add_single_agent_worker( description="Make some modifications imaginaively", worker=imaginative_agent, ).add_single_agent_worker( description="Integrate all the modifications", worker=integrator_agent, ).add_single_agent_worker( description="Generate the modifications report", worker=reporter_agent, )
def run_workforce(): task = Task( content=prompts.total_task, id = "0", )
task = work_force.process_task(task) print(task.result)
if __name__ == "__main__": run_single_agents()
run_workforce()
|