camel-ai 0.2.18__py3-none-any.whl → 0.2.20__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.
- camel/__init__.py +1 -1
- camel/agents/chat_agent.py +29 -30
- camel/agents/knowledge_graph_agent.py +1 -5
- camel/agents/multi_hop_generator_agent.py +35 -3
- camel/agents/programmed_agent_instruction.py +73 -18
- camel/benchmarks/apibench.py +1 -5
- camel/benchmarks/nexus.py +1 -5
- camel/benchmarks/ragbench.py +2 -2
- camel/bots/telegram_bot.py +1 -5
- camel/configs/__init__.py +9 -0
- camel/configs/aiml_config.py +80 -0
- camel/configs/gemini_config.py +1 -1
- camel/configs/moonshot_config.py +63 -0
- camel/configs/sglang_config.py +4 -0
- camel/configs/siliconflow_config.py +91 -0
- camel/datagen/__init__.py +3 -1
- camel/datagen/self_improving_cot.py +821 -0
- camel/datagen/source2synth/__init__.py +31 -0
- camel/{synthetic_datagen → datagen}/source2synth/data_processor.py +194 -29
- camel/{synthetic_datagen → datagen}/source2synth/models.py +25 -0
- camel/{synthetic_datagen → datagen}/source2synth/user_data_processor_config.py +9 -8
- camel/datahubs/huggingface.py +3 -3
- camel/embeddings/__init__.py +2 -0
- camel/embeddings/jina_embedding.py +161 -0
- camel/messages/func_message.py +1 -1
- camel/models/__init__.py +4 -0
- camel/models/aiml_model.py +147 -0
- camel/models/deepseek_model.py +29 -11
- camel/models/groq_model.py +0 -2
- camel/models/model_factory.py +9 -0
- camel/models/moonshot_model.py +138 -0
- camel/models/openai_model.py +1 -9
- camel/models/siliconflow_model.py +142 -0
- camel/societies/workforce/role_playing_worker.py +2 -4
- camel/societies/workforce/single_agent_worker.py +1 -6
- camel/societies/workforce/workforce.py +3 -9
- camel/toolkits/__init__.py +4 -0
- camel/toolkits/reddit_toolkit.py +8 -38
- camel/toolkits/search_toolkit.py +17 -6
- camel/toolkits/semantic_scholar_toolkit.py +308 -0
- camel/toolkits/sympy_toolkit.py +778 -0
- camel/toolkits/whatsapp_toolkit.py +11 -32
- camel/types/enums.py +205 -16
- camel/types/unified_model_type.py +5 -0
- camel/utils/__init__.py +7 -2
- camel/utils/commons.py +198 -21
- camel/utils/deduplication.py +199 -0
- camel/utils/token_counting.py +1 -39
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20.dist-info}/METADATA +17 -12
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20.dist-info}/RECORD +53 -41
- /camel/datagen/{cotdatagen.py → cot_datagen.py} +0 -0
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20.dist-info}/LICENSE +0 -0
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20.dist-info}/WHEEL +0 -0
camel/__init__.py
CHANGED
camel/agents/chat_agent.py
CHANGED
|
@@ -86,18 +86,18 @@ except (ImportError, AttributeError):
|
|
|
86
86
|
from camel.utils import track_agent
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
class
|
|
90
|
-
r"""Historical records of
|
|
89
|
+
class ToolCallingRecord(BaseModel):
|
|
90
|
+
r"""Historical records of tools called in the conversation.
|
|
91
91
|
|
|
92
92
|
Attributes:
|
|
93
|
-
|
|
93
|
+
tool_name (str): The name of the tool being called.
|
|
94
94
|
args (Dict[str, Any]): The dictionary of arguments passed to
|
|
95
|
-
the
|
|
96
|
-
result (Any): The execution result of calling this
|
|
95
|
+
the tools.
|
|
96
|
+
result (Any): The execution result of calling this tool.
|
|
97
97
|
tool_call_id (str): The ID of the tool call, if available.
|
|
98
98
|
"""
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
tool_name: str
|
|
101
101
|
args: Dict[str, Any]
|
|
102
102
|
result: Any
|
|
103
103
|
tool_call_id: str
|
|
@@ -106,10 +106,10 @@ class FunctionCallingRecord(BaseModel):
|
|
|
106
106
|
r"""Overridden version of the string function.
|
|
107
107
|
|
|
108
108
|
Returns:
|
|
109
|
-
str: Modified string to represent the
|
|
109
|
+
str: Modified string to represent the tool calling.
|
|
110
110
|
"""
|
|
111
111
|
return (
|
|
112
|
-
f"
|
|
112
|
+
f"Tool Execution: {self.tool_name}\n"
|
|
113
113
|
f"\tArgs: {self.args}\n"
|
|
114
114
|
f"\tResult: {self.result}\n"
|
|
115
115
|
)
|
|
@@ -489,7 +489,7 @@ class ChatAgent(BaseAgent):
|
|
|
489
489
|
usage: Optional[Dict[str, int]],
|
|
490
490
|
termination_reasons: List[str],
|
|
491
491
|
num_tokens: int,
|
|
492
|
-
tool_calls: List[
|
|
492
|
+
tool_calls: List[ToolCallingRecord],
|
|
493
493
|
external_tool_request: Optional[ChatCompletionMessageToolCall] = None,
|
|
494
494
|
) -> Dict[str, Any]:
|
|
495
495
|
r"""Returns a dictionary containing information about the chat session.
|
|
@@ -501,7 +501,7 @@ class ChatAgent(BaseAgent):
|
|
|
501
501
|
termination_reasons (List[str]): The reasons for the termination
|
|
502
502
|
of the chat session.
|
|
503
503
|
num_tokens (int): The number of tokens used in the chat session.
|
|
504
|
-
tool_calls (List[
|
|
504
|
+
tool_calls (List[ToolCallingRecord]): The list of function
|
|
505
505
|
calling records, containing the information of called tools.
|
|
506
506
|
external_tool_request
|
|
507
507
|
(Optional[ChatCompletionMessageToolCall], optional):
|
|
@@ -573,9 +573,8 @@ class ChatAgent(BaseAgent):
|
|
|
573
573
|
self.model_backend.model_config_dict.get("response_format")
|
|
574
574
|
and response_format
|
|
575
575
|
):
|
|
576
|
-
|
|
577
|
-
"
|
|
578
|
-
"the model configuration and in the ChatAgent step."
|
|
576
|
+
logger.warning(
|
|
577
|
+
f"Overriding the response format with {response_format}."
|
|
579
578
|
)
|
|
580
579
|
|
|
581
580
|
self.original_model_dict = self.model_backend.model_config_dict
|
|
@@ -645,7 +644,7 @@ class ChatAgent(BaseAgent):
|
|
|
645
644
|
)
|
|
646
645
|
|
|
647
646
|
# Record function calls made during the session
|
|
648
|
-
tool_call_records: List[
|
|
647
|
+
tool_call_records: List[ToolCallingRecord] = []
|
|
649
648
|
|
|
650
649
|
external_tool_request = None
|
|
651
650
|
|
|
@@ -885,7 +884,7 @@ class ChatAgent(BaseAgent):
|
|
|
885
884
|
|
|
886
885
|
self.update_memory(input_message, OpenAIBackendRole.USER)
|
|
887
886
|
|
|
888
|
-
tool_call_records: List[
|
|
887
|
+
tool_call_records: List[ToolCallingRecord] = []
|
|
889
888
|
while True:
|
|
890
889
|
try:
|
|
891
890
|
openai_messages, num_tokens = self.memory.get_context()
|
|
@@ -970,7 +969,7 @@ class ChatAgent(BaseAgent):
|
|
|
970
969
|
|
|
971
970
|
def _step_tool_call_and_update(
|
|
972
971
|
self, response: ChatCompletion
|
|
973
|
-
) ->
|
|
972
|
+
) -> ToolCallingRecord:
|
|
974
973
|
r"""Processes a function call within the chat completion response,
|
|
975
974
|
records the function call in the provided list of tool calls and
|
|
976
975
|
updates the memory of the current agent.
|
|
@@ -980,7 +979,7 @@ class ChatAgent(BaseAgent):
|
|
|
980
979
|
completion.
|
|
981
980
|
|
|
982
981
|
Returns:
|
|
983
|
-
|
|
982
|
+
ToolCallingRecord: The record of calling the function.
|
|
984
983
|
"""
|
|
985
984
|
|
|
986
985
|
# Perform function calling
|
|
@@ -996,7 +995,7 @@ class ChatAgent(BaseAgent):
|
|
|
996
995
|
|
|
997
996
|
async def _step_tool_call_and_update_async(
|
|
998
997
|
self, response: ChatCompletion
|
|
999
|
-
) ->
|
|
998
|
+
) -> ToolCallingRecord:
|
|
1000
999
|
(
|
|
1001
1000
|
func_assistant_msg,
|
|
1002
1001
|
func_result_msg,
|
|
@@ -1015,7 +1014,7 @@ class ChatAgent(BaseAgent):
|
|
|
1015
1014
|
List[str],
|
|
1016
1015
|
Dict[str, int],
|
|
1017
1016
|
str,
|
|
1018
|
-
|
|
1017
|
+
ToolCallingRecord,
|
|
1019
1018
|
int,
|
|
1020
1019
|
]:
|
|
1021
1020
|
r"""Internal function of structuring the output of the agent based on
|
|
@@ -1027,7 +1026,7 @@ class ChatAgent(BaseAgent):
|
|
|
1027
1026
|
|
|
1028
1027
|
Returns:
|
|
1029
1028
|
Tuple[List[BaseMessage], List[str], Dict[str, int], str,
|
|
1030
|
-
|
|
1029
|
+
ToolCallingRecord, int]:
|
|
1031
1030
|
A tuple containing the output messages, finish reasons, usage
|
|
1032
1031
|
dictionary, response ID, function calling record, and number of
|
|
1033
1032
|
tokens.
|
|
@@ -1141,7 +1140,7 @@ class ChatAgent(BaseAgent):
|
|
|
1141
1140
|
finish_reasons: List[str],
|
|
1142
1141
|
usage_dict: Dict[str, int],
|
|
1143
1142
|
response_id: str,
|
|
1144
|
-
tool_calls: List[
|
|
1143
|
+
tool_calls: List[ToolCallingRecord],
|
|
1145
1144
|
num_tokens: int,
|
|
1146
1145
|
external_tool_request: Optional[ChatCompletionMessageToolCall] = None,
|
|
1147
1146
|
) -> Dict[str, Any]:
|
|
@@ -1160,7 +1159,7 @@ class ChatAgent(BaseAgent):
|
|
|
1160
1159
|
usage_dict (Dict[str, int]): Dictionary containing token usage
|
|
1161
1160
|
information.
|
|
1162
1161
|
response_id (str): The ID of the response from the model.
|
|
1163
|
-
tool_calls (List[
|
|
1162
|
+
tool_calls (List[ToolCallingRecord]): Records of function calls
|
|
1164
1163
|
made during this step.
|
|
1165
1164
|
num_tokens (int): The number of tokens used in this step.
|
|
1166
1165
|
external_tool_request (Optional[ChatCompletionMessageToolCall]):
|
|
@@ -1335,7 +1334,7 @@ class ChatAgent(BaseAgent):
|
|
|
1335
1334
|
def _step_token_exceed(
|
|
1336
1335
|
self,
|
|
1337
1336
|
num_tokens: int,
|
|
1338
|
-
tool_calls: List[
|
|
1337
|
+
tool_calls: List[ToolCallingRecord],
|
|
1339
1338
|
termination_reason: str,
|
|
1340
1339
|
) -> ChatAgentResponse:
|
|
1341
1340
|
r"""Return trivial response containing number of tokens and information
|
|
@@ -1343,7 +1342,7 @@ class ChatAgent(BaseAgent):
|
|
|
1343
1342
|
|
|
1344
1343
|
Args:
|
|
1345
1344
|
num_tokens (int): Number of tokens in the messages.
|
|
1346
|
-
tool_calls (List[
|
|
1345
|
+
tool_calls (List[ToolCallingRecord]): List of information
|
|
1347
1346
|
objects of functions called in the current step.
|
|
1348
1347
|
termination_reason (str): String of termination reason.
|
|
1349
1348
|
|
|
@@ -1372,7 +1371,7 @@ class ChatAgent(BaseAgent):
|
|
|
1372
1371
|
self,
|
|
1373
1372
|
response: ChatCompletion,
|
|
1374
1373
|
) -> Tuple[
|
|
1375
|
-
FunctionCallingMessage, FunctionCallingMessage,
|
|
1374
|
+
FunctionCallingMessage, FunctionCallingMessage, ToolCallingRecord
|
|
1376
1375
|
]:
|
|
1377
1376
|
r"""Execute the function with arguments following the model's response.
|
|
1378
1377
|
|
|
@@ -1418,8 +1417,8 @@ class ChatAgent(BaseAgent):
|
|
|
1418
1417
|
)
|
|
1419
1418
|
|
|
1420
1419
|
# Record information about this function call
|
|
1421
|
-
func_record =
|
|
1422
|
-
|
|
1420
|
+
func_record = ToolCallingRecord(
|
|
1421
|
+
tool_name=func_name,
|
|
1423
1422
|
args=args,
|
|
1424
1423
|
result=result,
|
|
1425
1424
|
tool_call_id=tool_call_id,
|
|
@@ -1442,7 +1441,7 @@ class ChatAgent(BaseAgent):
|
|
|
1442
1441
|
self,
|
|
1443
1442
|
response: ChatCompletion,
|
|
1444
1443
|
) -> Tuple[
|
|
1445
|
-
FunctionCallingMessage, FunctionCallingMessage,
|
|
1444
|
+
FunctionCallingMessage, FunctionCallingMessage, ToolCallingRecord
|
|
1446
1445
|
]:
|
|
1447
1446
|
r"""Execute the async function with arguments following the model's
|
|
1448
1447
|
response.
|
|
@@ -1488,8 +1487,8 @@ class ChatAgent(BaseAgent):
|
|
|
1488
1487
|
)
|
|
1489
1488
|
|
|
1490
1489
|
# Record information about this function call
|
|
1491
|
-
func_record =
|
|
1492
|
-
|
|
1490
|
+
func_record = ToolCallingRecord(
|
|
1491
|
+
tool_name=func_name,
|
|
1493
1492
|
args=args,
|
|
1494
1493
|
result=result,
|
|
1495
1494
|
tool_call_id=tool_call_id,
|
|
@@ -165,11 +165,7 @@ class KnowledgeGraphAgent(ChatAgent):
|
|
|
165
165
|
task=str(element)
|
|
166
166
|
)
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
role_name="Graphify", content=knowledge_graph_generation
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
response = self.step(input_message=knowledge_graph_generation_msg)
|
|
168
|
+
response = self.step(input_message=knowledge_graph_generation)
|
|
173
169
|
|
|
174
170
|
content = response.msg.content
|
|
175
171
|
|
|
@@ -22,17 +22,36 @@ from camel.agents.programmed_agent_instruction import (
|
|
|
22
22
|
ProgrammedAgentInstructionResult,
|
|
23
23
|
programmable_capability,
|
|
24
24
|
)
|
|
25
|
-
from camel.
|
|
26
|
-
from camel.synthetic_datagen.source2synth.models import (
|
|
25
|
+
from camel.datagen.source2synth.models import (
|
|
27
26
|
ContextPrompt,
|
|
28
27
|
MultiHopQA,
|
|
29
28
|
)
|
|
29
|
+
from camel.messages import BaseMessage
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
class MultiHopGeneratorAgent(ProgrammableChatAgent):
|
|
33
|
+
r"""An agent specialized in generating multi-hop question-answer pairs.
|
|
34
|
+
|
|
35
|
+
This agent is designed to create complex questions that require multiple
|
|
36
|
+
steps of reasoning to answer. It analyzes context to identify related
|
|
37
|
+
facts and generates questions that require connecting these facts
|
|
38
|
+
logically.
|
|
39
|
+
|
|
40
|
+
Attributes:
|
|
41
|
+
model_config (ConfigDict): Configuration for model behavior.
|
|
42
|
+
system_message (BaseMessage): System message defining agent's role and
|
|
43
|
+
instructions.
|
|
44
|
+
"""
|
|
45
|
+
|
|
33
46
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
34
47
|
|
|
35
|
-
def __init__(self, **kwargs: Any):
|
|
48
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
49
|
+
r"""Initialize the MultiHopGeneratorAgent.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
**kwargs (Any): Additional keyword arguments to pass to parent
|
|
53
|
+
class.
|
|
54
|
+
"""
|
|
36
55
|
super().__init__(**kwargs)
|
|
37
56
|
|
|
38
57
|
system_text: str = textwrap.dedent(
|
|
@@ -64,6 +83,19 @@ class MultiHopGeneratorAgent(ProgrammableChatAgent):
|
|
|
64
83
|
def generate_multi_hop_qa(
|
|
65
84
|
self, context: str
|
|
66
85
|
) -> ProgrammedAgentInstructionResult[MultiHopQA]:
|
|
86
|
+
r"""Generate a multi-hop question-answer pair from given context.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
context (str): The input text context to generate QA from.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
ProgrammedAgentInstructionResult[MultiHopQA]: Result containing the
|
|
93
|
+
generated question, reasoning steps, answer, and supporting
|
|
94
|
+
facts.
|
|
95
|
+
|
|
96
|
+
Raises:
|
|
97
|
+
RuntimeError: If the agent fails to generate a response.
|
|
98
|
+
"""
|
|
67
99
|
context_prompt = ContextPrompt(
|
|
68
100
|
main_context=context, related_contexts=None
|
|
69
101
|
)
|
|
@@ -26,6 +26,16 @@ T = TypeVar('T')
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
class ProgrammableAgentRequirement(Enum):
|
|
29
|
+
r"""Requirements for programmable agent state.
|
|
30
|
+
|
|
31
|
+
Defines the possible requirements that can be used to repair the state
|
|
32
|
+
of a programmable agent.
|
|
33
|
+
|
|
34
|
+
Attributes:
|
|
35
|
+
LAST_MESSAGE_NOT_USER (str): Requires that the last message in the
|
|
36
|
+
conversation was not from the user.
|
|
37
|
+
"""
|
|
38
|
+
|
|
29
39
|
LAST_MESSAGE_NOT_USER = "LAST_MESSAGE_NOT_USER"
|
|
30
40
|
|
|
31
41
|
|
|
@@ -34,6 +44,11 @@ class ProgrammedAgentInstructionResult(BaseModel, Generic[T]):
|
|
|
34
44
|
|
|
35
45
|
Contains the messages exchanged during execution and the computed value.
|
|
36
46
|
The value type is specified by the generic type parameter T.
|
|
47
|
+
|
|
48
|
+
Attributes:
|
|
49
|
+
user_message (BaseMessage): The message sent by the user.
|
|
50
|
+
agent_message (BaseMessage): The message sent by the agent.
|
|
51
|
+
value (T): The computed result value of type T.
|
|
37
52
|
"""
|
|
38
53
|
|
|
39
54
|
user_message: BaseMessage
|
|
@@ -48,8 +63,7 @@ class AbstractProgrammableAgent(abc.ABC):
|
|
|
48
63
|
|
|
49
64
|
A programmable agent is an agent that can be programmed to perform a
|
|
50
65
|
specific function or task. This class defines the interface for a
|
|
51
|
-
programmable
|
|
52
|
-
agent.
|
|
66
|
+
programmable agent.
|
|
53
67
|
|
|
54
68
|
These methods should be implemented in order to ensure the agent supports
|
|
55
69
|
the necessary guarantees to enable a programming interface while
|
|
@@ -68,16 +82,15 @@ class AbstractProgrammableAgent(abc.ABC):
|
|
|
68
82
|
An atomic operation is an operation that is guaranteed to
|
|
69
83
|
be executed without interruption by any other operation.
|
|
70
84
|
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
Args:
|
|
86
|
+
callback (Callable[[], ProgrammedAgentInstructionResult[T]]): The
|
|
87
|
+
operation to execute atomically.
|
|
73
88
|
|
|
74
|
-
|
|
75
|
-
|
|
89
|
+
Returns:
|
|
90
|
+
ProgrammedAgentInstructionResult[T]: The result of the operation.
|
|
76
91
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
operation again. Though if state changes in successful operation
|
|
80
|
-
improve its ability to perform the operation, it should keep them.
|
|
92
|
+
Raises:
|
|
93
|
+
RuntimeError: If an operation is already in progress.
|
|
81
94
|
"""
|
|
82
95
|
raise NotImplementedError
|
|
83
96
|
|
|
@@ -86,10 +99,13 @@ class AbstractProgrammableAgent(abc.ABC):
|
|
|
86
99
|
r"""Repair the state of the agent.
|
|
87
100
|
|
|
88
101
|
Agents may have other non-atomic interfaces, such as a user interface,
|
|
89
|
-
or chat between other agents.
|
|
102
|
+
or chat between other agents. This method should restore the agent to
|
|
103
|
+
a state where it can perform operations according to the specified
|
|
104
|
+
requirement.
|
|
90
105
|
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
Args:
|
|
107
|
+
requirement (ProgrammableAgentRequirement): The requirement to
|
|
108
|
+
repair the state for.
|
|
93
109
|
"""
|
|
94
110
|
raise NotImplementedError
|
|
95
111
|
|
|
@@ -99,10 +115,16 @@ def programmable_capability(
|
|
|
99
115
|
) -> Callable[..., ProgrammedAgentInstructionResult[T]]:
|
|
100
116
|
r"""Decorator for programmable agent capabilities.
|
|
101
117
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
This decorator ensures that the decorated method is executed atomically
|
|
119
|
+
and maintains the agent's state guarantees.
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
func (Callable[..., ProgrammedAgentInstructionResult[T]]): The method
|
|
123
|
+
to decorate.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
Callable[..., ProgrammedAgentInstructionResult[T]]: The decorated
|
|
127
|
+
method that ensures atomic execution.
|
|
106
128
|
"""
|
|
107
129
|
|
|
108
130
|
@wraps(func)
|
|
@@ -120,9 +142,20 @@ class ProgrammableChatAgent(ChatAgent, AbstractProgrammableAgent):
|
|
|
120
142
|
Provides a default implementation of atomic execution using threading locks
|
|
121
143
|
and basic state tracking for message roles. Implementing classes need to
|
|
122
144
|
provide specific repair logic for their use cases.
|
|
145
|
+
|
|
146
|
+
Attributes:
|
|
147
|
+
_operation_lock (threading.Lock): Lock for ensuring atomic operations.
|
|
148
|
+
_last_message_role (Optional[str]): Role of the last message in the
|
|
149
|
+
conversation.
|
|
123
150
|
"""
|
|
124
151
|
|
|
125
|
-
def __init__(self, **kwargs: Any):
|
|
152
|
+
def __init__(self, **kwargs: Any) -> None:
|
|
153
|
+
r"""Initialize the ProgrammableChatAgent.
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
**kwargs (Any): Additional keyword arguments to pass to parent
|
|
157
|
+
class.
|
|
158
|
+
"""
|
|
126
159
|
super().__init__(**kwargs)
|
|
127
160
|
self._operation_lock = threading.Lock()
|
|
128
161
|
self._last_message_role: Optional[str] = None
|
|
@@ -130,6 +163,20 @@ class ProgrammableChatAgent(ChatAgent, AbstractProgrammableAgent):
|
|
|
130
163
|
def run_atomic(
|
|
131
164
|
self, callback: Callable[[], ProgrammedAgentInstructionResult[T]]
|
|
132
165
|
) -> ProgrammedAgentInstructionResult[T]:
|
|
166
|
+
r"""Run an atomic operation on the agent.
|
|
167
|
+
|
|
168
|
+
Ensures thread-safe execution of the callback function by using a lock.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
callback (Callable[[], ProgrammedAgentInstructionResult[T]]): The
|
|
172
|
+
operation to execute atomically.
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
ProgrammedAgentInstructionResult[T]: The result of the operation.
|
|
176
|
+
|
|
177
|
+
Raises:
|
|
178
|
+
RuntimeError: If an operation is already in progress.
|
|
179
|
+
"""
|
|
133
180
|
if not self._operation_lock.acquire(blocking=False):
|
|
134
181
|
raise RuntimeError("Operation already in progress")
|
|
135
182
|
|
|
@@ -141,6 +188,14 @@ class ProgrammableChatAgent(ChatAgent, AbstractProgrammableAgent):
|
|
|
141
188
|
self._operation_lock.release()
|
|
142
189
|
|
|
143
190
|
def repair_state(self, requirement: ProgrammableAgentRequirement) -> None:
|
|
191
|
+
r"""Repair the state of the agent.
|
|
192
|
+
|
|
193
|
+
Implements basic state repair for message role requirements.
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
requirement (ProgrammableAgentRequirement): The requirement to
|
|
197
|
+
repair the state for.
|
|
198
|
+
"""
|
|
144
199
|
if requirement == ProgrammableAgentRequirement.LAST_MESSAGE_NOT_USER:
|
|
145
200
|
if self._last_message_role == "user":
|
|
146
201
|
raise NotImplementedError(
|
camel/benchmarks/apibench.py
CHANGED
|
@@ -24,7 +24,6 @@ from tree_sitter import Language, Parser
|
|
|
24
24
|
|
|
25
25
|
from camel.agents import ChatAgent
|
|
26
26
|
from camel.benchmarks.base import BaseBenchmark
|
|
27
|
-
from camel.messages import BaseMessage
|
|
28
27
|
from camel.utils import download_github_subdirectory
|
|
29
28
|
|
|
30
29
|
logger = logging.getLogger(__name__)
|
|
@@ -281,12 +280,9 @@ class APIBenchBenchmark(BaseBenchmark):
|
|
|
281
280
|
with open(self.save_to, "w") as f:
|
|
282
281
|
for question in tqdm(datas, desc="Running"):
|
|
283
282
|
prompt = encode_question(question["text"], dataset_name)
|
|
284
|
-
msg = BaseMessage.make_user_message(
|
|
285
|
-
role_name="User", content=prompt
|
|
286
|
-
)
|
|
287
283
|
try:
|
|
288
284
|
# Generate response
|
|
289
|
-
responses = agent.step(
|
|
285
|
+
responses = agent.step(prompt)
|
|
290
286
|
response = responses.msgs[0].content
|
|
291
287
|
api_database = self._data['api']
|
|
292
288
|
qa_pairs = self._data['eval']
|
camel/benchmarks/nexus.py
CHANGED
|
@@ -28,7 +28,6 @@ from tqdm import tqdm
|
|
|
28
28
|
|
|
29
29
|
from camel.agents import ChatAgent
|
|
30
30
|
from camel.benchmarks.base import BaseBenchmark
|
|
31
|
-
from camel.messages import BaseMessage
|
|
32
31
|
|
|
33
32
|
logger = logging.getLogger(__name__)
|
|
34
33
|
|
|
@@ -309,13 +308,10 @@ class NexusBenchmark(BaseBenchmark):
|
|
|
309
308
|
with open(self.save_to, "w") as f:
|
|
310
309
|
for sample in tqdm(datas, desc="Running"):
|
|
311
310
|
prompt = construct_prompt(input=sample.input, tools=tools)
|
|
312
|
-
msg = BaseMessage.make_user_message(
|
|
313
|
-
role_name="User", content=prompt
|
|
314
|
-
)
|
|
315
311
|
ground_truth_call = sample.output
|
|
316
312
|
try:
|
|
317
313
|
# Generate response
|
|
318
|
-
response = agent.step(
|
|
314
|
+
response = agent.step(prompt)
|
|
319
315
|
agent_call = response.msgs[0].content
|
|
320
316
|
|
|
321
317
|
# Evaluate response
|
camel/benchmarks/ragbench.py
CHANGED
|
@@ -188,8 +188,8 @@ def ragas_evaluate_dataset(
|
|
|
188
188
|
Returns:
|
|
189
189
|
Dataset: Dataset with added evaluation metrics.
|
|
190
190
|
"""
|
|
191
|
-
from ragas import evaluate
|
|
192
|
-
from ragas.metrics import ( # type: ignore[import
|
|
191
|
+
from ragas import evaluate # type: ignore[import]
|
|
192
|
+
from ragas.metrics import ( # type: ignore[import]
|
|
193
193
|
context_relevancy,
|
|
194
194
|
faithfulness,
|
|
195
195
|
)
|
camel/bots/telegram_bot.py
CHANGED
|
@@ -15,7 +15,6 @@ import os
|
|
|
15
15
|
from typing import TYPE_CHECKING, Optional
|
|
16
16
|
|
|
17
17
|
from camel.agents import ChatAgent
|
|
18
|
-
from camel.messages import BaseMessage
|
|
19
18
|
from camel.utils import dependencies_required
|
|
20
19
|
|
|
21
20
|
# Conditionally import telebot types only for type checking
|
|
@@ -74,9 +73,6 @@ class TelegramBot:
|
|
|
74
73
|
if not message.text:
|
|
75
74
|
return
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
role_name="User", content=message.text
|
|
79
|
-
)
|
|
80
|
-
assistant_response = self.chat_agent.step(user_msg)
|
|
76
|
+
assistant_response = self.chat_agent.step(message.text)
|
|
81
77
|
|
|
82
78
|
self.bot.reply_to(message, assistant_response.msg.content)
|
camel/configs/__init__.py
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
|
+
from .aiml_config import AIML_API_PARAMS, AIMLConfig
|
|
14
15
|
from .anthropic_config import ANTHROPIC_API_PARAMS, AnthropicConfig
|
|
15
16
|
from .base_config import BaseConfig
|
|
16
17
|
from .cohere_config import COHERE_API_PARAMS, CohereConfig
|
|
@@ -20,6 +21,7 @@ from .groq_config import GROQ_API_PARAMS, GroqConfig
|
|
|
20
21
|
from .internlm_config import INTERNLM_API_PARAMS, InternLMConfig
|
|
21
22
|
from .litellm_config import LITELLM_API_PARAMS, LiteLLMConfig
|
|
22
23
|
from .mistral_config import MISTRAL_API_PARAMS, MistralConfig
|
|
24
|
+
from .moonshot_config import MOONSHOT_API_PARAMS, MoonshotConfig
|
|
23
25
|
from .nvidia_config import NVIDIA_API_PARAMS, NvidiaConfig
|
|
24
26
|
from .ollama_config import OLLAMA_API_PARAMS, OllamaConfig
|
|
25
27
|
from .openai_config import OPENAI_API_PARAMS, ChatGPTConfig
|
|
@@ -32,6 +34,7 @@ from .samba_config import (
|
|
|
32
34
|
SambaVerseAPIConfig,
|
|
33
35
|
)
|
|
34
36
|
from .sglang_config import SGLANG_API_PARAMS, SGLangConfig
|
|
37
|
+
from .siliconflow_config import SILICONFLOW_API_PARAMS, SiliconFlowConfig
|
|
35
38
|
from .togetherai_config import TOGETHERAI_API_PARAMS, TogetherAIConfig
|
|
36
39
|
from .vllm_config import VLLM_API_PARAMS, VLLMConfig
|
|
37
40
|
from .yi_config import YI_API_PARAMS, YiConfig
|
|
@@ -79,4 +82,10 @@ __all__ = [
|
|
|
79
82
|
'DEEPSEEK_API_PARAMS',
|
|
80
83
|
'InternLMConfig',
|
|
81
84
|
'INTERNLM_API_PARAMS',
|
|
85
|
+
'MoonshotConfig',
|
|
86
|
+
"MOONSHOT_API_PARAMS",
|
|
87
|
+
'SiliconFlowConfig',
|
|
88
|
+
'SILICONFLOW_API_PARAMS',
|
|
89
|
+
'AIMLConfig',
|
|
90
|
+
'AIML_API_PARAMS',
|
|
82
91
|
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# ========= Copyright 2023-2024 @ 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-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Sequence, Type, Union
|
|
17
|
+
|
|
18
|
+
from pydantic import BaseModel, Field
|
|
19
|
+
|
|
20
|
+
from camel.configs.base_config import BaseConfig
|
|
21
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AIMLConfig(BaseConfig):
|
|
25
|
+
r"""Defines the parameters for generating chat completions using the
|
|
26
|
+
AIML API.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
temperature (float, optional): Determines the degree of randomness
|
|
30
|
+
in the response. (default: :obj:`0.7`)
|
|
31
|
+
top_p (float, optional): The top_p (nucleus) parameter is used to
|
|
32
|
+
dynamically adjust the number of choices for each predicted token
|
|
33
|
+
based on the cumulative probabilities. (default: :obj:`0.7`)
|
|
34
|
+
n (int, optional): Number of generations to return. (default::obj:`1`)
|
|
35
|
+
response_format (object, optional): An object specifying the format
|
|
36
|
+
that the model must output.
|
|
37
|
+
stream (bool, optional): If set, tokens are returned as Server-Sent
|
|
38
|
+
Events as they are made available. (default: :obj:`False`)
|
|
39
|
+
stop (str or list, optional): Up to :obj:`4` sequences where the API
|
|
40
|
+
will stop generating further tokens. (default: :obj:`None`)
|
|
41
|
+
max_tokens (int, optional): The maximum number of tokens to generate.
|
|
42
|
+
(default: :obj:`None`)
|
|
43
|
+
logit_bias (dict, optional): Modify the likelihood of specified tokens
|
|
44
|
+
appearing in the completion. Accepts a json object that maps tokens
|
|
45
|
+
(specified by their token ID in the tokenizer) to an associated
|
|
46
|
+
bias value from :obj:`-100` to :obj:`100`. Mathematically, the bias
|
|
47
|
+
is added to the logits generated by the model prior to sampling.
|
|
48
|
+
The exact effect will vary per model, but values between:obj:` -1`
|
|
49
|
+
and :obj:`1` should decrease or increase likelihood of selection;
|
|
50
|
+
values like :obj:`-100` or :obj:`100` should result in a ban or
|
|
51
|
+
exclusive selection of the relevant token. (default: :obj:`{}`)
|
|
52
|
+
frequency_penalty (float, optional): Number between :obj:`-2.0` and
|
|
53
|
+
:obj:`2.0`. Positive values penalize new tokens based on their
|
|
54
|
+
existing frequency in the text so far, decreasing the model's
|
|
55
|
+
likelihood to repeat the same line verbatim. See more information
|
|
56
|
+
about frequency and presence penalties. (default: :obj:`0.0`)
|
|
57
|
+
presence_penalty (float, optional): Number between :obj:`-2.0` and
|
|
58
|
+
:obj:`2.0`. Positive values penalize new tokens based on whether
|
|
59
|
+
they appear in the text so far, increasing the model's likelihood
|
|
60
|
+
to talk about new topics. See more information about frequency and
|
|
61
|
+
presence penalties. (default: :obj:`0.0`)
|
|
62
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
63
|
+
call. Currently, only functions are supported as a tool. Use this
|
|
64
|
+
to provide a list of functions the model may generate JSON inputs
|
|
65
|
+
for. A max of 128 functions are supported.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
temperature: float = 0.7
|
|
69
|
+
top_p: float = 0.7
|
|
70
|
+
n: int = 1
|
|
71
|
+
stream: bool = False
|
|
72
|
+
stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
|
|
73
|
+
max_tokens: Union[int, NotGiven] = NOT_GIVEN
|
|
74
|
+
logit_bias: dict = Field(default_factory=dict)
|
|
75
|
+
response_format: Union[Type[BaseModel], dict, NotGiven] = NOT_GIVEN
|
|
76
|
+
presence_penalty: float = 0.0
|
|
77
|
+
frequency_penalty: float = 0.0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
AIML_API_PARAMS = {param for param in AIMLConfig.model_fields.keys()}
|
camel/configs/gemini_config.py
CHANGED
|
@@ -83,7 +83,7 @@ class GeminiConfig(BaseConfig):
|
|
|
83
83
|
stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
|
|
84
84
|
max_tokens: Union[int, NotGiven] = NOT_GIVEN
|
|
85
85
|
response_format: Union[Type[BaseModel], dict, NotGiven] = NOT_GIVEN
|
|
86
|
-
tool_choice: Optional[Union[dict[str, str], str]] =
|
|
86
|
+
tool_choice: Optional[Union[dict[str, str], str, NotGiven]] = NOT_GIVEN
|
|
87
87
|
|
|
88
88
|
def as_dict(self) -> dict[str, Any]:
|
|
89
89
|
r"""Convert the current configuration to a dictionary.
|