Open lightaime opened 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.
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
Structure of docs:
References: https://www.cmsdrupal.com/blog/anatomy-great-open-source-documentation-how-document-your-projects-github
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: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!