camel-ai 0.2.18__py3-none-any.whl → 0.2.20a0__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 +27 -27
- camel/agents/multi_hop_generator_agent.py +35 -3
- camel/agents/programmed_agent_instruction.py +73 -18
- camel/configs/__init__.py +6 -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/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 +2 -0
- camel/models/deepseek_model.py +29 -11
- camel/models/groq_model.py +0 -2
- camel/models/model_factory.py +6 -0
- camel/models/moonshot_model.py +138 -0
- camel/models/openai_model.py +1 -9
- camel/models/siliconflow_model.py +142 -0
- camel/toolkits/__init__.py +2 -0
- camel/toolkits/search_toolkit.py +17 -6
- camel/toolkits/semantic_scholar_toolkit.py +308 -0
- camel/types/enums.py +176 -15
- camel/types/unified_model_type.py +5 -0
- camel/utils/token_counting.py +1 -1
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20a0.dist-info}/METADATA +9 -3
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20a0.dist-info}/RECORD +34 -27
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20a0.dist-info}/LICENSE +0 -0
- {camel_ai-0.2.18.dist-info → camel_ai-0.2.20a0.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):
|
|
@@ -645,7 +645,7 @@ class ChatAgent(BaseAgent):
|
|
|
645
645
|
)
|
|
646
646
|
|
|
647
647
|
# Record function calls made during the session
|
|
648
|
-
tool_call_records: List[
|
|
648
|
+
tool_call_records: List[ToolCallingRecord] = []
|
|
649
649
|
|
|
650
650
|
external_tool_request = None
|
|
651
651
|
|
|
@@ -885,7 +885,7 @@ class ChatAgent(BaseAgent):
|
|
|
885
885
|
|
|
886
886
|
self.update_memory(input_message, OpenAIBackendRole.USER)
|
|
887
887
|
|
|
888
|
-
tool_call_records: List[
|
|
888
|
+
tool_call_records: List[ToolCallingRecord] = []
|
|
889
889
|
while True:
|
|
890
890
|
try:
|
|
891
891
|
openai_messages, num_tokens = self.memory.get_context()
|
|
@@ -970,7 +970,7 @@ class ChatAgent(BaseAgent):
|
|
|
970
970
|
|
|
971
971
|
def _step_tool_call_and_update(
|
|
972
972
|
self, response: ChatCompletion
|
|
973
|
-
) ->
|
|
973
|
+
) -> ToolCallingRecord:
|
|
974
974
|
r"""Processes a function call within the chat completion response,
|
|
975
975
|
records the function call in the provided list of tool calls and
|
|
976
976
|
updates the memory of the current agent.
|
|
@@ -980,7 +980,7 @@ class ChatAgent(BaseAgent):
|
|
|
980
980
|
completion.
|
|
981
981
|
|
|
982
982
|
Returns:
|
|
983
|
-
|
|
983
|
+
ToolCallingRecord: The record of calling the function.
|
|
984
984
|
"""
|
|
985
985
|
|
|
986
986
|
# Perform function calling
|
|
@@ -996,7 +996,7 @@ class ChatAgent(BaseAgent):
|
|
|
996
996
|
|
|
997
997
|
async def _step_tool_call_and_update_async(
|
|
998
998
|
self, response: ChatCompletion
|
|
999
|
-
) ->
|
|
999
|
+
) -> ToolCallingRecord:
|
|
1000
1000
|
(
|
|
1001
1001
|
func_assistant_msg,
|
|
1002
1002
|
func_result_msg,
|
|
@@ -1015,7 +1015,7 @@ class ChatAgent(BaseAgent):
|
|
|
1015
1015
|
List[str],
|
|
1016
1016
|
Dict[str, int],
|
|
1017
1017
|
str,
|
|
1018
|
-
|
|
1018
|
+
ToolCallingRecord,
|
|
1019
1019
|
int,
|
|
1020
1020
|
]:
|
|
1021
1021
|
r"""Internal function of structuring the output of the agent based on
|
|
@@ -1027,7 +1027,7 @@ class ChatAgent(BaseAgent):
|
|
|
1027
1027
|
|
|
1028
1028
|
Returns:
|
|
1029
1029
|
Tuple[List[BaseMessage], List[str], Dict[str, int], str,
|
|
1030
|
-
|
|
1030
|
+
ToolCallingRecord, int]:
|
|
1031
1031
|
A tuple containing the output messages, finish reasons, usage
|
|
1032
1032
|
dictionary, response ID, function calling record, and number of
|
|
1033
1033
|
tokens.
|
|
@@ -1141,7 +1141,7 @@ class ChatAgent(BaseAgent):
|
|
|
1141
1141
|
finish_reasons: List[str],
|
|
1142
1142
|
usage_dict: Dict[str, int],
|
|
1143
1143
|
response_id: str,
|
|
1144
|
-
tool_calls: List[
|
|
1144
|
+
tool_calls: List[ToolCallingRecord],
|
|
1145
1145
|
num_tokens: int,
|
|
1146
1146
|
external_tool_request: Optional[ChatCompletionMessageToolCall] = None,
|
|
1147
1147
|
) -> Dict[str, Any]:
|
|
@@ -1160,7 +1160,7 @@ class ChatAgent(BaseAgent):
|
|
|
1160
1160
|
usage_dict (Dict[str, int]): Dictionary containing token usage
|
|
1161
1161
|
information.
|
|
1162
1162
|
response_id (str): The ID of the response from the model.
|
|
1163
|
-
tool_calls (List[
|
|
1163
|
+
tool_calls (List[ToolCallingRecord]): Records of function calls
|
|
1164
1164
|
made during this step.
|
|
1165
1165
|
num_tokens (int): The number of tokens used in this step.
|
|
1166
1166
|
external_tool_request (Optional[ChatCompletionMessageToolCall]):
|
|
@@ -1335,7 +1335,7 @@ class ChatAgent(BaseAgent):
|
|
|
1335
1335
|
def _step_token_exceed(
|
|
1336
1336
|
self,
|
|
1337
1337
|
num_tokens: int,
|
|
1338
|
-
tool_calls: List[
|
|
1338
|
+
tool_calls: List[ToolCallingRecord],
|
|
1339
1339
|
termination_reason: str,
|
|
1340
1340
|
) -> ChatAgentResponse:
|
|
1341
1341
|
r"""Return trivial response containing number of tokens and information
|
|
@@ -1343,7 +1343,7 @@ class ChatAgent(BaseAgent):
|
|
|
1343
1343
|
|
|
1344
1344
|
Args:
|
|
1345
1345
|
num_tokens (int): Number of tokens in the messages.
|
|
1346
|
-
tool_calls (List[
|
|
1346
|
+
tool_calls (List[ToolCallingRecord]): List of information
|
|
1347
1347
|
objects of functions called in the current step.
|
|
1348
1348
|
termination_reason (str): String of termination reason.
|
|
1349
1349
|
|
|
@@ -1372,7 +1372,7 @@ class ChatAgent(BaseAgent):
|
|
|
1372
1372
|
self,
|
|
1373
1373
|
response: ChatCompletion,
|
|
1374
1374
|
) -> Tuple[
|
|
1375
|
-
FunctionCallingMessage, FunctionCallingMessage,
|
|
1375
|
+
FunctionCallingMessage, FunctionCallingMessage, ToolCallingRecord
|
|
1376
1376
|
]:
|
|
1377
1377
|
r"""Execute the function with arguments following the model's response.
|
|
1378
1378
|
|
|
@@ -1418,8 +1418,8 @@ class ChatAgent(BaseAgent):
|
|
|
1418
1418
|
)
|
|
1419
1419
|
|
|
1420
1420
|
# Record information about this function call
|
|
1421
|
-
func_record =
|
|
1422
|
-
|
|
1421
|
+
func_record = ToolCallingRecord(
|
|
1422
|
+
tool_name=func_name,
|
|
1423
1423
|
args=args,
|
|
1424
1424
|
result=result,
|
|
1425
1425
|
tool_call_id=tool_call_id,
|
|
@@ -1442,7 +1442,7 @@ class ChatAgent(BaseAgent):
|
|
|
1442
1442
|
self,
|
|
1443
1443
|
response: ChatCompletion,
|
|
1444
1444
|
) -> Tuple[
|
|
1445
|
-
FunctionCallingMessage, FunctionCallingMessage,
|
|
1445
|
+
FunctionCallingMessage, FunctionCallingMessage, ToolCallingRecord
|
|
1446
1446
|
]:
|
|
1447
1447
|
r"""Execute the async function with arguments following the model's
|
|
1448
1448
|
response.
|
|
@@ -1488,8 +1488,8 @@ class ChatAgent(BaseAgent):
|
|
|
1488
1488
|
)
|
|
1489
1489
|
|
|
1490
1490
|
# Record information about this function call
|
|
1491
|
-
func_record =
|
|
1492
|
-
|
|
1491
|
+
func_record = ToolCallingRecord(
|
|
1492
|
+
tool_name=func_name,
|
|
1493
1493
|
args=args,
|
|
1494
1494
|
result=result,
|
|
1495
1495
|
tool_call_id=tool_call_id,
|
|
@@ -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/configs/__init__.py
CHANGED
|
@@ -20,6 +20,7 @@ from .groq_config import GROQ_API_PARAMS, GroqConfig
|
|
|
20
20
|
from .internlm_config import INTERNLM_API_PARAMS, InternLMConfig
|
|
21
21
|
from .litellm_config import LITELLM_API_PARAMS, LiteLLMConfig
|
|
22
22
|
from .mistral_config import MISTRAL_API_PARAMS, MistralConfig
|
|
23
|
+
from .moonshot_config import MOONSHOT_API_PARAMS, MoonshotConfig
|
|
23
24
|
from .nvidia_config import NVIDIA_API_PARAMS, NvidiaConfig
|
|
24
25
|
from .ollama_config import OLLAMA_API_PARAMS, OllamaConfig
|
|
25
26
|
from .openai_config import OPENAI_API_PARAMS, ChatGPTConfig
|
|
@@ -32,6 +33,7 @@ from .samba_config import (
|
|
|
32
33
|
SambaVerseAPIConfig,
|
|
33
34
|
)
|
|
34
35
|
from .sglang_config import SGLANG_API_PARAMS, SGLangConfig
|
|
36
|
+
from .siliconflow_config import SILICONFLOW_API_PARAMS, SiliconFlowConfig
|
|
35
37
|
from .togetherai_config import TOGETHERAI_API_PARAMS, TogetherAIConfig
|
|
36
38
|
from .vllm_config import VLLM_API_PARAMS, VLLMConfig
|
|
37
39
|
from .yi_config import YI_API_PARAMS, YiConfig
|
|
@@ -79,4 +81,8 @@ __all__ = [
|
|
|
79
81
|
'DEEPSEEK_API_PARAMS',
|
|
80
82
|
'InternLMConfig',
|
|
81
83
|
'INTERNLM_API_PARAMS',
|
|
84
|
+
'MoonshotConfig',
|
|
85
|
+
"MOONSHOT_API_PARAMS",
|
|
86
|
+
'SiliconFlowConfig',
|
|
87
|
+
'SILICONFLOW_API_PARAMS',
|
|
82
88
|
]
|
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.
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
|
|
15
|
+
from typing import List, Optional, Union
|
|
16
|
+
|
|
17
|
+
from camel.configs.base_config import BaseConfig
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MoonshotConfig(BaseConfig):
|
|
21
|
+
r"""Defines the parameters for generating chat completions using the
|
|
22
|
+
Moonshot API. You can refer to the following link for more details:
|
|
23
|
+
https://platform.moonshot.cn/docs/api-reference
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
temperature (float, optional): Controls randomness in the response.
|
|
27
|
+
Lower values make the output more focused and deterministic.
|
|
28
|
+
(default: :obj:`0.3`)
|
|
29
|
+
max_tokens (int, optional): The maximum number of tokens to generate.
|
|
30
|
+
(default: :obj:`None`)
|
|
31
|
+
stream (bool, optional): Whether to stream the response.
|
|
32
|
+
(default: :obj:`False`)
|
|
33
|
+
tools (list, optional): List of tools that the model can use for
|
|
34
|
+
function calling. Each tool should be a dictionary containing
|
|
35
|
+
type, function name, description, and parameters.
|
|
36
|
+
(default: :obj:`None`)
|
|
37
|
+
top_p (float, optional): Controls diversity via nucleus sampling.
|
|
38
|
+
(default: :obj:`1.0`)
|
|
39
|
+
n (int, optional): How many chat completion choices to generate for
|
|
40
|
+
each input message. (default: :obj:`1`)
|
|
41
|
+
presence_penalty (float, optional): Penalty for new tokens based on
|
|
42
|
+
whether they appear in the text so far.
|
|
43
|
+
(default: :obj:`0.0`)
|
|
44
|
+
frequency_penalty (float, optional): Penalty for new tokens based on
|
|
45
|
+
their frequency in the text so far.
|
|
46
|
+
(default: :obj:`0.0`)
|
|
47
|
+
stop (Optional[Union[str, List[str]]], optional): Up to 4 sequences
|
|
48
|
+
where the API will stop generating further tokens.
|
|
49
|
+
(default: :obj:`None`)
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
temperature: float = 0.3
|
|
53
|
+
max_tokens: Optional[int] = None
|
|
54
|
+
stream: bool = False
|
|
55
|
+
tools: Optional[list] = None
|
|
56
|
+
top_p: float = 1.0
|
|
57
|
+
n: int = 1
|
|
58
|
+
presence_penalty: float = 0.0
|
|
59
|
+
frequency_penalty: float = 0.0
|
|
60
|
+
stop: Optional[Union[str, List[str]]] = None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
MOONSHOT_API_PARAMS = {param for param in MoonshotConfig.model_fields.keys()}
|
camel/configs/sglang_config.py
CHANGED
|
@@ -56,6 +56,10 @@ class SGLangConfig(BaseConfig):
|
|
|
56
56
|
in the chat completion. The total length of input tokens and
|
|
57
57
|
generated tokens is limited by the model's context length.
|
|
58
58
|
(default: :obj:`None`)
|
|
59
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
60
|
+
call. Currently, only functions are supported as a tool. Use this
|
|
61
|
+
to provide a list of functions the model may generate JSON inputs
|
|
62
|
+
for. A max of 128 functions are supported.
|
|
59
63
|
"""
|
|
60
64
|
|
|
61
65
|
stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
|
|
@@ -0,0 +1,91 @@
|
|
|
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 Any, Sequence, Type, Union
|
|
17
|
+
|
|
18
|
+
from pydantic import BaseModel
|
|
19
|
+
|
|
20
|
+
from camel.configs.base_config import BaseConfig
|
|
21
|
+
from camel.types import NOT_GIVEN, NotGiven
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class SiliconFlowConfig(BaseConfig):
|
|
25
|
+
r"""Defines the parameters for generating chat completions using the
|
|
26
|
+
SiliconFlow 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
|
+
frequency_penalty (float, optional): Number between :obj:`-2.0` and
|
|
44
|
+
:obj:`2.0`. Positive values penalize new tokens based on their
|
|
45
|
+
existing frequency in the text so far, decreasing the model's
|
|
46
|
+
likelihood to repeat the same line verbatim. See more information
|
|
47
|
+
about frequency and presence penalties. (default: :obj:`0.0`)
|
|
48
|
+
tools (list[FunctionTool], optional): A list of tools the model may
|
|
49
|
+
call. Currently, only functions are supported as a tool. Use this
|
|
50
|
+
to provide a list of functions the model may generate JSON inputs
|
|
51
|
+
for. A max of 128 functions are supported.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
temperature: float = 0.7
|
|
55
|
+
top_p: float = 0.7
|
|
56
|
+
n: int = 1
|
|
57
|
+
stream: bool = False
|
|
58
|
+
stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
|
|
59
|
+
max_tokens: Union[int, NotGiven] = NOT_GIVEN
|
|
60
|
+
response_format: Union[Type[BaseModel], dict, NotGiven] = NOT_GIVEN
|
|
61
|
+
frequency_penalty: float = 0.0
|
|
62
|
+
|
|
63
|
+
def as_dict(self) -> dict[str, Any]:
|
|
64
|
+
r"""Convert the current configuration to a dictionary.
|
|
65
|
+
|
|
66
|
+
This method converts the current configuration object to a dictionary
|
|
67
|
+
representation, which can be used for serialization or other purposes.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
dict[str, Any]: A dictionary representation of the current
|
|
71
|
+
configuration.
|
|
72
|
+
"""
|
|
73
|
+
config_dict = self.model_dump()
|
|
74
|
+
if self.tools:
|
|
75
|
+
from camel.toolkits import FunctionTool
|
|
76
|
+
|
|
77
|
+
tools_schema = []
|
|
78
|
+
for tool in self.tools:
|
|
79
|
+
if not isinstance(tool, FunctionTool):
|
|
80
|
+
raise ValueError(
|
|
81
|
+
f"The tool {tool} should "
|
|
82
|
+
"be an instance of `FunctionTool`."
|
|
83
|
+
)
|
|
84
|
+
tools_schema.append(tool.get_openai_tool_schema())
|
|
85
|
+
config_dict["tools"] = NOT_GIVEN
|
|
86
|
+
return config_dict
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
SILICONFLOW_API_PARAMS = {
|
|
90
|
+
param for param in SiliconFlowConfig.model_fields.keys()
|
|
91
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 .data_processor import (
|
|
15
|
+
DataCurator,
|
|
16
|
+
ExampleConstructor,
|
|
17
|
+
UserDataProcessor,
|
|
18
|
+
)
|
|
19
|
+
from .models import MultiHopQA, ReasoningStep
|
|
20
|
+
from .user_data_processor_config import (
|
|
21
|
+
ProcessorConfig,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"DataCurator",
|
|
26
|
+
"ExampleConstructor",
|
|
27
|
+
"ProcessorConfig",
|
|
28
|
+
"UserDataProcessor",
|
|
29
|
+
"ReasoningStep",
|
|
30
|
+
"MultiHopQA",
|
|
31
|
+
]
|