camel-ai / camel

🐫 CAMEL: Finding the Scaling Law of Agents. A multi-agent framework. https://www.camel-ai.org
https://www.camel-ai.org
Apache License 2.0
5.29k stars 640 forks source link

[Roadmap] Make markdown tutorials for core modules #132

Open lightaime opened 1 year ago

lightaime commented 1 year ago

It is important for the users to learn the basic concepts and the core modules of CAMEL. I made a markdown tutorial for TextPrompt with the help of ChatGPT. Here is how I prompt it:

Make a markdown tutorial for the `TextPrompt` class based on its pytest functions:

{the `TextPrompt` class}

{its pytest functions}

ChatGPT generated a draft for the tutorial then I did some cleanup and editing. Although it is not perfect, it greatly accelerated the process. Almost every core modules already have pytest functions implemented. We can use a similar approach to generate tutorials for other modules. Let me know if you want to help out.

Note that: the pytest functions can be found here, after we create the markdown file (*.md), we can put it under docs/get_started and add it to docs/index.rst. Make sure to test if it works as expected before you make it pull request following the instructions of Building Documentation.

Here are some important modules we can work on:

Thanks!

tczhangzhi commented 1 year ago

Thanks for starting the project, it really works as magic. However, I think there seem to be more automated prompts when generating tutorial documents. I suggest the following way:

Objective: Create a tutorial about the {TextPrompt} class, including examples based on source code and unit test cases.

Prompts:

Source Code:

{class TextPrompt(str):
    r"""A class that represents a text prompt. The :obj:`TextPrompt` class
    extends the built-in :obj:`str` class to provide a property for retrieving
    the set of key words in the prompt.

    Attributes:
        key_words (set): A set of strings representing the key words in the
            prompt.
    """

    @property
    def key_words(self) -> Set[str]:
        r"""Returns a set of strings representing the key words in the prompt.
        """
        return get_prompt_template_key_words(self)

    def format(self, *args: Any, **kwargs: Any) -> 'TextPrompt':
        r"""Overrides the built-in :obj:`str.format` method to allow for
        default values in the format string. This is used to allow formatting
        the partial string.

        Args:
            *args (Any): Variable length argument list.
            **kwargs (Any): Arbitrary keyword arguments.

        Returns:
            TextPrompt: A new :obj:`TextPrompt` object with the format string
                replaced with the formatted string.
        """
        default_kwargs = {key: '{' + f'{key}' + '}' for key in self.key_words}
        default_kwargs.update(kwargs)
        return TextPrompt(super().format(*args, **default_kwargs))}

Unit Test Cases:

