camel-ai 0.1.1__py3-none-any.whl → 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of camel-ai might be problematic. Click here for more details.

Files changed (117) hide show
  1. camel/__init__.py +1 -11
  2. camel/agents/__init__.py +7 -5
  3. camel/agents/chat_agent.py +134 -86
  4. camel/agents/critic_agent.py +28 -17
  5. camel/agents/deductive_reasoner_agent.py +235 -0
  6. camel/agents/embodied_agent.py +92 -40
  7. camel/agents/knowledge_graph_agent.py +221 -0
  8. camel/agents/role_assignment_agent.py +27 -17
  9. camel/agents/task_agent.py +60 -34
  10. camel/agents/tool_agents/base.py +0 -1
  11. camel/agents/tool_agents/hugging_face_tool_agent.py +7 -4
  12. camel/configs/__init__.py +29 -0
  13. camel/configs/anthropic_config.py +73 -0
  14. camel/configs/base_config.py +22 -0
  15. camel/{configs.py → configs/openai_config.py} +37 -64
  16. camel/embeddings/__init__.py +2 -0
  17. camel/embeddings/base.py +3 -2
  18. camel/embeddings/openai_embedding.py +10 -5
  19. camel/embeddings/sentence_transformers_embeddings.py +65 -0
  20. camel/functions/__init__.py +18 -3
  21. camel/functions/google_maps_function.py +335 -0
  22. camel/functions/math_functions.py +7 -7
  23. camel/functions/open_api_function.py +380 -0
  24. camel/functions/open_api_specs/coursera/__init__.py +13 -0
  25. camel/functions/open_api_specs/coursera/openapi.yaml +82 -0
  26. camel/functions/open_api_specs/klarna/__init__.py +13 -0
  27. camel/functions/open_api_specs/klarna/openapi.yaml +87 -0
  28. camel/functions/open_api_specs/speak/__init__.py +13 -0
  29. camel/functions/open_api_specs/speak/openapi.yaml +151 -0
  30. camel/functions/openai_function.py +346 -42
  31. camel/functions/retrieval_functions.py +61 -0
  32. camel/functions/search_functions.py +100 -35
  33. camel/functions/slack_functions.py +275 -0
  34. camel/functions/twitter_function.py +484 -0
  35. camel/functions/weather_functions.py +36 -23
  36. camel/generators.py +65 -46
  37. camel/human.py +17 -11
  38. camel/interpreters/__init__.py +25 -0
  39. camel/interpreters/base.py +49 -0
  40. camel/{utils/python_interpreter.py → interpreters/internal_python_interpreter.py} +129 -48
  41. camel/interpreters/interpreter_error.py +19 -0
  42. camel/interpreters/subprocess_interpreter.py +190 -0
  43. camel/loaders/__init__.py +22 -0
  44. camel/{functions/base_io_functions.py → loaders/base_io.py} +38 -35
  45. camel/{functions/unstructured_io_fuctions.py → loaders/unstructured_io.py} +199 -110
  46. camel/memories/__init__.py +17 -7
  47. camel/memories/agent_memories.py +156 -0
  48. camel/memories/base.py +97 -32
  49. camel/memories/blocks/__init__.py +21 -0
  50. camel/memories/{chat_history_memory.py → blocks/chat_history_block.py} +34 -34
  51. camel/memories/blocks/vectordb_block.py +101 -0
  52. camel/memories/context_creators/__init__.py +3 -2
  53. camel/memories/context_creators/score_based.py +32 -20
  54. camel/memories/records.py +6 -5
  55. camel/messages/__init__.py +2 -2
  56. camel/messages/base.py +99 -16
  57. camel/messages/func_message.py +7 -4
  58. camel/models/__init__.py +6 -2
  59. camel/models/anthropic_model.py +146 -0
  60. camel/models/base_model.py +10 -3
  61. camel/models/model_factory.py +17 -11
  62. camel/models/open_source_model.py +25 -13
  63. camel/models/openai_audio_models.py +251 -0
  64. camel/models/openai_model.py +20 -13
  65. camel/models/stub_model.py +10 -5
  66. camel/prompts/__init__.py +7 -5
  67. camel/prompts/ai_society.py +21 -14
  68. camel/prompts/base.py +54 -47
  69. camel/prompts/code.py +22 -14
  70. camel/prompts/evaluation.py +8 -5
  71. camel/prompts/misalignment.py +26 -19
  72. camel/prompts/object_recognition.py +35 -0
  73. camel/prompts/prompt_templates.py +14 -8
  74. camel/prompts/role_description_prompt_template.py +16 -10
  75. camel/prompts/solution_extraction.py +9 -5
  76. camel/prompts/task_prompt_template.py +24 -21
  77. camel/prompts/translation.py +9 -5
  78. camel/responses/agent_responses.py +5 -2
  79. camel/retrievers/__init__.py +26 -0
  80. camel/retrievers/auto_retriever.py +330 -0
  81. camel/retrievers/base.py +69 -0
  82. camel/retrievers/bm25_retriever.py +140 -0
  83. camel/retrievers/cohere_rerank_retriever.py +108 -0
  84. camel/retrievers/vector_retriever.py +183 -0
  85. camel/societies/__init__.py +1 -1
  86. camel/societies/babyagi_playing.py +56 -32
  87. camel/societies/role_playing.py +188 -133
  88. camel/storages/__init__.py +18 -0
  89. camel/storages/graph_storages/__init__.py +23 -0
  90. camel/storages/graph_storages/base.py +82 -0
  91. camel/storages/graph_storages/graph_element.py +74 -0
  92. camel/storages/graph_storages/neo4j_graph.py +582 -0
  93. camel/storages/key_value_storages/base.py +1 -2
  94. camel/storages/key_value_storages/in_memory.py +1 -2
  95. camel/storages/key_value_storages/json.py +8 -13
  96. camel/storages/vectordb_storages/__init__.py +33 -0
  97. camel/storages/vectordb_storages/base.py +202 -0
  98. camel/storages/vectordb_storages/milvus.py +396 -0
  99. camel/storages/vectordb_storages/qdrant.py +373 -0
  100. camel/terminators/__init__.py +1 -1
  101. camel/terminators/base.py +2 -3
  102. camel/terminators/response_terminator.py +21 -12
  103. camel/terminators/token_limit_terminator.py +5 -3
  104. camel/toolkits/__init__.py +21 -0
  105. camel/toolkits/base.py +22 -0
  106. camel/toolkits/github_toolkit.py +245 -0
  107. camel/types/__init__.py +18 -6
  108. camel/types/enums.py +129 -15
  109. camel/types/openai_types.py +10 -5
  110. camel/utils/__init__.py +20 -13
  111. camel/utils/commons.py +170 -85
  112. camel/utils/token_counting.py +135 -15
  113. {camel_ai-0.1.1.dist-info → camel_ai-0.1.4.dist-info}/METADATA +123 -75
  114. camel_ai-0.1.4.dist-info/RECORD +119 -0
  115. {camel_ai-0.1.1.dist-info → camel_ai-0.1.4.dist-info}/WHEEL +1 -1
  116. camel/memories/context_creators/base.py +0 -72
  117. camel_ai-0.1.1.dist-info/RECORD +0 -75
