hzm
commited on
Commit
·
7869507
1
Parent(s):
f580792
add Azure OpenAI API to GUI
Browse files- README.md +3 -0
- README_zh.md +3 -0
- owl/.env_template +7 -0
- owl/app.py +30 -0
- owl/run_azure_openai.py +114 -0
README.md
CHANGED
@@ -307,6 +307,9 @@ python owl/run_deepseek_zh.py
|
|
307 |
# Run with other OpenAI-compatible models
|
308 |
python owl/run_openai_compatiable_model.py
|
309 |
|
|
|
|
|
|
|
310 |
# Run with Ollama
|
311 |
python owl/run_ollama.py
|
312 |
```
|
|
|
307 |
# Run with other OpenAI-compatible models
|
308 |
python owl/run_openai_compatiable_model.py
|
309 |
|
310 |
+
# Run with Azure OpenAI
|
311 |
+
python owl/run_azure_openai.py
|
312 |
+
|
313 |
# Run with Ollama
|
314 |
python owl/run_ollama.py
|
315 |
```
|
README_zh.md
CHANGED
@@ -311,6 +311,9 @@ python owl/run_deepseek_zh.py
|
|
311 |
# 使用其他 OpenAI 兼容模型运行
|
312 |
python owl/run_openai_compatiable_model.py
|
313 |
|
|
|
|
|
|
|
314 |
# 使用 Ollama 运行
|
315 |
python owl/run_ollama.py
|
316 |
```
|
|
|
311 |
# 使用其他 OpenAI 兼容模型运行
|
312 |
python owl/run_openai_compatiable_model.py
|
313 |
|
314 |
+
# 使用 Azure OpenAI模型运行
|
315 |
+
python owl/run_azure_openai.py
|
316 |
+
|
317 |
# 使用 Ollama 运行
|
318 |
python owl/run_ollama.py
|
319 |
```
|
owl/.env_template
CHANGED
@@ -4,6 +4,13 @@
|
|
4 |
# OPENAI_API_KEY= ""
|
5 |
# OPENAI_API_BASE_URL=""
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Qwen API (https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key)
|
8 |
# QWEN_API_KEY=""
|
9 |
|
|
|
4 |
# OPENAI_API_KEY= ""
|
5 |
# OPENAI_API_BASE_URL=""
|
6 |
|
7 |
+
# Azure OpenAI API
|
8 |
+
AZURE_OPENAI_BASE_URL=""
|
9 |
+
AZURE_API_VERSION=""
|
10 |
+
AZURE_OPENAI_API_KEY=""
|
11 |
+
AZURE_DEPLOYMENT_NAME=""
|
12 |
+
|
13 |
+
|
14 |
# Qwen API (https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key)
|
15 |
# QWEN_API_KEY=""
|
16 |
|
owl/app.py
CHANGED
@@ -40,6 +40,7 @@ SCRIPTS = {
|
|
40 |
"Default": "run.py",
|
41 |
"GAIA Roleplaying": "run_gaia_roleplaying.py",
|
42 |
"OpenAI Compatible": "run_openai_compatiable_model.py",
|
|
|
43 |
"Ollama": "run_ollama.py",
|
44 |
"Terminal": "run_terminal_zh.py",
|
45 |
}
|
@@ -53,6 +54,7 @@ SCRIPT_DESCRIPTIONS = {
|
|
53 |
"Default": "默认OWL实现,使用OpenAI GPT-4o模型和全套工具",
|
54 |
"GAIA Roleplaying": "GAIA基准测试实现,用于评估模型能力",
|
55 |
"OpenAI Compatible": "使用兼容OpenAI API的第三方模型,支持自定义API端点",
|
|
|
56 |
"Ollama": "使用Ollama API",
|
57 |
"Terminal": "使用本地终端执行python文件",
|
58 |
}
|
@@ -74,6 +76,34 @@ ENV_GROUPS = {
|
|
74 |
"required": False,
|
75 |
"help": "OpenAI API的基础URL,可选。如果使用代理或自定义端点,请设置此项。",
|
76 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
{
|
78 |
"name": "QWEN_API_KEY",
|
79 |
"label": "阿里云Qwen API密钥",
|
|
|
40 |
"Default": "run.py",
|
41 |
"GAIA Roleplaying": "run_gaia_roleplaying.py",
|
42 |
"OpenAI Compatible": "run_openai_compatiable_model.py",
|
43 |
+
"Azure OpenAI": "run_azure_openai.py",
|
44 |
"Ollama": "run_ollama.py",
|
45 |
"Terminal": "run_terminal_zh.py",
|
46 |
}
|
|
|
54 |
"Default": "默认OWL实现,使用OpenAI GPT-4o模型和全套工具",
|
55 |
"GAIA Roleplaying": "GAIA基准测试实现,用于评估模型能力",
|
56 |
"OpenAI Compatible": "使用兼容OpenAI API的第三方模型,支持自定义API端点",
|
57 |
+
"Azure OpenAI": "使用Azure OpenAI API",
|
58 |
"Ollama": "使用Ollama API",
|
59 |
"Terminal": "使用本地终端执行python文件",
|
60 |
}
|
|
|
76 |
"required": False,
|
77 |
"help": "OpenAI API的基础URL,可选。如果使用代理或自定义端点,请设置此项。",
|
78 |
},
|
79 |
+
{
|
80 |
+
"name": "AZURE_OPENAI_KEY",
|
81 |
+
"label": "Azure OpenAI API密钥",
|
82 |
+
"type": "password",
|
83 |
+
"required": False,
|
84 |
+
"help": "Azure OpenAI API密钥,用于访问Azure部署的GPT模型",
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"name": "AZURE_OPENAI_ENDPOINT",
|
88 |
+
"label": "Azure OpenAI端点",
|
89 |
+
"type": "text",
|
90 |
+
"required": False,
|
91 |
+
"help": "Azure OpenAI服务的端点URL",
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"name": "AZURE_DEPLOYMENT_NAME",
|
95 |
+
"label": "Azure OpenAI部署名称",
|
96 |
+
"type": "text",
|
97 |
+
"required": False,
|
98 |
+
"help": "Azure OpenAI服务的部署名称",
|
99 |
+
},
|
100 |
+
{
|
101 |
+
"name": "AZURE_OPENAI_VERSION",
|
102 |
+
"label": "Azure OpenAI API版本",
|
103 |
+
"type": "text",
|
104 |
+
"required": False,
|
105 |
+
"help": "Azure OpenAI API版本,例如:2023-12-01-preview",
|
106 |
+
},
|
107 |
{
|
108 |
"name": "QWEN_API_KEY",
|
109 |
"label": "阿里云Qwen API密钥",
|
owl/run_azure_openai.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
import os
|
15 |
+
from dotenv import load_dotenv
|
16 |
+
from camel.configs import ChatGPTConfig
|
17 |
+
from camel.models import ModelFactory
|
18 |
+
from camel.toolkits import (
|
19 |
+
CodeExecutionToolkit,
|
20 |
+
ExcelToolkit,
|
21 |
+
ImageAnalysisToolkit,
|
22 |
+
SearchToolkit,
|
23 |
+
WebToolkit,
|
24 |
+
FileWriteToolkit,
|
25 |
+
)
|
26 |
+
from camel.types import ModelPlatformType
|
27 |
+
|
28 |
+
from utils import OwlRolePlaying, run_society
|
29 |
+
|
30 |
+
from camel.logger import set_log_level
|
31 |
+
|
32 |
+
set_log_level(level="DEBUG")
|
33 |
+
|
34 |
+
load_dotenv()
|
35 |
+
|
36 |
+
|
37 |
+
def construct_society(question: str) -> OwlRolePlaying:
|
38 |
+
r"""Construct a society of agents based on the given question.
|
39 |
+
|
40 |
+
Args:
|
41 |
+
question (str): The task or question to be addressed by the society.
|
42 |
+
|
43 |
+
Returns:
|
44 |
+
OwlRolePlaying: A configured society of agents ready to address the question.
|
45 |
+
"""
|
46 |
+
|
47 |
+
# Create models for different components using Azure OpenAI
|
48 |
+
base_model_config = {
|
49 |
+
"model_platform": ModelPlatformType.AZURE,
|
50 |
+
"model_type": os.getenv("AZURE_OPENAI_MODEL_TYPE"),
|
51 |
+
"model_config_dict": ChatGPTConfig(temperature=0.4, max_tokens=4096).as_dict(),
|
52 |
+
}
|
53 |
+
|
54 |
+
models = {
|
55 |
+
"user": ModelFactory.create(**base_model_config),
|
56 |
+
"assistant": ModelFactory.create(**base_model_config),
|
57 |
+
"web": ModelFactory.create(**base_model_config),
|
58 |
+
"planning": ModelFactory.create(**base_model_config),
|
59 |
+
"image": ModelFactory.create(**base_model_config),
|
60 |
+
}
|
61 |
+
|
62 |
+
# Configure toolkits
|
63 |
+
tools = [
|
64 |
+
*WebToolkit(
|
65 |
+
headless=False, # Set to True for headless mode (e.g., on remote servers)
|
66 |
+
web_agent_model=models["web"],
|
67 |
+
planning_agent_model=models["planning"],
|
68 |
+
).get_tools(),
|
69 |
+
*CodeExecutionToolkit(sandbox="subprocess", verbose=True).get_tools(),
|
70 |
+
*ImageAnalysisToolkit(model=models["image"]).get_tools(),
|
71 |
+
SearchToolkit().search_duckduckgo,
|
72 |
+
SearchToolkit().search_google, # Comment this out if you don't have google search
|
73 |
+
SearchToolkit().search_wiki,
|
74 |
+
*ExcelToolkit().get_tools(),
|
75 |
+
*FileWriteToolkit(output_dir="./").get_tools(),
|
76 |
+
]
|
77 |
+
|
78 |
+
# Configure agent roles and parameters
|
79 |
+
user_agent_kwargs = {"model": models["user"]}
|
80 |
+
assistant_agent_kwargs = {"model": models["assistant"], "tools": tools}
|
81 |
+
|
82 |
+
# Configure task parameters
|
83 |
+
task_kwargs = {
|
84 |
+
"task_prompt": question,
|
85 |
+
"with_task_specify": False,
|
86 |
+
}
|
87 |
+
|
88 |
+
# Create and return the society
|
89 |
+
society = OwlRolePlaying(
|
90 |
+
**task_kwargs,
|
91 |
+
user_role_name="user",
|
92 |
+
user_agent_kwargs=user_agent_kwargs,
|
93 |
+
assistant_role_name="assistant",
|
94 |
+
assistant_agent_kwargs=assistant_agent_kwargs,
|
95 |
+
)
|
96 |
+
|
97 |
+
return society
|
98 |
+
|
99 |
+
|
100 |
+
def main():
|
101 |
+
r"""Main function to run the OWL system with Azure OpenAI."""
|
102 |
+
# Example question
|
103 |
+
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."
|
104 |
+
|
105 |
+
# Construct and run the society
|
106 |
+
society = construct_society(question)
|
107 |
+
answer, chat_history, token_count = run_society(society)
|
108 |
+
|
109 |
+
# Output the result
|
110 |
+
print(f"\033[94mAnswer: {answer}\033[0m")
|
111 |
+
|
112 |
+
|
113 |
+
if __name__ == "__main__":
|
114 |
+
main()
|