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

1.7 KB
Raw Blame
<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

```python
def try_modify_message_with_format(
    message: OpenAIMessage,
    response_format: Type[BaseModel] | None
):
```

Modifies the content of the message to include the instruction of using
the response format.

The message will not be modified in the following cases:
- response_format is None
- message content is not a string
- message role is assistant

**Parameters:**

- **response_format** (Type[BaseModel] | None): The Pydantic model class.
- **message** (OpenAIMessage): The message to be modified.