@@ -34,9 +34,9 @@ class RolePlaying:
34
34
  assistant_role_name (str): The name of the role played by the
35
35
  assistant.
36
36
  user_role_name (str): The name of the role played by the user.
37
- critic_role_name (str): The name of the role played by the critic.
38
- Role name with :obj:`"human"` will set critic as a :obj:`Human`
39
- agent, else will create a :obj:`CriticAgent`.
37
+ critic_role_name (str, optional): The name of the role played by the
38
+ critic. Role name with :obj:`"human"` will set critic as a
39
+ :obj:`Human` agent, else will create a :obj:`CriticAgent`.
40
40
  (default: :obj:`"critic"`)
41
41
  task_prompt (str, optional): A prompt for the task to be performed.
42
42
  (default: :obj:`""`)
@@ -104,44 +104,65 @@ class RolePlaying:
104
104
  self.task_prompt = task_prompt
105
105
 
106
106
  self.specified_task_prompt: Optional[TextPrompt] = None
107
- self.init_specified_task_prompt(assistant_role_name, user_role_name,
108
- task_specify_agent_kwargs,
109
- extend_task_specify_meta_dict,
110
- output_language)
107
+ self._init_specified_task_prompt(
108
+ assistant_role_name,
109
+ user_role_name,
110
+ task_specify_agent_kwargs=task_specify_agent_kwargs,
111
+ extend_task_specify_meta_dict=extend_task_specify_meta_dict,
112
+ output_language=output_language,
113
+ )
111
114
 
