-
Notifications
You must be signed in to change notification settings - Fork 2.1k
add files upload in webapp and human control example #384
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,4 +145,4 @@ def main(): | |
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| # ========= Copyright 2023-2024 @ 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-2024 @ CAMEL-AI.org. All Rights Reserved. ========= | ||
| import sys | ||
| import pathlib | ||
| from dotenv import load_dotenv | ||
| from camel.models import ModelFactory | ||
| from camel.toolkits import ( | ||
| AudioAnalysisToolkit, | ||
| CodeExecutionToolkit, | ||
| ExcelToolkit, | ||
| ImageAnalysisToolkit, | ||
| SearchToolkit, | ||
| VideoAnalysisToolkit, | ||
| BrowserToolkit, | ||
| FileWriteToolkit, | ||
| HumanToolkit, | ||
| TerminalToolkit, | ||
| ) | ||
| from camel.types import ModelPlatformType, ModelType | ||
| from camel.logger import set_log_level | ||
| from camel.societies import RolePlaying | ||
|
|
||
| from owl.utils import run_society, DocumentProcessingToolkit | ||
|
|
||
| base_dir = pathlib.Path(__file__).parent.parent | ||
| env_path = base_dir / "owl" / ".env" | ||
| load_dotenv(dotenv_path=str(env_path)) | ||
|
|
||
| set_log_level(level="DEBUG") | ||
|
|
||
|
|
||
| def construct_society(question: str) -> RolePlaying: | ||
| r"""Construct a society of agents based on the given question. | ||
|
|
||
| Args: | ||
| question (str): The task or question to be addressed by the society. | ||
|
|
||
| Returns: | ||
| RolePlaying: A configured society of agents ready to address the question. | ||
| """ | ||
|
|
||
| # Create models for different components | ||
| models = { | ||
| "user": ModelFactory.create( | ||
| model_platform=ModelPlatformType.OPENAI, | ||
| model_type=ModelType.GPT_4O, | ||
| model_config_dict={"temperature": 0}, | ||
| ), | ||
| "assistant": ModelFactory.create( | ||
| model_platform=ModelPlatformType.OPENAI, | ||
| model_type=ModelType.GPT_4O, | ||
| model_config_dict={"temperature": 0}, | ||
| ), | ||
| "browsing": ModelFactory.create( | ||
| model_platform=ModelPlatformType.OPENAI, | ||
| model_type=ModelType.GPT_4O, | ||
| model_config_dict={"temperature": 0}, | ||
| ), | ||
| "planning": ModelFactory.create( | ||
| model_platform=ModelPlatformType.OPENAI, | ||
| model_type=ModelType.GPT_4O, | ||
| model_config_dict={"temperature": 0}, | ||
| ), | ||
| "video": ModelFactory.create( | ||
| model_platform=ModelPlatformType.OPENAI, | ||
| model_type=ModelType.GPT_4O, | ||
| model_config_dict={"temperature": 0}, | ||
| ), | ||
| "image": ModelFactory.create( | ||
| model_platform=ModelPlatformType.OPENAI, | ||
| model_type=ModelType.GPT_4O, | ||
| model_config_dict={"temperature": 0}, | ||
| ), | ||
| "document": ModelFactory.create( | ||
| model_platform=ModelPlatformType.OPENAI, | ||
| model_type=ModelType.GPT_4O, | ||
| model_config_dict={"temperature": 0}, | ||
| ), | ||
| } | ||
|
|
||
| # Configure toolkits | ||
| tools = [ | ||
| *HumanToolkit().get_tools(), | ||
| *TerminalToolkit().get_tools(), | ||
| *BrowserToolkit( | ||
| headless=False, # Set to True for headless mode (e.g., on remote servers) | ||
| web_agent_model=models["browsing"], | ||
| planning_agent_model=models["planning"], | ||
| ).get_tools(), | ||
| *VideoAnalysisToolkit(model=models["video"]).get_tools(), | ||
| *AudioAnalysisToolkit().get_tools(), # This requires OpenAI Key | ||
| *CodeExecutionToolkit(sandbox="subprocess", verbose=True).get_tools(), | ||
| *ImageAnalysisToolkit(model=models["image"]).get_tools(), | ||
| SearchToolkit().search_duckduckgo, | ||
| SearchToolkit().search_google, # Comment this out if you don't have google search | ||
| SearchToolkit().search_wiki, | ||
| *ExcelToolkit().get_tools(), | ||
| *DocumentProcessingToolkit(model=models["document"]).get_tools(), | ||
| *FileWriteToolkit(output_dir="./").get_tools(), | ||
| ] | ||
|
|
||
| # Configure agent roles and parameters | ||
| user_agent_kwargs = {"model": models["user"]} | ||
| assistant_agent_kwargs = {"model": models["assistant"], "tools": tools} | ||
|
|
||
| # Configure task parameters | ||
| task_kwargs = { | ||
| "task_prompt": question, | ||
| "with_task_specify": False, | ||
| } | ||
|
|
||
| # Create and return the society | ||
| society = RolePlaying( | ||
| **task_kwargs, | ||
| user_role_name="user", | ||
| user_agent_kwargs=user_agent_kwargs, | ||
| assistant_role_name="assistant", | ||
| assistant_agent_kwargs=assistant_agent_kwargs, | ||
| ) | ||
|
|
||
| return society | ||
|
|
||
|
|
||
| def main(): | ||
| r"""Main function to run the OWL system with an example question.""" | ||
| # Default research question | ||
| default_task = "Use plot to draw a heart-shaped graph, save it locally, and ask for my opinion using HumanToolkit before taking each step." | ||
|
|
||
| # Override default task if command line argument is provided | ||
| task = sys.argv[1] if len(sys.argv) > 1 else default_task | ||
|
|
||
| # Construct and run the society | ||
| society = construct_society(task) | ||
| answer, chat_history, token_count = run_society(society) | ||
|
|
||
| # Output the result | ||
| print(f"\033[94mAnswer: {answer}\033[0m") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey @zjrwtx , let's keep current web app as MVP and don't add additional non-core feature to the web app, the current arch is not good for us to do further feature development, we need to redesign the arch is we want to support more features There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okok |
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.
there's no need to add example just for some specific toolkit, we can add it to current run template, to reduce redundancy, the run_terminal one should also be refactored
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.
got it