Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

Auto-update documentation after merge [skip ci]

camel-docs-bot5ef537256b50
diff --git a/docs/mintlify/reference/camel.models._utils.mdx b/docs/mintlify/reference/camel.models._utils.mdx
index 152a1e6e5..968cb884f 100644
--- a/docs/mintlify/reference/camel.models._utils.mdx
+++ b/docs/mintlify/reference/camel.models._utils.mdx
@@ -1,5 +1,35 @@
<a id="camel.models._utils"></a>
+<a id="camel.models._utils.extract_thinking_from_content"></a>
+
+## extract_thinking_from_content
+
+```python
+def extract_thinking_from_content(content: str, reasoning_content: str | None = None):
+```
+
+Extract `__INLINE_CODE_0__` tags from content into reasoning_content.
+
+Used for both pre-processing (stripping `__INLINE_CODE_1__` tags from
+input messages before sending to the model) and post-processing
+(extracting `__INLINE_CODE_2__` tags from model output into the
+`__INLINE_CODE_3__` field).
+
+If the content contains `__INLINE_CODE_4__` tags and
+`__INLINE_CODE_5__` is not already set, extracts the thinking
+content and returns cleaned content with the reasoning.
+
+**Parameters:**
+
+- **content** (str): The response content that may contain `__INLINE_CODE_0__` tags.
+- **reasoning_content** (str | None): Existing reasoning content. If already set, no extraction is performed. (default: :obj:`None`)
+
+**Returns:**
+
+ tuple[str, str | None]: A tuple of (cleaned_content,
+reasoning_content). If no extraction was needed, returns
+the original values unchanged.
+
<a id="camel.models._utils.try_modify_message_with_format"></a>
## try_modify_message_with_format
@@ -7,7 +37,7 @@
```python
def try_modify_message_with_format(
message: OpenAIMessage,
- response_format: Optional[Type[BaseModel]]
+ response_format: Type[BaseModel] | None
):
```
@@ -21,5 +51,5 @@ The message will not be modified in the following cases:
**Parameters:**
-- **response_format** (Optional[Type[BaseModel]]): The Pydantic model class.
+- **response_format** (Type[BaseModel] | None): The Pydantic model class.
- **message** (OpenAIMessage): The message to be modified.
diff --git a/docs/mintlify/reference/camel.models.base_model.mdx b/docs/mintlify/reference/camel.models.base_model.mdx
index 834fe25bc..825cbbcaa 100644
--- a/docs/mintlify/reference/camel.models.base_model.mdx
+++ b/docs/mintlify/reference/camel.models.base_model.mdx
@@ -144,11 +144,13 @@ def __del__(self):
class ModelBackendMeta(ABCMeta):
```
-Metaclass that automatically preprocesses messages in run method.
+Metaclass that automatically pre/post-processes the run method.
-Automatically wraps the run method of any class inheriting from
-BaseModelBackend to preprocess messages (remove `<think>` tags) before they
-are sent to the model.
+Automatically wraps the run and arun methods of any class inheriting from
+BaseModelBackend to:
+- Preprocess messages (remove `<think>` tags) before sending to the model.
+- Postprocess responses (extract `<think>` tags into reasoning_content)
+after receiving from the model.
<a id="camel.models.base_model.ModelBackendMeta.__new__"></a>
@@ -163,7 +165,7 @@ def __new__(
):
```
-Wraps run method with preprocessing if it exists in the class.
+Wraps run/arun methods with pre/post-processing.
<a id="camel.models.base_model.BaseModelBackend"></a>
@@ -185,6 +187,7 @@ It may be OpenAI API, a local LLM, a stub for unit tests, etc.
- **token_counter** (Optional[BaseTokenCounter], optional): Token counter to use for the model. If not provided, :obj:`OpenAITokenCounter` will be used. (default: :obj:`None`)
- **timeout** (Optional[float], optional): The timeout value in seconds for API calls. (default: :obj:`None`)
- **max_retries** (int, optional): Maximum number of retries for API calls. (default: :obj:`3`)
+- **extract_thinking_from_response** (bool, optional): Whether to extract `__INLINE_CODE_0____INLINE_CODE_1____INLINE_CODE_2____INLINE_CODE_3____INLINE_CODE_4____INLINE_CODE_5____INLINE_CODE_6____INLINE_CODE_7____INLINE_CODE_8____INLINE_CODE_9____INLINE_CODE_10____INLINE_CODE_11__True`)
<a id="camel.models.base_model.BaseModelBackend.__init__"></a>
@@ -199,7 +202,8 @@ def __init__(
url: Optional[str] = None,
token_counter: Optional[BaseTokenCounter] = None,
timeout: Optional[float] = Constants.TIMEOUT_THRESHOLD,
- max_retries: int = 3
+ max_retries: int = 3,
+ extract_thinking_from_response: bool = True
):
```
@@ -259,6 +263,34 @@ detected.
List[OpenAIMessage]: Preprocessed messages
+<a id="camel.models.base_model.BaseModelBackend.postprocess_response"></a>
+
+### postprocess_response
+
+```python
+def postprocess_response(self, response: Any):
+```
+
+Postprocess model response to extract `__INLINE_CODE_0__` tags.
+
+For non-streaming responses, if the model embeds reasoning in
+`__INLINE_CODE_1__` tags within the response content (and
+`__INLINE_CODE_2__` is not already set), extracts the content
+of the tags into `__INLINE_CODE_3__` and removes them from
+`__INLINE_CODE_4__`.
+
+Streaming responses and other non-ChatCompletion types are
+returned as-is.
+
+**Parameters:**
+
+- **response**: The model response. May be a :obj:`ChatCompletion`, a streaming object, or other types.
+
+**Returns:**
+
+ The response, potentially with `__INLINE_CODE_0__`
+populated and `__INLINE_CODE_1__` cleaned.
+
<a id="camel.models.base_model.BaseModelBackend._log_request"></a>
### _log_request