Comments (2)
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.
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)
- [Feature Request] Allow different models for `assistant`, `user`, `task_specify_agent`, and `critic` etc in the `RolePlaying` HOT 3
- [Feature Request] Add and bind termination reason or criteria to `RolePlaying` HOT 3
- [BUG] Flacky test `test_chat_agent_batch_stream_same_output` HOT 2
- [Feature Request] Could you please offer a simple jupyter notebook illustrating the flow of generating the conversations as a new job? HOT 2
- [BUG] Many mypy errors from python_interpreter.py HOT 2
- [BUG] Mypy errors in examples HOT 2
- [BUG] Multiple set_output_language calls HOT 1
- [Feature Request] Add a Makefile for better development process
- [Feature Request] Benchmark communicative agents' generated dialogue
- [Feature Request] Intergrate `LLaMA 2` to `CAMEL` HOT 1
- [Question] Problems of embodied agent test and hugging face tool agent test HOT 1
- how set multi ai agent role HOT 1
- RuntimeError: Property msg is only availablefor a single message in msgs HOT 15
- [Feature Request] Support `Azure` OpenAI models HOT 3
- [BUG] `original_task` is not passed to the right argument in `RolePlaying` in the agent demo app HOT 3
- [Feature Request] Improve Wikipedia search HOT 1
- [BUG] Pre-commit license check fails due to encoding issues (GBK vs UTF-8) HOT 7
- [Feature Request] Automatic Role Generation with Descriptions for Two Roles
- [Feature Request] Some suggestions about project structure HOT 3
- [BUG] Multiple values of model_config HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from camel.