GithubHelp home page GithubHelp logo

Comments (2)

tczhangzhi avatar tczhangzhi commented on June 12, 2024

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: Examine the source code of the {TextPrompt} class and its unit test cases to understand its implementation and functionality.
  • Introduction: Write an introduction to the {TextPrompt} class, explaining its purpose.
  • Creating a {TextPrompt} instance: Explain how to create a {TextPrompt} instance.
  • Describe the properties of the {TextPrompt} class and provide an example of using them.
  • Explain the method of the {TextPrompt} class and provide an example of using them.
  • Conclusion: Summarize the key points of the tutorial and encourage readers to try using the {TextPrompt} class in their projects.

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.

from camel.

tczhangzhi avatar tczhangzhi commented on June 12, 2024

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

from camel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.