Skip to content

Commit

Permalink
fix: output_language setting in ChatAgent (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wendong-Fan authored Nov 10, 2024
1 parent 62f0c90 commit 32f19f5
Show file tree
Hide file tree
Showing 26 changed files with 61 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ body:
attributes:
label: What version of camel are you using?
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
placeholder: E.g., 0.2.6
placeholder: E.g., 0.2.7
validations:
required: true

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ conda create --name camel python=3.10
conda activate camel
# Clone github repo
git clone -b v0.2.6 https://github.com/camel-ai/camel.git
git clone -b v0.2.7 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
Expand Down
2 changes: 1 addition & 1 deletion camel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========

__version__ = '0.2.6'
__version__ = '0.2.7'

__all__ = [
'__version__',
Expand Down
17 changes: 12 additions & 5 deletions camel/agents/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ def __init__(
model_type=ModelType.DEFAULT,
)
)
self.output_language: Optional[str] = output_language
if self.output_language is not None:
self.set_output_language(self.output_language)

self.model_type = self.model_backend.model_type

Expand Down Expand Up @@ -218,6 +215,10 @@ def __init__(
context_creator, window_size=message_window_size
)

self.output_language: Optional[str] = output_language
if self.output_language is not None:
self.set_output_language(self.output_language)

self.terminated: bool = False
self.response_terminators = response_terminators or []
self.init_messages()
Expand Down Expand Up @@ -371,13 +372,19 @@ def set_output_language(self, output_language: str) -> BaseMessage:
self._system_message = self.orig_sys_message.create_new_instance(
content
)
return self._system_message
else:
self._system_message = BaseMessage.make_assistant_message(
role_name="Assistant",
content=language_prompt,
)
return self._system_message

system_record = MemoryRecord(
message=self._system_message,
role_at_backend=OpenAIBackendRole.SYSTEM,
)
self.memory.clear()
self.memory.write_record(system_record)
return self._system_message

def get_info(
self,
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
project = 'CAMEL'
copyright = '2024, CAMEL-AI.org'
author = 'CAMEL-AI.org'
release = '0.2.6'
release = '0.2.7'

html_favicon = (
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/agents_message.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai==0.2.6\""
"!pip install \"camel-ai==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/agents_prompting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai==0.2.6\""
"!pip install \"camel-ai==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/agents_society.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai==0.2.6\""
"!pip install \"camel-ai==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/agents_tracking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"outputs": [],
"source": [
"%pip install camel-ai[all]==0.2.6\n",
"%pip install camel-ai[all]==0.2.7\n",
"%pip install agentops==0.3.10"
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/agents_with_memory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai[all]==0.2.6\""
"!pip install \"camel-ai[all]==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/agents_with_rag.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai[all]==0.2.6\""
"!pip install \"camel-ai[all]==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/agents_with_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai[all]==0.2.6\""
"!pip install \"camel-ai[all]==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/create_your_first_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
{
"cell_type": "code",
"source": [
"!pip install \"camel-ai[all]==0.2.6\""
"!pip install \"camel-ai[all]==0.2.7\""
],
"metadata": {
"id": "UtcC3c-KVZmU"
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/create_your_first_agents_society.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{
"cell_type": "code",
"source": [
"!pip install \"camel-ai==0.2.6\""
"!pip install \"camel-ai==0.2.7\""
],
"metadata": {
"id": "RiwfwyyLYYxo"
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/critic_agents_and_tree_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
{
"cell_type": "code",
"source": [
"%pip install \"camel-ai==0.2.6\""
"%pip install \"camel-ai==0.2.7\""
],
"metadata": {
"id": "UtcC3c-KVZmU"
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/embodied_agents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{
"cell_type": "code",
"source": [
"%pip install \"camel-ai==0.2.6\""
"%pip install \"camel-ai==0.2.7\""
],
"metadata": {
"id": "UtcC3c-KVZmU"
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/knowledge_graph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"outputs": [],
"source": [
"pip install \"camel-ai[all]==0.2.6\""
"pip install \"camel-ai[all]==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/model_speed_comparison.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{
"cell_type": "code",
"source": [
"!pip install \"camel-ai==0.2.6\""
"!pip install \"camel-ai==0.2.7\""
],
"metadata": {
"id": "UtcC3c-KVZmU"
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/roleplaying_scraper.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai[all]==0.2.6\""
"!pip install \"camel-ai[all]==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/task_generation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"outputs": [],
"source": [
"!pip install \"camel-ai==0.2.6\""
"!pip install \"camel-ai==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/video_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"outputs": [],
"source": [
"%pip install \"camel-ai[all]==0.2.6\""
"%pip install \"camel-ai[all]==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/cookbooks/workforce_judge_committee.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"outputs": [],
"source": [
"%pip install \"camel-ai[all]==0.2.6\""
"%pip install \"camel-ai[all]==0.2.7\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/get_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ conda create --name camel python=3.10
conda activate camel
# Clone github repo
git clone -b v0.2.6 https://github.com/camel-ai/camel.git
git clone -b v0.2.7 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
Expand Down
4 changes: 2 additions & 2 deletions docs/key_modules/loaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ response = jina_reader.read_content("https://docs.camel-ai.org/")
print(response)
```
```markdown
>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.6 documentation
>>>Welcome to CAMEL’s documentation! — CAMEL 0.2.7 documentation
===============

[Skip to main content](https://docs.camel-ai.org/#main-content)

Back to top Ctrl+K

[![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.6](https://docs.camel-ai.org/#)
[![Image 1](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png) ![Image 2](https://raw.githubusercontent.com/camel-ai/camel/master/misc/logo_light.png)CAMEL 0.2.7](https://docs.camel-ai.org/#)

Search Ctrl+K

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "camel-ai"
version = "0.2.6"
version = "0.2.7"
authors = ["CAMEL-AI.org"]
description = "Communicative Agents for AI Society Study"
readme = "README.md"
Expand Down
50 changes: 24 additions & 26 deletions test/agents/test_chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,13 @@ def test_set_output_language():
assert agent.output_language == output_language

# Verify that the system message is updated with the new output language
updated_system_message = BaseMessage(
role_name="assistant",
role_type=RoleType.ASSISTANT,
meta_dict=None,
content="You are a help assistant."
"\nRegardless of the input language, you must output text in Arabic.",
)
assert agent.system_message.content == updated_system_message.content
updated_system_message = {
'role': 'system',
'content': 'You are a help assistant.\nRegardless of the '
'input language, you must output text in Arabic.',
}
memory_content = agent.memory.get_context()
assert memory_content[0][0] == updated_system_message


@pytest.mark.model_backend
Expand All @@ -444,28 +443,27 @@ def test_set_multiple_output_language():
agent_without_sys_msg.set_output_language("English")
agent_without_sys_msg.set_output_language("French")

updated_system_message_with_content = BaseMessage(
role_name="assistant",
role_type=RoleType.ASSISTANT,
meta_dict=None,
content="You are a help assistant."
"\nRegardless of the input language, you must output text in French.",
)
updated_system_message_without_content = BaseMessage(
role_name="assistant",
role_type=RoleType.ASSISTANT,
meta_dict=None,
content="\nRegardless of the input language, you must output text "
"in French.",
)
updated_system_message_with_sys_msg = {
'role': 'system',
'content': 'You are a help assistant.\nRegardless of the '
'input language, you must output text in French.',
}
updated_system_message_without_sys_msg = {
'role': 'system',
'content': '\nRegardless of the input language, you must output '
'text in French.',
}

memory_content_with_sys_msg = agent_with_sys_msg.memory.get_context()
memory_content_without_sys_msg = agent_without_sys_msg.memory.get_context()

assert (
agent_with_sys_msg.system_message.content
== updated_system_message_with_content.content
memory_content_with_sys_msg[0][0]
== updated_system_message_with_sys_msg
)
assert (
agent_without_sys_msg.system_message.content
== updated_system_message_without_content.content
memory_content_without_sys_msg[0][0]
== updated_system_message_without_sys_msg
)


Expand Down

0 comments on commit 32f19f5

Please sign in to comment.