lazychih114 commited on
Commit
f87fb65
·
1 Parent(s): 356d377

Create run_mini.py

Browse files
Files changed (1) hide show
  1. owl/run_mini.py +96 -0
owl/run_mini.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+
4
+ from camel.models import ModelFactory
5
+ from camel.toolkits import (
6
+ WebToolkit,
7
+ DocumentProcessingToolkit,
8
+ VideoAnalysisToolkit,
9
+ AudioAnalysisToolkit,
10
+ CodeExecutionToolkit,
11
+ ImageAnalysisToolkit,
12
+ SearchToolkit,
13
+ ExcelToolkit,
14
+ FunctionTool
15
+ )
16
+ from camel.types import ModelPlatformType, ModelType
17
+ from camel.configs import ChatGPTConfig
18
+
19
+ from typing import List, Dict
20
+
21
+ from retry import retry
22
+ from loguru import logger
23
+
24
+ from utils import OwlRolePlaying, run_society
25
+ import os
26
+
27
+
28
+
29
+
30
+ def construct_society(question: str) -> OwlRolePlaying:
31
+ r"""Construct the society based on the question."""
32
+
33
+ user_role_name = "user"
34
+ assistant_role_name = "assistant"
35
+
36
+ user_model = ModelFactory.create(
37
+ model_platform=ModelPlatformType.OPENAI,
38
+ model_type=ModelType.GPT_4O,
39
+ model_config_dict=ChatGPTConfig(temperature=0, top_p=1).as_dict(), # [Optional] the config for model
40
+ )
41
+
42
+ assistant_model = ModelFactory.create(
43
+ model_platform=ModelPlatformType.OPENAI,
44
+ model_type=ModelType.GPT_4O,
45
+ model_config_dict=ChatGPTConfig(temperature=0, top_p=1).as_dict(), # [Optional] the config for model
46
+ )
47
+
48
+ tools_list = [
49
+ *WebToolkit(
50
+ headless=False,
51
+ web_agent_model=assistant_model,
52
+ planning_agent_model=assistant_model
53
+ ).get_tools(),
54
+ # *DocumentProcessingToolkit().get_tools(),
55
+ # *VideoAnalysisToolkit(model=assistant_model).get_tools(), # This requires OpenAI Key
56
+ # *AudioAnalysisToolkit().get_tools(), # This requires OpenAI Key
57
+ # *CodeExecutionToolkit().get_tools(),
58
+ # *ImageAnalysisToolkit(model=assistant_model).get_tools(),
59
+ FunctionTool(SearchToolkit(model=assistant_model).search_duckduckgo),
60
+ # *ExcelToolkit().get_tools()
61
+ ]
62
+
63
+ user_role_name = 'user'
64
+ user_agent_kwargs = dict(model=user_model)
65
+ assistant_role_name = 'assistant'
66
+ assistant_agent_kwargs = dict(model=assistant_model,
67
+ tools=tools_list)
68
+
69
+ task_kwargs = {
70
+ 'task_prompt': question,
71
+ 'with_task_specify': False,
72
+ }
73
+
74
+ society = OwlRolePlaying(
75
+ **task_kwargs,
76
+ user_role_name=user_role_name,
77
+ user_agent_kwargs=user_agent_kwargs,
78
+ assistant_role_name=assistant_role_name,
79
+ assistant_agent_kwargs=assistant_agent_kwargs,
80
+ )
81
+
82
+ return society
83
+
84
+
85
+ # Example case
86
+ question = "What was the volume in m^3 of the fish bag that was calculated in the University of Leicester paper `Can Hiccup Supply Enough Fish to Maintain a Dragon’s Diet?` "
87
+
88
+ society = construct_society(question)
89
+ answer, chat_history, token_count = run_society(society)
90
+
91
+ logger.success(f"Answer: {answer}")
92
+
93
+
94
+
95
+
96
+