112
115
  self.planned_task_prompt: Optional[TextPrompt] = None
113
- self.init_planned_task_prompt(task_planner_agent_kwargs,
114
- output_language)
116
+ self._init_planned_task_prompt(
117
+ task_planner_agent_kwargs=task_planner_agent_kwargs,
118
+ output_language=output_language,
119
+ )
115
120
 
116
121
  sys_msg_generator = SystemMessageGenerator(
117
- task_type=self.task_type, **(sys_msg_generator_kwargs or {}))
122
+ task_type=self.task_type,
123
+ **(sys_msg_generator_kwargs or {}),
124
+ )
118
125
 
119
- (init_assistant_sys_msg, init_user_sys_msg,
120
- sys_msg_meta_dicts) = self.get_sys_message_info(
121
- assistant_role_name, user_role_name, sys_msg_generator,
122
- extend_sys_msg_meta_dicts)
126
+ (
127
+ init_assistant_sys_msg,
128
+ init_user_sys_msg,
129
+ sys_msg_meta_dicts,
130
+ ) = self._get_sys_message_info(
131
+ assistant_role_name,
132
+ user_role_name,
133
+ sys_msg_generator,
134
+ extend_sys_msg_meta_dicts=extend_sys_msg_meta_dicts,
135
+ )
123
136
 
124
137
  self.assistant_agent: ChatAgent
125
138
  self.user_agent: ChatAgent
126
139
  self.assistant_sys_msg: BaseMessage
127
140
  self.user_sys_msg: BaseMessage
128
- self.init_agents(
141
+ self._init_agents(
129
142
  init_assistant_sys_msg,
130
- assistant_agent_kwargs,
131
143
  init_user_sys_msg,
132
- user_agent_kwargs,
133
- output_language,
144
+ assistant_agent_kwargs=assistant_agent_kwargs,
145
+ user_agent_kwargs=user_agent_kwargs,
146
+ output_language=output_language,
134
147
  )
135
148
  self.critic: Optional[Union[CriticAgent, Human]] = None
136
149
  self.critic_sys_msg: Optional[BaseMessage] = None
137
- self.init_critic(critic_role_name, critic_criteria, critic_kwargs,
138
- sys_msg_generator, sys_msg_meta_dicts)
139
-
140
- def init_specified_task_prompt(
141
- self, assistant_role_name: str, user_role_name: str,
142
- task_specify_agent_kwargs: Optional[Dict],
143
- extend_task_specify_meta_dict: Optional[Dict],
144
- output_language: Optional[str]):
150
+ self._init_critic(
151
+ sys_msg_generator,
152
+ sys_msg_meta_dicts,
153
+ critic_role_name,
154
+ critic_criteria=critic_criteria,
155
+ critic_kwargs=critic_kwargs,
156
+ )
157
+
158
+ def _init_specified_task_prompt(
159
+ self,
160
+ assistant_role_name: str,
161
+ user_role_name: str,
162
+ task_specify_agent_kwargs: Optional[Dict] = None,
163
+ extend_task_specify_meta_dict: Optional[Dict] = None,
164
+ output_language: Optional[str] = None,
165
+ ) -> None:
145
166
  r"""Use a task specify agent to generate a specified task prompt.
146
167
  Generated specified task prompt will be used to replace original
147
168
  task prompt. If there is no task specify agent, specified task
@@ -152,24 +173,28 @@ class RolePlaying:
152
173
  assistant.
153
174
  user_role_name (str): The name of the role played by the user.
154
175
  task_specify_agent_kwargs (Dict, optional): Additional arguments
155
- to pass to the task specify agent.
176
+ to pass to the task specify agent. (default: :obj:`None`)
156
177
  extend_task_specify_meta_dict (Dict, optional): A dict to extend
157
- the task specify meta dict with.
178
+ the task specify meta dict with. (default: :obj:`None`)
158
179
  output_language (str, optional): The language to be output by the
159
- agents.
180
+ agents. (default: :obj:`None`)
160
181
  """
161
182
  if self.with_task_specify:
162
183
  task_specify_meta_dict = dict()
163
184
  if self.task_type in [TaskType.AI_SOCIETY, TaskType.MISALIGNMENT]:
164
185
  task_specify_meta_dict.update(
165
- dict(assistant_role=assistant_role_name,
166
- user_role=user_role_name))
186
+ dict(
187
+ assistant_role=assistant_role_name,
188
+ user_role=user_role_name,
189
+ )
190
+ )
167
191
  task_specify_meta_dict.update(extend_task_specify_meta_dict or {})