{def test_return_text_prompt_decorator():

    @return_text_prompt
    def my_function():
        return "Hello, world!"

    result = my_function()
    assert isinstance(result, TextPrompt)
    assert str(result) == "Hello, world!"

def test_return_text_prompt_decorator_with_tuple():

    @return_text_prompt
    def my_function():
        return ("Hello, {name}!", "Welcome, {name}!")

    result = my_function()
    assert isinstance(result, tuple)
    assert all(isinstance(item, TextPrompt) for item in result)
    assert str(result[0]) == "Hello, {name}!"
    assert str(result[1]) == "Welcome, {name}!"

def test_wrap_text_prompt_functions():
    # Example class for testing
    class MyClass:

        def __init__(self):
            pass

        def my_function(self):
            return "Hello, World!"

        def my_other_function(self):
            return "Goodbye, World!"

    # Decorate the class with the wrapper function
    @wrap_text_prompt_functions
    class MyDecoratedClass(MyClass):
        pass

    # Create an instance of the decorated class
    obj = MyDecoratedClass()

    # Check if the functions are wrapped correctly
    assert isinstance(obj.my_function(), TextPrompt)
    assert isinstance(obj.my_other_function(), TextPrompt)

def test_text_prompt_key_words():
    prompt = TextPrompt('Please enter your name and age: {name}, {age}')
    assert prompt.key_words == {'name', 'age'}

    prompt = prompt.format(name='John')
    assert prompt.key_words == {'age'}

    prompt = prompt.format(age=30)
    assert prompt.key_words == set()

def test_text_prompt_format():
    prompt = TextPrompt('Your name and age are: {name}, {age}')

    name, age = 'John', 30
    assert prompt.format(name=name,
                         age=age) == 'Your name and age are: John, 30'

    # Partial formatting
    assert prompt.format(name=name) == 'Your name and age are: John, {age}'

def test_text_prompt_manipulate():
    prompt1 = TextPrompt('Hello, {name}!')
    prompt2 = TextPrompt('Welcome, {name}!')

    prompt3 = prompt1 + ' ' + prompt2
    assert prompt3 == 'Hello, {name}! Welcome, {name}!'
    assert isinstance(prompt3, TextPrompt)
    assert prompt3.key_words == {'name'}

    prompt4 = TextPrompt(' ').join([prompt1, prompt2])
    assert prompt4 == 'Hello, {name}! Welcome, {name}!'
    assert isinstance(prompt4, TextPrompt)
    assert prompt4.key_words == {'name'}

    prompt5 = prompt4.upper()
    assert prompt5 == 'HELLO, {NAME}! WELCOME, {NAME}!'
    assert isinstance(prompt5, TextPrompt)
    assert prompt5.key_words == {'NAME'}

def test_text_prompt_dict():
    prompt_dict = TextPromptDict()
    prompt_dict['test'] = TextPrompt('test')
    assert prompt_dict['test'] == TextPrompt('test')}

Based on these prompts, source code, and unit test cases, create a comprehensive tutorial that explains the {TextPrompt} class and provides examples of its usage.

tczhangzhi commented 1 year ago

After a simple try, I found that a lot of labor is still necessary.

BTW, I suppose a more effective way may be to write comments and tutorial documents first, and then complete test cases and code, using ChatGPT for human assistance.

FYI, https://github.com/openai/openai-cookbook/blob/main/examples/Unit_test_writing_using_a_multi-step_prompt.ipynb https://towardsdatascience.com/streamline-your-documentation-with-gpt-3-5d9f2bbf217c https://code.visualstudio.com/blogs/2023/03/30/vscode-copilot

Wendong-Fan commented 7 months ago

Documentation

Structure of docs:

  1. Getting Started
    1. Our Roadmap and Where YOU can Contribute
    2. Installation and Setup
      1. Installation from Pip
      2. Installation from Source
        1. with poetry
        2. with conda
      3. OpenAI API set
    3. How to Read These Docs
      1. (show the structure of docs here)
    4. High-Level Concepts
      1. what is agent
      2. what is role-playing
      3. what is multi-agent
  2. Module Guides ([markdown file](https://camel-ai.github.io/camel/get_started/text_prompt.html#), current structure can be further enhanced)
    1. Agents
      1. Concept
      2. Get Started
      3. Types (if any)
      4. Examples (link to cookbook)
    2. Embeddings
    3. Functions
    4. Memories
    5. Messages
    6. Models
    7. Prompts
    8. Responses
    9. Retrievers
    10. Societies
    11. Storages
    12. Terminators
    13. Types
    14. Utils
  3. Cookbook (.ipynb file, for main module)
    1. [RAG Cookbook](https://github.com/camel-ai/camel/blob/feature/retrieval_function/docs/retrieval_augmented_generation/rag_cookbook.ipynb)
  4. Package Reference ([current modules](https://camel-ai.github.io/camel/camel.agents.html))
  5. Blog Post (nice to have)

References: https://www.cmsdrupal.com/blog/anatomy-great-open-source-documentation-how-document-your-projects-github

ZIYU-DEEP commented 7 months ago

just a quick comment: while working on the /docs to make a pull request, i am also testing the wiki feature.