camel-ai 0.1.5.6__py3-none-any.whl → 0.1.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of camel-ai might be problematic. Click here for more details.
- camel/__init__.py +1 -1
- camel/agents/chat_agent.py +249 -36
- camel/agents/critic_agent.py +18 -2
- camel/agents/deductive_reasoner_agent.py +16 -4
- camel/agents/embodied_agent.py +20 -6
- camel/agents/knowledge_graph_agent.py +24 -5
- camel/agents/role_assignment_agent.py +13 -1
- camel/agents/search_agent.py +16 -5
- camel/agents/task_agent.py +20 -5
- camel/configs/__init__.py +11 -9
- camel/configs/anthropic_config.py +5 -6
- camel/configs/base_config.py +50 -4
- camel/configs/gemini_config.py +69 -17
- camel/configs/groq_config.py +105 -0
- camel/configs/litellm_config.py +2 -8
- camel/configs/mistral_config.py +78 -0
- camel/configs/ollama_config.py +5 -7
- camel/configs/openai_config.py +12 -23
- camel/configs/vllm_config.py +102 -0
- camel/configs/zhipuai_config.py +5 -11
- camel/embeddings/__init__.py +2 -0
- camel/embeddings/mistral_embedding.py +89 -0
- camel/human.py +1 -1
- camel/interpreters/__init__.py +2 -0
- camel/interpreters/ipython_interpreter.py +167 -0
- camel/loaders/__init__.py +2 -0
- camel/loaders/firecrawl_reader.py +213 -0
- camel/memories/agent_memories.py +1 -4
- camel/memories/blocks/chat_history_block.py +6 -2
- camel/memories/blocks/vectordb_block.py +3 -1
- camel/memories/context_creators/score_based.py +6 -6
- camel/memories/records.py +9 -7
- camel/messages/base.py +1 -0
- camel/models/__init__.py +8 -0
- camel/models/anthropic_model.py +7 -2
- camel/models/azure_openai_model.py +152 -0
- camel/models/base_model.py +9 -2
- camel/models/gemini_model.py +14 -2
- camel/models/groq_model.py +131 -0
- camel/models/litellm_model.py +26 -4
- camel/models/mistral_model.py +169 -0
- camel/models/model_factory.py +30 -3
- camel/models/ollama_model.py +21 -2
- camel/models/open_source_model.py +13 -5
- camel/models/openai_model.py +7 -2
- camel/models/stub_model.py +4 -4
- camel/models/vllm_model.py +138 -0
- camel/models/zhipuai_model.py +7 -4
- camel/prompts/__init__.py +8 -1
- camel/prompts/image_craft.py +34 -0
- camel/prompts/multi_condition_image_craft.py +34 -0
- camel/prompts/task_prompt_template.py +10 -4
- camel/prompts/{descripte_video_prompt.py → video_description_prompt.py} +1 -1
- camel/responses/agent_responses.py +4 -3
- camel/retrievers/auto_retriever.py +2 -2
- camel/societies/babyagi_playing.py +6 -4
- camel/societies/role_playing.py +16 -8
- camel/storages/graph_storages/graph_element.py +10 -14
- camel/storages/graph_storages/neo4j_graph.py +5 -0
- camel/storages/vectordb_storages/base.py +24 -13
- camel/storages/vectordb_storages/milvus.py +1 -1
- camel/storages/vectordb_storages/qdrant.py +2 -3
- camel/tasks/__init__.py +22 -0
- camel/tasks/task.py +408 -0
- camel/tasks/task_prompt.py +65 -0
- camel/toolkits/__init__.py +39 -0
- camel/toolkits/base.py +4 -2
- camel/toolkits/code_execution.py +1 -1
- camel/toolkits/dalle_toolkit.py +146 -0
- camel/toolkits/github_toolkit.py +19 -34
- camel/toolkits/google_maps_toolkit.py +368 -0
- camel/toolkits/math_toolkit.py +79 -0
- camel/toolkits/open_api_toolkit.py +547 -0
- camel/{functions → toolkits}/openai_function.py +2 -7
- camel/toolkits/retrieval_toolkit.py +76 -0
- camel/toolkits/search_toolkit.py +326 -0
- camel/toolkits/slack_toolkit.py +308 -0
- camel/toolkits/twitter_toolkit.py +522 -0
- camel/toolkits/weather_toolkit.py +173 -0
- camel/types/enums.py +154 -35
- camel/utils/__init__.py +14 -2
- camel/utils/async_func.py +1 -1
- camel/utils/commons.py +152 -2
- camel/utils/constants.py +3 -0
- camel/utils/token_counting.py +148 -40
- camel/workforce/__init__.py +23 -0
- camel/workforce/base.py +50 -0
- camel/workforce/manager_node.py +299 -0
- camel/workforce/role_playing_node.py +168 -0
- camel/workforce/single_agent_node.py +77 -0
- camel/workforce/task_channel.py +173 -0
- camel/workforce/utils.py +97 -0
- camel/workforce/worker_node.py +115 -0
- camel/workforce/workforce.py +49 -0
- camel/workforce/workforce_prompt.py +125 -0
- {camel_ai-0.1.5.6.dist-info → camel_ai-0.1.6.1.dist-info}/METADATA +45 -3
- camel_ai-0.1.6.1.dist-info/RECORD +182 -0
- camel/functions/__init__.py +0 -51
- camel/functions/google_maps_function.py +0 -335
- camel/functions/math_functions.py +0 -61
- camel/functions/open_api_function.py +0 -508
- camel/functions/retrieval_functions.py +0 -61
- camel/functions/search_functions.py +0 -298
- camel/functions/slack_functions.py +0 -286
- camel/functions/twitter_function.py +0 -479
- camel/functions/weather_functions.py +0 -144
- camel_ai-0.1.5.6.dist-info/RECORD +0 -157
- /camel/{functions → toolkits}/open_api_specs/biztoc/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/biztoc/ai-plugin.json +0 -0
- /camel/{functions → toolkits}/open_api_specs/biztoc/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/coursera/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/coursera/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/create_qr_code/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/create_qr_code/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/klarna/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/klarna/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/nasa_apod/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/nasa_apod/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/ai-plugin.json +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/paths/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/paths/get_classes.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/outschool/paths/search_teachers.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/security_config.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/speak/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/speak/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/ai-plugin.json +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/openapi.yaml +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/paths/__init__.py +0 -0
- /camel/{functions → toolkits}/open_api_specs/web_scraper/paths/scraper.py +0 -0
- {camel_ai-0.1.5.6.dist-info → camel_ai-0.1.6.1.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
from typing import Any, Dict, List, Optional, Union
|
|
15
|
+
|
|
16
|
+
from openai import OpenAI, Stream
|
|
17
|
+
|
|
18
|
+
from camel.configs import VLLM_API_PARAMS
|
|
19
|
+
from camel.messages import OpenAIMessage
|
|
20
|
+
from camel.types import ChatCompletion, ChatCompletionChunk, ModelType
|
|
21
|
+
from camel.utils import BaseTokenCounter, OpenAITokenCounter
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# flake8: noqa: E501
|
|
25
|
+
class VLLMModel:
|
|
26
|
+
r"""vLLM service interface."""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
model_type: str,
|
|
31
|
+
model_config_dict: Dict[str, Any],
|
|
32
|
+
url: Optional[str] = None,
|
|
33
|
+
api_key: Optional[str] = None,
|
|
34
|
+
token_counter: Optional[BaseTokenCounter] = None,
|
|
35
|
+
) -> None:
|
|
36
|
+
r"""Constructor for vLLM backend with OpenAI compatibility.
|
|
37
|
+
|
|
38
|
+
# Reference: https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
model_type (str): Model for which a backend is created.
|
|
42
|
+
model_config_dict (Dict[str, Any]): A dictionary that will
|
|
43
|
+
be fed into openai.ChatCompletion.create().
|
|
44
|
+
url (Optional[str]): The url to the model service. (default:
|
|
45
|
+
:obj:`None`)
|
|
46
|
+
api_key (Optional[str]): The API key for authenticating with the
|
|
47
|
+
model service.
|
|
48
|
+
token_counter (Optional[BaseTokenCounter]): Token counter to use
|
|
49
|
+
for the model. If not provided, `OpenAITokenCounter(ModelType.
|
|
50
|
+
GPT_3_5_TURBO)` will be used.
|
|
51
|
+
"""
|
|
52
|
+
self.model_type = model_type
|
|
53
|
+
self.model_config_dict = model_config_dict
|
|
54
|
+
# Use OpenAI cilent as interface call vLLM
|
|
55
|
+
self._client = OpenAI(
|
|
56
|
+
timeout=60,
|
|
57
|
+
max_retries=3,
|
|
58
|
+
base_url=url,
|
|
59
|
+
api_key=api_key,
|
|
60
|
+
)
|
|
61
|
+
self._token_counter = token_counter
|
|
62
|
+
self.check_model_config()
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def token_counter(self) -> BaseTokenCounter:
|
|
66
|
+
r"""Initialize the token counter for the model backend.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
BaseTokenCounter: The token counter following the model's
|
|
70
|
+
tokenization style.
|
|
71
|
+
"""
|
|
72
|
+
if not self._token_counter:
|
|
73
|
+
self._token_counter = OpenAITokenCounter(ModelType.GPT_3_5_TURBO)
|
|
74
|
+
return self._token_counter
|
|
75
|
+
|
|
76
|
+
def check_model_config(self):
|
|
77
|
+
r"""Check whether the model configuration contains any
|
|
78
|
+
unexpected arguments to vLLM API.
|
|
79
|
+
|
|
80
|
+
Raises:
|
|
81
|
+
ValueError: If the model configuration dictionary contains any
|
|
82
|
+
unexpected arguments to OpenAI API.
|
|
83
|
+
"""
|
|
84
|
+
for param in self.model_config_dict:
|
|
85
|
+
if param not in VLLM_API_PARAMS:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"Unexpected argument `{param}` is "
|
|
88
|
+
"input into vLLM model backend."
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def run(
|
|
92
|
+
self,
|
|
93
|
+
messages: List[OpenAIMessage],
|
|
94
|
+
) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
|
|
95
|
+
r"""Runs inference of OpenAI chat completion.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
messages (List[OpenAIMessage]): Message list with the chat history
|
|
99
|
+
in OpenAI API format.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Union[ChatCompletion, Stream[ChatCompletionChunk]]:
|
|
103
|
+
`ChatCompletion` in the non-stream mode, or
|
|
104
|
+
`Stream[ChatCompletionChunk]` in the stream mode.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
response = self._client.chat.completions.create(
|
|
108
|
+
messages=messages,
|
|
109
|
+
model=self.model_type,
|
|
110
|
+
**self.model_config_dict,
|
|
111
|
+
)
|
|
112
|
+
return response
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def token_limit(self) -> int:
|
|
116
|
+
"""Returns the maximum token limit for the given model.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
int: The maximum token limit for the given model.
|
|
120
|
+
"""
|
|
121
|
+
max_tokens = self.model_config_dict.get("max_tokens")
|
|
122
|
+
if isinstance(max_tokens, int):
|
|
123
|
+
return max_tokens
|
|
124
|
+
print(
|
|
125
|
+
"Must set `max_tokens` as an integer in `model_config_dict` when"
|
|
126
|
+
" setting up the model. Using 4096 as default value."
|
|
127
|
+
)
|
|
128
|
+
return 4096
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def stream(self) -> bool:
|
|
132
|
+
r"""Returns whether the model is in stream mode, which sends partial
|
|
133
|
+
results each time.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
bool: Whether the model is in stream mode.
|
|
137
|
+
"""
|
|
138
|
+
return self.model_config_dict.get('stream', False)
|
camel/models/zhipuai_model.py
CHANGED
|
@@ -37,6 +37,7 @@ class ZhipuAIModel(BaseModelBackend):
|
|
|
37
37
|
model_config_dict: Dict[str, Any],
|
|
38
38
|
api_key: Optional[str] = None,
|
|
39
39
|
url: Optional[str] = None,
|
|
40
|
+
token_counter: Optional[BaseTokenCounter] = None,
|
|
40
41
|
) -> None:
|
|
41
42
|
r"""Constructor for ZhipuAI backend.
|
|
42
43
|
|
|
@@ -49,8 +50,13 @@ class ZhipuAIModel(BaseModelBackend):
|
|
|
49
50
|
ZhipuAI service. (default: :obj:`None`)
|
|
50
51
|
url (Optional[str]): The url to the ZhipuAI service. (default:
|
|
51
52
|
:obj:`None`)
|
|
53
|
+
token_counter (Optional[BaseTokenCounter]): Token counter to use
|
|
54
|
+
for the model. If not provided, `OpenAITokenCounter(ModelType.
|
|
55
|
+
GPT_3_5_TURBO)` will be used.
|
|
52
56
|
"""
|
|
53
|
-
super().__init__(
|
|
57
|
+
super().__init__(
|
|
58
|
+
model_type, model_config_dict, api_key, url, token_counter
|
|
59
|
+
)
|
|
54
60
|
self._url = url or os.environ.get("ZHIPUAI_API_BASE_URL")
|
|
55
61
|
self._api_key = api_key or os.environ.get("ZHIPUAI_API_KEY")
|
|
56
62
|
if not self._url or not self._api_key:
|
|
@@ -63,7 +69,6 @@ class ZhipuAIModel(BaseModelBackend):
|
|
|
63
69
|
api_key=self._api_key,
|
|
64
70
|
base_url=self._url,
|
|
65
71
|
)
|
|
66
|
-
self._token_counter: Optional[BaseTokenCounter] = None
|
|
67
72
|
|
|
68
73
|
@api_keys_required("ZHIPUAI_API_KEY")
|
|
69
74
|
def run(
|
|
@@ -100,7 +105,6 @@ class ZhipuAIModel(BaseModelBackend):
|
|
|
100
105
|
"""
|
|
101
106
|
|
|
102
107
|
if not self._token_counter:
|
|
103
|
-
# It's a temporary setting for token counter.
|
|
104
108
|
self._token_counter = OpenAITokenCounter(ModelType.GPT_3_5_TURBO)
|
|
105
109
|
return self._token_counter
|
|
106
110
|
|
|
@@ -118,7 +122,6 @@ class ZhipuAIModel(BaseModelBackend):
|
|
|
118
122
|
f"Unexpected argument `{param}` is "
|
|
119
123
|
"input into ZhipuAI model backend."
|
|
120
124
|
)
|
|
121
|
-
pass
|
|
122
125
|
|
|
123
126
|
@property
|
|
124
127
|
def stream(self) -> bool:
|
camel/prompts/__init__.py
CHANGED
|
@@ -14,18 +14,22 @@
|
|
|
14
14
|
from .ai_society import AISocietyPromptTemplateDict
|
|
15
15
|
from .base import CodePrompt, TextPrompt, TextPromptDict
|
|
16
16
|
from .code import CodePromptTemplateDict
|
|
17
|
-
from .descripte_video_prompt import DescriptionVideoPromptTemplateDict
|
|
18
17
|
from .evaluation import EvaluationPromptTemplateDict
|
|
19
18
|
from .generate_text_embedding_data import (
|
|
20
19
|
GenerateTextEmbeddingDataPromptTemplateDict,
|
|
21
20
|
)
|
|
21
|
+
from .image_craft import ImageCraftPromptTemplateDict
|
|
22
22
|
from .misalignment import MisalignmentPromptTemplateDict
|
|
23
|
+
from .multi_condition_image_craft import (
|
|
24
|
+
MultiConditionImageCraftPromptTemplateDict,
|
|
25
|
+
)
|
|
23
26
|
from .object_recognition import ObjectRecognitionPromptTemplateDict
|
|
24
27
|
from .prompt_templates import PromptTemplateGenerator
|
|
25
28
|
from .role_description_prompt_template import RoleDescriptionPromptTemplateDict
|
|
26
29
|
from .solution_extraction import SolutionExtractionPromptTemplateDict
|
|
27
30
|
from .task_prompt_template import TaskPromptTemplateDict
|
|
28
31
|
from .translation import TranslationPromptTemplateDict
|
|
32
|
+
from .video_description_prompt import VideoDescriptionPromptTemplateDict
|
|
29
33
|
|
|
30
34
|
__all__ = [
|
|
31
35
|
'TextPrompt',
|
|
@@ -42,5 +46,8 @@ __all__ = [
|
|
|
42
46
|
'SolutionExtractionPromptTemplateDict',
|
|
43
47
|
'GenerateTextEmbeddingDataPromptTemplateDict',
|
|
44
48
|
'ObjectRecognitionPromptTemplateDict',
|
|
49
|
+
'ImageCraftPromptTemplateDict',
|
|
50
|
+
'MultiConditionImageCraftPromptTemplateDict',
|
|
45
51
|
'DescriptionVideoPromptTemplateDict',
|
|
52
|
+
'VideoDescriptionPromptTemplateDict',
|
|
46
53
|
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from camel.prompts import TextPrompt, TextPromptDict
|
|
17
|
+
from camel.types import RoleType
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ImageCraftPromptTemplateDict(TextPromptDict):
|
|
21
|
+
ASSISTANT_PROMPT = TextPrompt(
|
|
22
|
+
"""You are tasked with creating an original image based on
|
|
23
|
+
the provided descriptive captions. Use your imagination
|
|
24
|
+
and artistic skills to visualize and draw the images and
|
|
25
|
+
explain your thought process."""
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
29
|
+
super().__init__(*args, **kwargs)
|
|
30
|
+
self.update(
|
|
31
|
+
{
|
|
32
|
+
RoleType.ASSISTANT: self.ASSISTANT_PROMPT,
|
|
33
|
+
}
|
|
34
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the “License”);
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an “AS IS” BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from camel.prompts import TextPrompt, TextPromptDict
|
|
17
|
+
from camel.types import RoleType
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MultiConditionImageCraftPromptTemplateDict(TextPromptDict):
|
|
21
|
+
ASSISTANT_PROMPT = TextPrompt(
|
|
22
|
+
"""You are tasked with creating an image based on
|
|
23
|
+
the provided text and images conditions. Please use your
|
|
24
|
+
imagination and artistic capabilities to visualize and
|
|
25
|
+
draw the images and explain what you are thinking about."""
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
29
|
+
super().__init__(*args, **kwargs)
|
|
30
|
+
self.update(
|
|
31
|
+
{
|
|
32
|
+
RoleType.ASSISTANT: self.ASSISTANT_PROMPT,
|
|
33
|
+
}
|
|
34
|
+
)
|
|
@@ -18,16 +18,17 @@ from camel.prompts.ai_society import (
|
|
|
18
18
|
TextPromptDict,
|
|
19
19
|
)
|
|
20
20
|
from camel.prompts.code import CodePromptTemplateDict
|
|
21
|
-
from camel.prompts.descripte_video_prompt import (
|
|
22
|
-
DescriptionVideoPromptTemplateDict,
|
|
23
|
-
)
|
|
24
21
|
from camel.prompts.evaluation import (
|
|
25
22
|
EvaluationPromptTemplateDict,
|
|
26
23
|
)
|
|
27
24
|
from camel.prompts.generate_text_embedding_data import (
|
|
28
25
|
GenerateTextEmbeddingDataPromptTemplateDict,
|
|
29
26
|
)
|
|
27
|
+
from camel.prompts.image_craft import ImageCraftPromptTemplateDict
|
|
30
28
|
from camel.prompts.misalignment import MisalignmentPromptTemplateDict
|
|
29
|
+
from camel.prompts.multi_condition_image_craft import (
|
|
30
|
+
MultiConditionImageCraftPromptTemplateDict,
|
|
31
|
+
)
|
|
31
32
|
from camel.prompts.object_recognition import (
|
|
32
33
|
ObjectRecognitionPromptTemplateDict,
|
|
33
34
|
)
|
|
@@ -38,6 +39,9 @@ from camel.prompts.solution_extraction import (
|
|
|
38
39
|
SolutionExtractionPromptTemplateDict,
|
|
39
40
|
)
|
|
40
41
|
from camel.prompts.translation import TranslationPromptTemplateDict
|
|
42
|
+
from camel.prompts.video_description_prompt import (
|
|
43
|
+
VideoDescriptionPromptTemplateDict,
|
|
44
|
+
)
|
|
41
45
|
from camel.types import TaskType
|
|
42
46
|
|
|
43
47
|
|
|
@@ -64,6 +68,8 @@ class TaskPromptTemplateDict(Dict[Any, TextPromptDict]):
|
|
|
64
68
|
TaskType.ROLE_DESCRIPTION: RoleDescriptionPromptTemplateDict(),
|
|
65
69
|
TaskType.OBJECT_RECOGNITION: ObjectRecognitionPromptTemplateDict(), # noqa: E501
|
|
66
70
|
TaskType.GENERATE_TEXT_EMBEDDING_DATA: GenerateTextEmbeddingDataPromptTemplateDict(), # noqa: E501
|
|
67
|
-
TaskType.
|
|
71
|
+
TaskType.IMAGE_CRAFT: ImageCraftPromptTemplateDict(),
|
|
72
|
+
TaskType.MULTI_CONDITION_IMAGE_CRAFT: MultiConditionImageCraftPromptTemplateDict(), # noqa: E501
|
|
73
|
+
TaskType.VIDEO_DESCRIPTION: VideoDescriptionPromptTemplateDict(), # noqa: E501
|
|
68
74
|
}
|
|
69
75
|
)
|
|
@@ -18,7 +18,7 @@ from camel.types import RoleType
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
# flake8: noqa :E501
|
|
21
|
-
class
|
|
21
|
+
class VideoDescriptionPromptTemplateDict(TextPromptDict):
|
|
22
22
|
ASSISTANT_PROMPT = TextPrompt(
|
|
23
23
|
"""You are a master of video analysis.
|
|
24
24
|
Please provide a shot description of the content of the current video."""
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
-
from dataclasses import dataclass
|
|
15
14
|
from typing import Any, Dict, List
|
|
16
15
|
|
|
16
|
+
from pydantic import BaseModel, ConfigDict
|
|
17
|
+
|
|
17
18
|
from camel.messages import BaseMessage
|
|
18
19
|
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
class ChatAgentResponse:
|
|
21
|
+
class ChatAgentResponse(BaseModel):
|
|
22
22
|
r"""Response of a ChatAgent.
|
|
23
23
|
|
|
24
24
|
Attributes:
|
|
@@ -31,6 +31,7 @@ class ChatAgentResponse:
|
|
|
31
31
|
info (Dict[str, Any]): Extra information about the chat message.
|
|
32
32
|
"""
|
|
33
33
|
|
|
34
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
34
35
|
msgs: List[BaseMessage]
|
|
35
36
|
terminated: bool
|
|
36
37
|
info: Dict[str, Any]
|
|
@@ -235,8 +235,6 @@ class AutoRetriever:
|
|
|
235
235
|
else content_input_paths
|
|
236
236
|
)
|
|
237
237
|
|
|
238
|
-
vr = VectorRetriever()
|
|
239
|
-
|
|
240
238
|
all_retrieved_info = []
|
|
241
239
|
for content_input_path in content_input_paths:
|
|
242
240
|
# Generate a valid collection name
|
|
@@ -283,12 +281,14 @@ class AutoRetriever:
|
|
|
283
281
|
vr = VectorRetriever(
|
|
284
282
|
storage=vector_storage_instance,
|
|
285
283
|
similarity_threshold=similarity_threshold,
|
|
284
|
+
embedding_model=self.embedding_model,
|
|
286
285
|
)
|
|
287
286
|
vr.process(content_input_path)
|
|
288
287
|
else:
|
|
289
288
|
vr = VectorRetriever(
|
|
290
289
|
storage=vector_storage_instance,
|
|
291
290
|
similarity_threshold=similarity_threshold,
|
|
291
|
+
embedding_model=self.embedding_model,
|
|
292
292
|
)
|
|
293
293
|
# Retrieve info by given query from the vector storage
|
|
294
294
|
retrieved_info = vr.query(query, top_k)
|
|
@@ -270,10 +270,12 @@ class BabyAGI:
|
|
|
270
270
|
"All tasks are solved"
|
|
271
271
|
)
|
|
272
272
|
return ChatAgentResponse(
|
|
273
|
-
[assistant_msg],
|
|
273
|
+
msgs=[assistant_msg],
|
|
274
|
+
terminated=terminated,
|
|
275
|
+
info=assistant_response.info,
|
|
274
276
|
)
|
|
275
277
|
return ChatAgentResponse(
|
|
276
|
-
[assistant_msg],
|
|
277
|
-
assistant_response.terminated,
|
|
278
|
-
assistant_response.info,
|
|
278
|
+
msgs=[assistant_msg],
|
|
279
|
+
terminated=assistant_response.terminated,
|
|
280
|
+
info=assistant_response.info,
|
|
279
281
|
)
|
camel/societies/role_playing.py
CHANGED
|
@@ -478,9 +478,11 @@ class RolePlaying:
|
|
|
478
478
|
user_response = self.user_agent.step(assistant_msg)
|
|
479
479
|
if user_response.terminated or user_response.msgs is None:
|
|
480
480
|
return (
|
|
481
|
-
ChatAgentResponse([], False, {}),
|
|
481
|
+
ChatAgentResponse(msgs=[], terminated=False, info={}),
|
|
482
482
|
ChatAgentResponse(
|
|
483
|
-
[],
|
|
483
|
+
msgs=[],
|
|
484
|
+
terminated=user_response.terminated,
|
|
485
|
+
info=user_response.info,
|
|
484
486
|
),
|
|
485
487
|
)
|
|
486
488
|
user_msg = self._reduce_message_options(user_response.msgs)
|
|
@@ -490,20 +492,26 @@ class RolePlaying:
|
|
|
490
492
|
if assistant_response.terminated or assistant_response.msgs is None:
|
|
491
493
|
return (
|
|
492
494
|
ChatAgentResponse(
|
|
493
|
-
[],
|
|
495
|
+
msgs=[],
|
|
496
|
+
terminated=assistant_response.terminated,
|
|
497
|
+
info=assistant_response.info,
|
|
498
|
+
),
|
|
499
|
+
ChatAgentResponse(
|
|
500
|
+
msgs=[user_msg], terminated=False, info=user_response.info
|
|
494
501
|
),
|
|
495
|
-
ChatAgentResponse([user_msg], False, user_response.info),
|
|
496
502
|
)
|
|
497
503
|
assistant_msg = self._reduce_message_options(assistant_response.msgs)
|
|
498
504
|
self.assistant_agent.record_message(assistant_msg)
|
|
499
505
|
|
|
500
506
|
return (
|
|
501
507
|
ChatAgentResponse(
|
|
502
|
-
[assistant_msg],
|
|
503
|
-
assistant_response.terminated,
|
|
504
|
-
assistant_response.info,
|
|
508
|
+
msgs=[assistant_msg],
|
|
509
|
+
terminated=assistant_response.terminated,
|
|
510
|
+
info=assistant_response.info,
|
|
505
511
|
),
|
|
506
512
|
ChatAgentResponse(
|
|
507
|
-
[user_msg],
|
|
513
|
+
msgs=[user_msg],
|
|
514
|
+
terminated=user_response.terminated,
|
|
515
|
+
info=user_response.info,
|
|
508
516
|
),
|
|
509
517
|
)
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
14
|
from __future__ import annotations
|
|
15
15
|
|
|
16
|
-
from dataclasses import dataclass, field
|
|
17
16
|
from typing import List, Union
|
|
18
17
|
|
|
18
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
19
|
+
|
|
19
20
|
try:
|
|
20
21
|
from unstructured.documents.elements import Element
|
|
21
22
|
except ImportError:
|
|
22
23
|
Element = None
|
|
23
24
|
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
class Node:
|
|
26
|
+
class Node(BaseModel):
|
|
27
27
|
r"""Represents a node in a graph with associated properties.
|
|
28
28
|
|
|
29
29
|
Attributes:
|
|
@@ -35,11 +35,10 @@ class Node:
|
|
|
35
35
|
|
|
36
36
|
id: Union[str, int]
|
|
37
37
|
type: str = "Node"
|
|
38
|
-
properties: dict =
|
|
38
|
+
properties: dict = Field(default_factory=dict)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
class Relationship:
|
|
41
|
+
class Relationship(BaseModel):
|
|
43
42
|
r"""Represents a directed relationship between two nodes in a graph.
|
|
44
43
|
|
|
45
44
|
Attributes:
|
|
@@ -53,24 +52,21 @@ class Relationship:
|
|
|
53
52
|
subj: Node
|
|
54
53
|
obj: Node
|
|
55
54
|
type: str = "Relationship"
|
|
56
|
-
properties: dict =
|
|
55
|
+
properties: dict = Field(default_factory=dict)
|
|
57
56
|
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
class GraphElement:
|
|
58
|
+
class GraphElement(BaseModel):
|
|
61
59
|
r"""A graph element with lists of nodes and relationships.
|
|
62
60
|
|
|
63
61
|
Attributes:
|
|
64
62
|
nodes (List[Node]): A list of nodes in the graph.
|
|
65
63
|
relationships (List[Relationship]): A list of relationships in the
|
|
66
|
-
|
|
64
|
+
graph.
|
|
67
65
|
source (Element): The element from which the graph information is
|
|
68
|
-
|
|
66
|
+
derived.
|
|
69
67
|
"""
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
class Config:
|
|
73
|
-
arbitrary_types_allowed = True
|
|
69
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
74
70
|
|
|
75
71
|
nodes: List[Node]
|
|
76
72
|
relationships: List[Relationship]
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
14
|
import logging
|
|
15
|
+
import os
|
|
15
16
|
from hashlib import md5
|
|
16
17
|
from typing import Any, Dict, List, Optional
|
|
17
18
|
|
|
@@ -95,6 +96,10 @@ class Neo4jGraph(BaseGraphStorage):
|
|
|
95
96
|
r"""Create a new Neo4j graph instance."""
|
|
96
97
|
import neo4j
|
|
97
98
|
|
|
99
|
+
url = os.environ.get("NEO4J_URI") or url
|
|
100
|
+
username = os.environ.get("NEO4J_USERNAME") or username
|
|
101
|
+
password = os.environ.get("NEO4J_PASSWORD") or password
|
|
102
|
+
|
|
98
103
|
self.driver = neo4j.GraphDatabase.driver(
|
|
99
104
|
url, auth=(username, password)
|
|
100
105
|
)
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
14
|
|
|
15
15
|
from abc import ABC, abstractmethod
|
|
16
|
-
from dataclasses import dataclass, field
|
|
17
16
|
from typing import Any, Dict, List, Optional
|
|
18
17
|
from uuid import uuid4
|
|
19
18
|
|
|
19
|
+
from pydantic import BaseModel, Field
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
class VectorRecord:
|
|
21
|
+
|
|
22
|
+
class VectorRecord(BaseModel):
|
|
23
23
|
r"""Encapsulates information about a vector's unique identifier and its
|
|
24
24
|
payload, which is primarily used as a data transfer object when saving
|
|
25
25
|
to vector storage.
|
|
@@ -33,12 +33,11 @@ class VectorRecord:
|
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
35
|
vector: List[float]
|
|
36
|
-
id: str =
|
|
36
|
+
id: str = Field(default_factory=lambda: str(uuid4()))
|
|
37
37
|
payload: Optional[Dict[str, Any]] = None
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
class VectorDBQuery:
|
|
40
|
+
class VectorDBQuery(BaseModel):
|
|
42
41
|
r"""Represents a query to a vector database.
|
|
43
42
|
|
|
44
43
|
Attributes:
|
|
@@ -49,11 +48,24 @@ class VectorDBQuery:
|
|
|
49
48
|
"""
|
|
50
49
|
|
|
51
50
|
query_vector: List[float]
|
|
51
|
+
"""The numerical representation of the query vector."""
|
|
52
52
|
top_k: int = 1
|
|
53
|
+
"""The number of top similar vectors to retrieve from the database."""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self, query_vector: List[float], top_k: int, **kwargs: Any
|
|
57
|
+
) -> None:
|
|
58
|
+
"""Pass in query_vector and tok_k as positional arg.
|
|
59
|
+
Args:
|
|
60
|
+
query_vector (List[float]): The numerical representation of the
|
|
61
|
+
query vector.
|
|
62
|
+
top_k (int, optional): The number of top similar vectors to
|
|
63
|
+
retrieve from the database. (default: :obj:`1`)
|
|
64
|
+
"""
|
|
65
|
+
super().__init__(query_vector=query_vector, top_k=top_k, **kwargs)
|
|
53
66
|
|
|
54
67
|
|
|
55
|
-
|
|
56
|
-
class VectorDBQueryResult:
|
|
68
|
+
class VectorDBQueryResult(BaseModel):
|
|
57
69
|
r"""Encapsulates the result of a query against a vector database.
|
|
58
70
|
|
|
59
71
|
Attributes:
|
|
@@ -66,7 +78,7 @@ class VectorDBQueryResult:
|
|
|
66
78
|
similarity: float
|
|
67
79
|
|
|
68
80
|
@classmethod
|
|
69
|
-
def
|
|
81
|
+
def create(
|
|
70
82
|
cls,
|
|
71
83
|
similarity: float,
|
|
72
84
|
vector: List[float],
|
|
@@ -75,13 +87,12 @@ class VectorDBQueryResult:
|
|
|
75
87
|
) -> "VectorDBQueryResult":
|
|
76
88
|
r"""A class method to construct a `VectorDBQueryResult` instance."""
|
|
77
89
|
return cls(
|
|
78
|
-
record=VectorRecord(vector, id, payload),
|
|
90
|
+
record=VectorRecord(vector=vector, id=id, payload=payload),
|
|
79
91
|
similarity=similarity,
|
|
80
92
|
)
|
|
81
93
|
|
|
82
94
|
|
|
83
|
-
|
|
84
|
-
class VectorDBStatus:
|
|
95
|
+
class VectorDBStatus(BaseModel):
|
|
85
96
|
r"""Vector database status.
|
|
86
97
|
|
|
87
98
|
Attributes:
|
|
@@ -195,7 +206,7 @@ class BaseVectorStorage(ABC):
|
|
|
195
206
|
List[List[Dict[str, Any]]]: A list of vector payloads retrieved
|
|
196
207
|
from the storage based on similarity to the query vector.
|
|
197
208
|
"""
|
|
198
|
-
results = self.query(VectorDBQuery(vector, top_k))
|
|
209
|
+
results = self.query(VectorDBQuery(query_vector=vector, top_k=top_k))
|
|
199
210
|
return [
|
|
200
211
|
result.record.payload
|
|
201
212
|
for result in results
|
|
@@ -361,7 +361,7 @@ class MilvusStorage(BaseVectorStorage):
|
|
|
361
361
|
query_results = []
|
|
362
362
|
for point in search_result:
|
|
363
363
|
query_results.append(
|
|
364
|
-
VectorDBQueryResult.
|
|
364
|
+
VectorDBQueryResult.create(
|
|
365
365
|
similarity=(point[0]['distance']),
|
|
366
366
|
id=str(point[0]['id']),
|
|
367
367
|
payload=(point[0]['entity'].get('payload')),
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
|
|
14
|
-
from dataclasses import asdict
|
|
15
14
|
from datetime import datetime
|
|
16
15
|
from typing import Any, Dict, List, Optional, Tuple, Union, cast
|
|
17
16
|
|
|
@@ -261,7 +260,7 @@ class QdrantStorage(BaseVectorStorage):
|
|
|
261
260
|
"""
|
|
262
261
|
from qdrant_client.http.models import PointStruct, UpdateStatus
|
|
263
262
|
|
|
264
|
-
qdrant_points = [PointStruct(**
|
|
263
|
+
qdrant_points = [PointStruct(**p.model_dump()) for p in records]
|
|
265
264
|
op_info = self._client.upsert(
|
|
266
265
|
collection_name=self.collection_name,
|
|
267
266
|
points=qdrant_points,
|
|
@@ -340,7 +339,7 @@ class QdrantStorage(BaseVectorStorage):
|
|
|
340
339
|
query_results = []
|
|
341
340
|
for point in search_result:
|
|
342
341
|
query_results.append(
|
|
343
|
-
VectorDBQueryResult.
|
|
342
|
+
VectorDBQueryResult.create(
|
|
344
343
|
similarity=point.score,
|
|
345
344
|
id=str(point.id),
|
|
346
345
|
payload=point.payload,
|