168
192
  if self.model_type is not None:
169
193
  if task_specify_agent_kwargs is None:
170
194
  task_specify_agent_kwargs = {}
171
195
  task_specify_agent_kwargs.update(
172
- dict(model_type=self.model_type))
196
+ dict(model_type=self.model_type)
197
+ )
173
198
  task_specify_agent = TaskSpecifyAgent(
174
199
  task_type=self.task_type,
175
200
  output_language=output_language,
@@ -181,9 +206,11 @@ class RolePlaying:
181
206
  )
182
207
  self.task_prompt = self.specified_task_prompt
183
208
 
184
- def init_planned_task_prompt(self,
185
- task_planner_agent_kwargs: Optional[Dict],
186
- output_language: Optional[str]):
209
+ def _init_planned_task_prompt(
210
+ self,
211
+ task_planner_agent_kwargs: Optional[Dict] = None,
212
+ output_language: Optional[str] = None,
213
+ ) -> None:
187
214
  r"""Use a task plan agent to append a planned task prompt to task
188
215
  prompt. The planned task prompt is generated based on the task
189
216
  prompt, which can be original task prompt or specified task prompt
@@ -192,27 +219,29 @@ class RolePlaying:
192
219
 
193
220
  Args:
194
221
  task_planner_agent_kwargs (Dict, optional): Additional arguments
195
- to pass to the task planner agent.
222
+ to pass to the task planner agent. (default: :obj:`None`)
196
223
  output_language (str, optional): The language to be output by the
197
- agents.
224
+ agents. (default: :obj:`None`)
198
225
  """
199
226
  if self.with_task_planner:
200
227
  if self.model_type is not None:
201
228
  if task_planner_agent_kwargs is None:
202
229
  task_planner_agent_kwargs = {}
203
230
  task_planner_agent_kwargs.update(
204
- dict(model_type=self.model_type))
231
+ dict(model_type=self.model_type)
232
+ )
205
233
  task_planner_agent = TaskPlannerAgent(
206
234
  output_language=output_language,
207
235
  **(task_planner_agent_kwargs or {}),
208
236
  )
209
237
  self.planned_task_prompt = task_planner_agent.run(self.task_prompt)
210
- self.task_prompt = (f"{self.task_prompt}\n"
211
- f"{self.planned_task_prompt}")
238
+ self.task_prompt = (
239
+ f"{self.task_prompt}\n" f"{self.planned_task_prompt}"
240
+ )
212
241
  else:
213
242
  self.planned_task_prompt = None
214
243
 
