thekage91
commited on
Commit
·
1ef515b
1
Parent(s):
7a11f89
Add run script to use Groq provider
Browse files- owl/.env_template +3 -0
- owl/run_groq.py +140 -0
owl/.env_template
CHANGED
@@ -4,6 +4,9 @@
|
|
4 |
# OPENAI_API_KEY= ""
|
5 |
# OPENAI_API_BASE_URL=""
|
6 |
|
|
|
|
|
|
|
7 |
# Azure OpenAI API
|
8 |
# AZURE_OPENAI_BASE_URL=""
|
9 |
# AZURE_API_VERSION=""
|
|
|
4 |
# OPENAI_API_KEY= ""
|
5 |
# OPENAI_API_BASE_URL=""
|
6 |
|
7 |
+
# When using GROQ remember to set OPENAI_API_BASE_URL to https://api.groq.com/openai/v1 to use the groq model according to https://console.groq.com/docs/openai
|
8 |
+
# GROQ_API_KEY=""
|
9 |
+
|
10 |
# Azure OpenAI API
|
11 |
# AZURE_OPENAI_BASE_URL=""
|
12 |
# AZURE_API_VERSION=""
|
owl/run_groq.py
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ========= Copyright 2023-2024 @ 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-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
14 |
+
from dotenv import load_dotenv
|
15 |
+
from camel.models import ModelFactory
|
16 |
+
from camel.toolkits import (
|
17 |
+
AudioAnalysisToolkit,
|
18 |
+
CodeExecutionToolkit,
|
19 |
+
ExcelToolkit,
|
20 |
+
ImageAnalysisToolkit,
|
21 |
+
SearchToolkit,
|
22 |
+
VideoAnalysisToolkit,
|
23 |
+
BrowserToolkit,
|
24 |
+
FileWriteToolkit,
|
25 |
+
)
|
26 |
+
from camel.types import ModelPlatformType, ModelType
|
27 |
+
from camel.logger import set_log_level
|
28 |
+
|
29 |
+
from utils import OwlRolePlaying, run_society, DocumentProcessingToolkit
|
30 |
+
|
31 |
+
load_dotenv()
|
32 |
+
|
33 |
+
set_log_level(level="DEBUG")
|
34 |
+
|
35 |
+
|
36 |
+
def construct_society(question: str) -> OwlRolePlaying:
|
37 |
+
r"""Construct a society of agents based on the given question.
|
38 |
+
|
39 |
+
Args:
|
40 |
+
question (str): The task or question to be addressed by the society.
|
41 |
+
|
42 |
+
Returns:
|
43 |
+
OwlRolePlaying: A configured society of agents ready to address the question.
|
44 |
+
"""
|
45 |
+
|
46 |
+
# Create models for different components
|
47 |
+
models = {
|
48 |
+
"user": ModelFactory.create(
|
49 |
+
model_platform=ModelPlatformType.GROQ,
|
50 |
+
model_type=ModelType.GROQ_LLAMA_3_1_8B,
|
51 |
+
model_config_dict={"temperature": 0},
|
52 |
+
),
|
53 |
+
"assistant": ModelFactory.create(
|
54 |
+
model_platform=ModelPlatformType.GROQ,
|
55 |
+
model_type=ModelType.GROQ_LLAMA_3_1_8B,
|
56 |
+
model_config_dict={"temperature": 0},
|
57 |
+
),
|
58 |
+
"web": ModelFactory.create(
|
59 |
+
model_platform=ModelPlatformType.GROQ,
|
60 |
+
model_type=ModelType.GROQ_LLAMA_3_1_8B,
|
61 |
+
model_config_dict={"temperature": 0},
|
62 |
+
),
|
63 |
+
"planning": ModelFactory.create(
|
64 |
+
model_platform=ModelPlatformType.GROQ,
|
65 |
+
model_type=ModelType.GROQ_LLAMA_3_1_8B,
|
66 |
+
model_config_dict={"temperature": 0},
|
67 |
+
),
|
68 |
+
"video": ModelFactory.create(
|
69 |
+
model_platform=ModelPlatformType.GROQ,
|
70 |
+
model_type=ModelType.GROQ_LLAMA_3_1_8B,
|
71 |
+
model_config_dict={"temperature": 0},
|
72 |
+
),
|
73 |
+
"image": ModelFactory.create(
|
74 |
+
model_platform=ModelPlatformType.GROQ,
|
75 |
+
model_type=ModelType.GROQ_LLAMA_3_1_8B,
|
76 |
+
model_config_dict={"temperature": 0},
|
77 |
+
),
|
78 |
+
"document": ModelFactory.create(
|
79 |
+
model_platform=ModelPlatformType.GROQ,
|
80 |
+
model_type=ModelType.GROQ_LLAMA_3_1_8B,
|
81 |
+
model_config_dict={"temperature": 0},
|
82 |
+
),
|
83 |
+
}
|
84 |
+
|
85 |
+
# Configure toolkits
|
86 |
+
tools = [
|
87 |
+
*BrowserToolkit(
|
88 |
+
headless=False, # Set to True for headless mode (e.g., on remote servers)
|
89 |
+
web_agent_model=models["web"],
|
90 |
+
planning_agent_model=models["planning"],
|
91 |
+
).get_tools(),
|
92 |
+
*VideoAnalysisToolkit(model=models["video"]).get_tools(),
|
93 |
+
*AudioAnalysisToolkit().get_tools(), # This requires OpenAI Key
|
94 |
+
*CodeExecutionToolkit(sandbox="subprocess", verbose=True).get_tools(),
|
95 |
+
*ImageAnalysisToolkit(model=models["image"]).get_tools(),
|
96 |
+
SearchToolkit().search_duckduckgo,
|
97 |
+
SearchToolkit().search_google, # Comment this out if you don't have google search
|
98 |
+
SearchToolkit().search_wiki,
|
99 |
+
*ExcelToolkit().get_tools(),
|
100 |
+
*DocumentProcessingToolkit(model=models["document"]).get_tools(),
|
101 |
+
*FileWriteToolkit(output_dir="./").get_tools(),
|
102 |
+
]
|
103 |
+
|
104 |
+
# Configure agent roles and parameters
|
105 |
+
user_agent_kwargs = {"model": models["user"]}
|
106 |
+
assistant_agent_kwargs = {"model": models["assistant"], "tools": tools}
|
107 |
+
|
108 |
+
# Configure task parameters
|
109 |
+
task_kwargs = {
|
110 |
+
"task_prompt": question,
|
111 |
+
"with_task_specify": False,
|
112 |
+
}
|
113 |
+
|
114 |
+
# Create and return the society
|
115 |
+
society = OwlRolePlaying(
|
116 |
+
**task_kwargs,
|
117 |
+
user_role_name="user",
|
118 |
+
user_agent_kwargs=user_agent_kwargs,
|
119 |
+
assistant_role_name="assistant",
|
120 |
+
assistant_agent_kwargs=assistant_agent_kwargs,
|
121 |
+
)
|
122 |
+
|
123 |
+
return society
|
124 |
+
|
125 |
+
|
126 |
+
def main():
|
127 |
+
r"""Main function to run the OWL system with an example question."""
|
128 |
+
# Example research question
|
129 |
+
question = "Navigate to Amazon.com and identify one product that is attractive to coders. Please provide me with the product name and price. No need to verify your answer."
|
130 |
+
|
131 |
+
# Construct and run the society
|
132 |
+
society = construct_society(question)
|
133 |
+
answer, chat_history, token_count = run_society(society)
|
134 |
+
|
135 |
+
# Output the result
|
136 |
+
print(f"\033[94mAnswer: {answer}\033[0m")
|
137 |
+
|
138 |
+
|
139 |
+
if __name__ == "__main__":
|
140 |
+
main()
|