Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: circular import of FunctionTool and ChatAgent #1379

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 61 additions & 61 deletions camel/toolkits/function_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ast
import inspect
import logging
import textwrap
import warnings
from inspect import Parameter, getsource, signature
from typing import Any, Callable, Dict, Mapping, Optional, Tuple, Type
Expand All @@ -24,7 +25,6 @@
from pydantic import BaseModel, create_model
from pydantic.fields import FieldInfo

from camel.agents import ChatAgent
from camel.models import BaseModelBackend, ModelFactory
from camel.types import ModelPlatformType, ModelType
from camel.utils import get_pydantic_object_schema, to_pascal
Expand Down Expand Up @@ -237,41 +237,43 @@ def generate_docstring(
Returns:
str: The generated docstring.
"""
# Create the docstring prompt
docstring_prompt = '''
**Role**: Generate professional Python docstrings conforming to
PEP 8/PEP 257.

**Requirements**:
- Use appropriate format: reST, Google, or NumPy, as needed.
- Include parameters, return values, and exceptions.
- Reference any existing docstring in the function and
retain useful information.
from camel.agents import ChatAgent

**Input**: Python function.
# Create the docstring prompt
docstring_prompt = textwrap.dedent(
"""\
**Role**: Generate professional Python docstrings conforming to PEP 8/PEP 257.

**Output**: Docstring content (plain text, no code markers).
**Requirements**:
- Use appropriate format: reST, Google, or NumPy, as needed.
- Include parameters, return values, and exceptions.
- Reference any existing docstring in the function and retain useful information.

**Example:**
**Input**: Python function.

Input:
```python
def add(a: int, b: int) -> int:
return a + b
```
**Output**: Docstring content (plain text, no code markers).

Output:
Adds two numbers.
Args:
a (int): The first number.
b (int): The second number.
**Example:**

Returns:
int: The sum of the two numbers.
Input:
```python
def add(a: int, b: int) -> int:
return a + b
```

**Task**: Generate a docstring for the function below.
Output:
Adds two numbers.
Args:
a (int): The first number.
b (int): The second number.

Returns:
int: The sum of the two numbers.

'''
**Task**: Generate a docstring for the function below.
""" # noqa: E501
)
# Initialize assistant with system message and model
assistant_sys_msg = "You are a helpful assistant."
docstring_assistant = ChatAgent(assistant_sys_msg, model=model)
Expand Down Expand Up @@ -665,7 +667,7 @@ def synthesize_execution_output(
Any: Synthesized output from the function execution. If no
synthesis model is provided, a warning is logged.
"""
import textwrap
from camel.agents import ChatAgent

# Retrieve the function source code
function_string = inspect.getsource(self.func)
Expand Down Expand Up @@ -694,39 +696,37 @@ def synthesize_execution_output(
function_string += f"\nkwargs:\n{kwargs}"

# Define the assistant system message
assistant_sys_msg = '''
**Role:** AI Assistant specialized in synthesizing tool execution outputs
without actual execution.

**Capabilities:**
- Analyzes function to understand their
purpose and expected outputs.
- Generates synthetic outputs based on the function logic.
- Ensures the synthesized output is contextually accurate and aligns with the
function's intended behavior.

**Instructions:**
1. **Input:** Provide the function code, function docstring, args, and kwargs.
2. **Output:** Synthesize the expected output of the function based on the
provided args and kwargs.

**Example:**
- **User Input:**
def sum(a, b, c=0):
"""Adds three numbers together."""
return a + b + c

- **Input Arguments:**
args: (1, 2)
kwargs: {"c": 3}

- **Output:**
6

**Note:**
- Just return the synthesized output of the function without any explanation.
- The output should be in plain text without any formatting.
'''
assistant_sys_msg = textwrap.dedent(
'''\
**Role:** AI Assistant specialized in synthesizing tool execution outputs without actual execution.

**Capabilities:**
- Analyzes function to understand their purpose and expected outputs.
- Generates synthetic outputs based on the function logic.
- Ensures the synthesized output is contextually accurate and aligns with the function's intended behavior.

**Instructions:**
1. **Input:** Provide the function code, function docstring, args, and kwargs.
2. **Output:** Synthesize the expected output of the function based on the provided args and kwargs.

**Example:**
- **User Input:**
def sum(a, b, c=0):
"""Adds three numbers together."""
return a + b + c

- **Input Arguments:**
args: (1, 2)
kwargs: {"c": 3}

- **Output:**
6

**Note:**
- Just return the synthesized output of the function without any explanation.
- The output should be in plain text without any formatting.
''' # noqa: E501
)

# Initialize the synthesis agent
synthesis_agent = ChatAgent(
Expand Down
Loading