215
- def get_sys_message_info(
244
+ def _get_sys_message_info(
216
245
  self,
217
246
  assistant_role_name: str,
218
247
  user_role_name: str,
@@ -230,28 +259,33 @@ class RolePlaying:
230
259
  generator for agents.
231
260
  extend_sys_msg_meta_dicts (List[Dict], optional): A list of dicts
232
261
  to extend the system message meta dicts with.
262
+ (default: :obj:`None`)
233
263
 
234
264
  Returns:
235
- A tuple containing a `BaseMessage` representing the assistant's
236
- initial system message, a `BaseMessage` representing the user's
237
- initial system message, and a list of system message meta dicts.
265
+ Tuple[BaseMessage, BaseMessage, List[Dict]]: A tuple containing a
266
+ `BaseMessage` representing the assistant's initial system
267
+ message, a `BaseMessage` representing the user's initial system
268
+ message, and a list of system message meta dicts.
238
269
  """
239
270
  sys_msg_meta_dicts = [dict(task=self.task_prompt) for _ in range(2)]
240
- if (extend_sys_msg_meta_dicts is None and self.task_type in [
241
- TaskType.AI_SOCIETY,
242
- TaskType.MISALIGNMENT,
243
- ]):
271
+ if extend_sys_msg_meta_dicts is None and self.task_type in [
272
+ TaskType.AI_SOCIETY,
273
+ TaskType.MISALIGNMENT,
274
+ ]:
244
275
  extend_sys_msg_meta_dicts = [
245
- dict(assistant_role=assistant_role_name,
246
- user_role=user_role_name) for _ in range(2)
276
+ dict(
277
+ assistant_role=assistant_role_name, user_role=user_role_name
278
+ )
279
+ for _ in range(2)
247
280
  ]
248
281
 
249
282
  if extend_sys_msg_meta_dicts is not None:
250
- sys_msg_meta_dicts = [{
251
- **sys_msg_meta_dict,
252
- **extend_sys_msg_meta_dict
253
- } for sys_msg_meta_dict, extend_sys_msg_meta_dict in zip(
254
- sys_msg_meta_dicts, extend_sys_msg_meta_dicts)]
283
+ sys_msg_meta_dicts = [
284
+ {**sys_msg_meta_dict, **extend_sys_msg_meta_dict}
285
+ for sys_msg_meta_dict, extend_sys_msg_meta_dict in zip(
286
+ sys_msg_meta_dicts, extend_sys_msg_meta_dicts
287
+ )
288
+ ]
255
289
 
256
290
  init_assistant_sys_msg, init_user_sys_msg = (
257
291
  sys_msg_generator.from_dicts(
@@ -260,30 +294,31 @@ class RolePlaying:
260
294
  (assistant_role_name, RoleType.ASSISTANT),
261
295
  (user_role_name, RoleType.USER),
262
296
  ],
263
- ))
297
+ )
298
+ )
264
299
  return init_assistant_sys_msg, init_user_sys_msg, sys_msg_meta_dicts
265
300
 
266
- def init_agents(
301
+ def _init_agents(
267
302
  self,
268
303
  init_assistant_sys_msg: BaseMessage,
269
- assistant_agent_kwargs: Optional[Dict],
270
304
  init_user_sys_msg: BaseMessage,
271
- user_agent_kwargs: Optional[Dict],
272
- output_language: Optional[str],
273
- ):
305
+ assistant_agent_kwargs: Optional[Dict] = None,
306
+ user_agent_kwargs: Optional[Dict] = None,
307
+ output_language: Optional[str] = None,
308
+ ) -> None:
274
309
  r"""Initialize assistant and user agents with their system messages.
275
310
 
276
311
  Args:
277
312
  init_assistant_sys_msg (BaseMessage): Assistant agent's initial
278
313
  system message.
279
- assistant_agent_kwargs (Dict, optional): Additional arguments to
280
- pass to the assistant agent.
281
314
  init_user_sys_msg (BaseMessage): User agent's initial system
282
315
  message.
316
+ assistant_agent_kwargs (Dict, optional): Additional arguments to
317
+ pass to the assistant agent. (default: :obj:`None`)
283
318
  user_agent_kwargs (Dict, optional): Additional arguments to
284
- pass to the user agent.
319
+ pass to the user agent. (default: :obj:`None`)
285
320
  output_language (str, optional): The language to be output by the
286
- agents.
321
+ agents. (default: :obj:`None`)
287
322
  """
288
323
  if self.model_type is not None:
289
324
  if assistant_agent_kwargs is None:
@@ -307,36 +342,42 @@ class RolePlaying:
307
342
  )
308
343
  self.user_sys_msg = self.user_agent.system_message
309
344
 
310
- def init_critic(self, critic_role_name: str,
311
- critic_criteria: Optional[str],
312
- critic_kwargs: Optional[Dict],
313
- sys_msg_generator: SystemMessageGenerator,
314
- sys_msg_meta_dicts: List[Dict]):
345
+ def _init_critic(
346
+ self,
347
+ sys_msg_generator: SystemMessageGenerator,
348
+ sys_msg_meta_dicts: List[Dict],
349
+ critic_role_name: str,
350
+ critic_criteria: Optional[str] = None,
351
+ critic_kwargs: Optional[Dict] = None,
352
+ ) -> None:
315
353
  r"""Initialize critic agent. If critic role name is :obj:`"human"`,
316
354
  create a :obj:`Human` critic agent. Else, create a :obj:`CriticAgent`
317
355
  critic agent with specified critic criteria. If the critic criteria
318
356
  is not specified, set it to improve task performance.
319
357
 
320
358
  Args:
359
+ sys_msg_generator (SystemMessageGenerator): A system message
360
+ generator for agents.
361
+ sys_msg_meta_dicts (list): A list of system message meta dicts.
321
362
  critic_role_name (str): The name of the role played by the critic.
322
363
  critic_criteria (str, optional): Critic criteria for the
323
364
  critic agent. If not specified, set the criteria to
324
- improve task performance.
365
+ improve task performance. (default: :obj:`None`)
325
366
  critic_kwargs (Dict, optional): Additional arguments to
326
- pass to the critic.
327
- sys_msg_generator (SystemMessageGenerator): A system message
328
- generator for agents.
329
- sys_msg_meta_dicts (list): A list of system message meta dicts.
367
+ pass to the critic. (default: :obj:`None`)
330
368
  """
331
369
  if self.with_critic_in_the_loop:
332
370
  if critic_role_name.lower() == "human":
333
371
  self.critic = Human(**(critic_kwargs or {}))
334
372
  else:
335
- critic_criteria = (critic_criteria
336
- or "improving the task performance")
337
- critic_msg_meta_dict = dict(critic_role=critic_role_name,
338
- criteria=critic_criteria,
339
- **sys_msg_meta_dicts[0])
373
+ critic_criteria = (
374
+ critic_criteria or "improving the task performance"
375
+ )
376
+ critic_msg_meta_dict = dict(
377
+ critic_role=critic_role_name,
378
+ criteria=critic_criteria,
379
+ **sys_msg_meta_dicts[0],
380
+ )
340
381
  self.critic_sys_msg = sys_msg_generator.from_dict(
341
382
  critic_msg_meta_dict,
342
383
  role_tuple=(critic_role_name, RoleType.CRITIC),
@@ -350,37 +391,7 @@ class RolePlaying:
350
391
  **(critic_kwargs or {}),
351
392
  )
352
393
 
353
- def init_chat(self) -> Tuple[BaseMessage, List[BaseMessage]]:
354
- r"""Initializes the chat by resetting both of the assistant and user
355
- agents, and sending the system messages again to the agents using
356
- chat messages. Returns the assistant's introductory message and the
357
- user's response messages.
358
-
359
- Returns:
360
- A tuple containing a `BaseMessage` representing the assistant's
361
- introductory message, and a list of `BaseMessage` representing
362
- the user's response messages.
363
- """
364
- self.assistant_agent.reset()
365
- self.user_agent.reset()
366
-
367
- # Send the system messages again to the agents using chat messages
368
- assistant_msg = BaseMessage.make_assistant_message(
369
- role_name=self.assistant_sys_msg.role_name,
370
- content=(f"{self.user_sys_msg.content}. "
371
- "Now start to give me instructions one by one. "
372
- "Only reply with Instruction and Input."))
373
- user_msg = BaseMessage.make_user_message(
374
- role_name=self.user_sys_msg.role_name,
375
- content=f"{self.assistant_sys_msg.content}")
376
- assistant_response = self.assistant_agent.step(user_msg)
377
- if assistant_response.terminated or assistant_response.msgs is None:
378
- raise ValueError(f"Assistant agent terminated unexpectedly. "
379
- f"Error info: {assistant_response.info}")
380
-
381
- return assistant_msg, assistant_response.msgs
382
-
383
- def reduce_message_options(
394
+ def _reduce_message_options(
384
395
  self,
385
396
  messages: Sequence[BaseMessage],
386
397
  ) -> BaseMessage:
@@ -390,16 +401,20 @@ class RolePlaying:
390
401
  If no messages are provided, a `ValueError` will be raised.
391
402
 
392
403
  Args:
393
- messages: A sequence of `BaseMessage` objects to process.
404
+ messages (Sequence[BaseMessage]): A sequence of `BaseMessage`
405
+ objects to process.
394
406
 
395
407
  Returns:
396
- A single `BaseMessage` representing the processed message.
408
+ BaseMessage: A single `BaseMessage` representing the processed
409
+ message.
397
410
  """
398
411
  if len(messages) == 0:
399
412
  raise ValueError("No messages to process.")
400
413
  if len(messages) > 1 and not self.with_critic_in_the_loop:
401
- raise ValueError("Got than one message to process. "
402
- f"Num of messages: {len(messages)}.")
414
+ raise ValueError(
415
+ "Got than one message to process. "
416
+ f"Num of messages: {len(messages)}."
417
+ )
403
418
  elif self.with_critic_in_the_loop and self.critic is not None:
404
419
  critic_response = self.critic.reduce_step(messages)
405
420
  processed_msg = critic_response.msg
@@ -408,6 +423,35 @@ class RolePlaying:
408
423
 
409
424
  return processed_msg
410
425
 
426
+ def init_chat(self, init_msg_content: Optional[str] = None) -> BaseMessage:
427
+ r"""Initializes the chat by resetting both of the assistant and user
428
+ agents. Returns an initial message for the role-playing session.
429
+
430
+ Args:
431
+ init_msg_content (str, optional): A user-specified initial message.
432
+ Will be sent to the role-playing session as the initial
433
+ message. (default: :obj:`None`)
434
+
435
+ Returns:
436
+ BaseMessage: A single `BaseMessage` representing the initial
437
+ message.
438
+ """
439
+ self.assistant_agent.reset()
440
+ self.user_agent.reset()
441
+ default_init_msg_content = (
442
+ "Now start to give me instructions one by one. "
443
+ "Only reply with Instruction and Input."
444
+ )
445
+ if init_msg_content is None:
446
+ init_msg_content = default_init_msg_content
447
+ # Initialize a message sent by the assistant
448
+ init_msg = BaseMessage.make_assistant_message(
449
+ role_name=self.assistant_sys_msg.role_name,
450
+ content=init_msg_content,
451
+ )
452
+
453
+ return init_msg
454
+
411
455
  def step(
412
456
  self,
413
457
  assistant_msg: BaseMessage,
@@ -425,32 +469,43 @@ class RolePlaying:
425
469
  assistant.
426
470
 
427
471
  Returns:
428
- A tuple containing two ChatAgentResponse: the first struct contains
429
- the resulting assistant message, whether the assistant agent
430
- terminated the conversation, and any additional assistant
431
- information; the second struct contains the resulting user message,
432
- whether the user agent terminated the conversation, and any
433
- additional user information.
472
+ Tuple[ChatAgentResponse, ChatAgentResponse]: A tuple containing two
473
+ ChatAgentResponse: the first struct contains the resulting
474
+ assistant message, whether the assistant agent terminated the
475
+ conversation, and any additional assistant information; the
476
+ second struct contains the resulting user message, whether the
477
+ user agent terminated the conversation, and any additional user
478
+ information.
434
479
  """
435
480
  user_response = self.user_agent.step(assistant_msg)
436
481
  if user_response.terminated or user_response.msgs is None:
437
- return (ChatAgentResponse([], False, {}),
438
- ChatAgentResponse([], user_response.terminated,
439
- user_response.info))
440
- user_msg = self.reduce_message_options(user_response.msgs)
482
+ return (
483
+ ChatAgentResponse([], False, {}),
484
+ ChatAgentResponse(
485
+ [], user_response.terminated, user_response.info
486
+ ),
487
+ )
488
+ user_msg = self._reduce_message_options(user_response.msgs)
441
489
  self.user_agent.record_message(user_msg)
442
490
 
443
491
  assistant_response = self.assistant_agent.step(user_msg)
444
492
  if assistant_response.terminated or assistant_response.msgs is None:
445
- return (ChatAgentResponse([], assistant_response.terminated,
446
- assistant_response.info),
447
- ChatAgentResponse([user_msg], False, user_response.info))
448
- assistant_msg = self.reduce_message_options(assistant_response.msgs)
493
+ return (
494
+ ChatAgentResponse(
495
+ [], assistant_response.terminated, assistant_response.info
496
+ ),
497
+ ChatAgentResponse([user_msg], False, user_response.info),
498
+ )
499
+ assistant_msg = self._reduce_message_options(assistant_response.msgs)
449
500
  self.assistant_agent.record_message(assistant_msg)
450
501
 
451
502
  return (
452
- ChatAgentResponse([assistant_msg], assistant_response.terminated,
453
- assistant_response.info),
454
- ChatAgentResponse([user_msg], user_response.terminated,
455
- user_response.info),
503
+ ChatAgentResponse(
504
+ [assistant_msg],
505
+ assistant_response.terminated,
506
+ assistant_response.info,
507
+ ),
508
+ ChatAgentResponse(
509
+ [user_msg], user_response.terminated, user_response.info
510
+ ),
456
511
  )
@@ -12,12 +12,30 @@
12
12
  # limitations under the License.
13
13
  # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
14
14
 
15
+ from .graph_storages.base import BaseGraphStorage
16
+ from .graph_storages.neo4j_graph import Neo4jGraph
15
17
  from .key_value_storages.base import BaseKeyValueStorage
16
18
  from .key_value_storages.in_memory import InMemoryKeyValueStorage
17
19
  from .key_value_storages.json import JsonStorage
20
+ from .vectordb_storages.base import (
21
+ BaseVectorStorage,
22
+ VectorDBQuery,
23
+ VectorDBQueryResult,
24
+ VectorRecord,
25
+ )
26
+ from .vectordb_storages.milvus import MilvusStorage
27
+ from .vectordb_storages.qdrant import QdrantStorage
18
28
 
19
29
  __all__ = [
20
30
  'BaseKeyValueStorage',
21
31
  'InMemoryKeyValueStorage',
22
32
  'JsonStorage',
33
+ 'VectorRecord',
34
+ 'BaseVectorStorage',
35
+ 'VectorDBQuery',
36
+ 'VectorDBQueryResult',
37
+ 'QdrantStorage',
38
+ 'MilvusStorage',
39
+ 'BaseGraphStorage',
40
+ 'Neo4jGraph',
23
41
  ]
@@ -0,0 +1,23 @@
1
+ # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
+ # Licensed under the Apache License, Version 2.0 (the “License”);
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an “AS IS” BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
14
+
15
+ from .base import BaseGraphStorage
16
+ from .graph_element import GraphElement
17
+ from .neo4j_graph import Neo4jGraph
18
+
19
+ __all__ = [
20
+ 'BaseGraphStorage',
21
+ 'GraphElement',
22
+ 'Neo4jGraph',
23
+ ]
@@ -0,0 +1,82 @@
1
+ # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
+ # Licensed under the Apache License, Version 2.0 (the “License”);
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an “AS IS” BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
14
+
15
+ from abc import ABC, abstractmethod
16
+ from typing import Any, Dict, List, Optional
17
+
18
+
19
+ class BaseGraphStorage(ABC):
20
+ r"""An abstract base class for graph storage systems."""
21
+
22
+ @property
23
+ @abstractmethod
24
+ def get_client(self) -> Any:
25
+ r"""Get the underlying graph storage client."""
26
+ pass
27
+
28
+ @property
29
+ @abstractmethod
30
+ def get_schema(self) -> str:
31
+ r"""Get the schema of the graph storage"""
32
+ pass
33
+
34
+ @property
35
+ @abstractmethod
36
+ def get_structured_schema(self) -> Dict[str, Any]:
37
+ r"""Get the structured schema of the graph storage"""
38
+ pass
39
+
40
+ @abstractmethod
41
+ def refresh_schema(self) -> None:
42
+ r"""Refreshes the graph schema information."""
43
+ pass
44
+
45
+ @abstractmethod
46
+ def add_triplet(self, subj: str, obj: str, rel: str) -> None:
47
+ r"""Adds a relationship (triplet) between two entities in the database.
48
+
49
+ Args:
50
+ subj (str): The identifier for the subject entity.
51
+ obj (str): The identifier for the object entity.
52
+ rel (str): The relationship between the subject and object.
53
+ """
54
+ pass
55
+
56
+ @abstractmethod
57
+ def delete_triplet(self, subj: str, obj: str, rel: str) -> None:
58
+ r"""Deletes a specific triplet from the graph, comprising a subject,
59
+ object and relationship.
60
+
61
+ Args:
62
+ subj (str): The identifier for the subject entity.
63
+ obj (str): The identifier for the object entity.
64
+ rel (str): The relationship between the subject and object.
65
+ """
66
+ pass
67
+
68
+ @abstractmethod
69
+ def query(
70
+ self, query: str, params: Optional[Dict[str, Any]] = None
71
+ ) -> List[Dict[str, Any]]:
72
+ r"""Query the graph store with statement and parameters.
73
+ Args:
74
+ query (str): The query to be executed.
75
+ params (Optional[Dict[str, Any]]): A dictionary of parameters to
76
+ be used in the query. Defaults to `None`.
77
+
78
+ Returns:
79
+ List[Dict[str, Any]]: A list of dictionaries, each
80
+ dictionary represents a row of results from the query.
81
+ """
82
+ pass