-
Notifications
You must be signed in to change notification settings - Fork 586
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
chores: move role_playing_with_functions
from utils into example
#549
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e9febeb
move role playing with functions from utils into example
Wendong-Fan 7eb85ae
Merge branch 'master' into role_playing_example
Wendong-Fan cdd0b5c
fix
Wendong-Fan 29dd785
fix
Wendong-Fan 3da59bd
fix
Wendong-Fan 951078e
Merge branch 'master' into role_playing_example
Wendong-Fan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== | ||
# Licensed under the Apache License, Version 2.0 (the “License”); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an “AS IS” BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== | ||
|
||
from typing import List | ||
|
||
from colorama import Fore | ||
|
||
from camel.agents.chat_agent import FunctionCallingRecord | ||
from camel.configs import ChatGPTConfig | ||
from camel.functions import ( | ||
MAP_FUNCS, | ||
MATH_FUNCS, | ||
SEARCH_FUNCS, | ||
TWITTER_FUNCS, | ||
WEATHER_FUNCS, | ||
) | ||
from camel.societies import RolePlaying | ||
from camel.types import ModelType | ||
from camel.utils import print_text_animated | ||
|
||
|
||
def main(model_type=ModelType.GPT_3_5_TURBO, chat_turn_limit=10) -> None: | ||
task_prompt = ( | ||
"Assume now is 2024 in the Gregorian calendar, " | ||
"estimate the current age of University of Oxford " | ||
"and then add 10 more years to this age, " | ||
"and get the current weather of the city where " | ||
"the University is located." | ||
) | ||
|
||
user_model_config = ChatGPTConfig(temperature=0.0) | ||
|
||
function_list = [ | ||
*MATH_FUNCS, | ||
*SEARCH_FUNCS, | ||
*WEATHER_FUNCS, | ||
*MAP_FUNCS, | ||
*TWITTER_FUNCS, | ||
] | ||
assistant_model_config = ChatGPTConfig( | ||
tools=function_list, | ||
temperature=0.0, | ||
) | ||
|
||
role_play_session = RolePlaying( | ||
assistant_role_name="Searcher", | ||
user_role_name="Professor", | ||
assistant_agent_kwargs=dict( | ||
model_type=model_type, | ||
model_config=assistant_model_config, | ||
tools=function_list, | ||
), | ||
user_agent_kwargs=dict( | ||
model_type=model_type, | ||
model_config=user_model_config, | ||
), | ||
task_prompt=task_prompt, | ||
with_task_specify=False, | ||
) | ||
|
||
print( | ||
Fore.GREEN | ||
+ f"AI Assistant sys message:\n{role_play_session.assistant_sys_msg}\n" | ||
) | ||
print( | ||
Fore.BLUE + f"AI User sys message:\n{role_play_session.user_sys_msg}\n" | ||
) | ||
|
||
print(Fore.YELLOW + f"Original task prompt:\n{task_prompt}\n") | ||
print( | ||
Fore.CYAN | ||
+ f"Specified task prompt:\n{role_play_session.specified_task_prompt}\n" | ||
) | ||
print(Fore.RED + f"Final task prompt:\n{role_play_session.task_prompt}\n") | ||
|
||
n = 0 | ||
input_msg = role_play_session.init_chat() | ||
while n < chat_turn_limit: | ||
n += 1 | ||
assistant_response, user_response = role_play_session.step(input_msg) | ||
|
||
if assistant_response.terminated: | ||
print( | ||
Fore.GREEN | ||
+ ( | ||
"AI Assistant terminated. Reason: " | ||
f"{assistant_response.info['termination_reasons']}." | ||
) | ||
) | ||
break | ||
if user_response.terminated: | ||
print( | ||
Fore.GREEN | ||
+ ( | ||
"AI User terminated. " | ||
f"Reason: {user_response.info['termination_reasons']}." | ||
) | ||
) | ||
break | ||
|
||
# Print output from the user | ||
print_text_animated( | ||
Fore.BLUE + f"AI User:\n\n{user_response.msg.content}\n" | ||
) | ||
|
||
# Print output from the assistant, including any function | ||
# execution information | ||
print_text_animated(Fore.GREEN + "AI Assistant:") | ||
tool_calls: List[FunctionCallingRecord] = assistant_response.info[ | ||
'tool_calls' | ||
] | ||
for func_record in tool_calls: | ||
print_text_animated(f"{func_record}") | ||
print_text_animated(f"{assistant_response.msg.content}\n") | ||
|
||
if "CAMEL_TASK_DONE" in user_response.msg.content: | ||
break | ||
|
||
input_msg = assistant_response.msg | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The agent is initialized, so is
agent.reset()
necessary?