From 4597af124adb6bd83334d9f29e1ee6b49f0475b8 Mon Sep 17 00:00:00 2001 From: sts07142 Date: Mon, 22 Jul 2024 12:25:42 +0900 Subject: [PATCH] Add GPT 4o&4o mini --- camel/model_backend.py | 6 ++++++ camel/typing.py | 2 ++ camel/utils.py | 6 ++++++ chatdev/statistics.py | 8 ++++++++ ecl/utils.py | 4 ++++ requirements.txt | 2 +- run.py | 4 +++- 7 files changed, 30 insertions(+), 2 deletions(-) diff --git a/camel/model_backend.py b/camel/model_backend.py index 2c664ba..c4b6b58 100644 --- a/camel/model_backend.py +++ b/camel/model_backend.py @@ -91,6 +91,8 @@ class OpenAIModel(ModelBackend): "gpt-4-0613": 8192, "gpt-4-32k": 32768, "gpt-4-turbo": 100000, + "gpt-4o": 4096, #100000 + "gpt-4o-mini": 16384, #100000 } num_max_token = num_max_token_map[self.model_type.value] num_max_completion_tokens = num_max_token - num_prompt_tokens @@ -122,6 +124,8 @@ class OpenAIModel(ModelBackend): "gpt-4-0613": 8192, "gpt-4-32k": 32768, "gpt-4-turbo": 100000, + "gpt-4o": 4096, #100000 + "gpt-4o-mini": 16384, #100000 } num_max_token = num_max_token_map[self.model_type.value] num_max_completion_tokens = num_max_token - num_prompt_tokens @@ -182,6 +186,8 @@ class ModelFactory: ModelType.GPT_4_32k, ModelType.GPT_4_TURBO, ModelType.GPT_4_TURBO_V, + ModelType.GPT_4O, + ModelType.GPT_4O_MINI, None }: model_class = OpenAIModel diff --git a/camel/typing.py b/camel/typing.py index fa0caa9..e949878 100644 --- a/camel/typing.py +++ b/camel/typing.py @@ -50,6 +50,8 @@ class ModelType(Enum): GPT_4_32k = "gpt-4-32k" GPT_4_TURBO = "gpt-4-turbo" GPT_4_TURBO_V = "gpt-4-turbo" + GPT_4O = "gpt-4o" + GPT_4O_MINI = "gpt-4o-mini" STUB = "stub" diff --git a/camel/utils.py b/camel/utils.py index a2713af..2989e6c 100644 --- a/camel/utils.py +++ b/camel/utils.py @@ -89,6 +89,8 @@ def num_tokens_from_messages( ModelType.GPT_4_32k, ModelType.GPT_4_TURBO, ModelType.GPT_4_TURBO_V, + ModelType.GPT_4O, + ModelType.GPT_4O_MINI, ModelType.STUB }: return count_tokens_openai_chat_models(messages, encoding) @@ -124,6 +126,10 @@ def get_model_token_limit(model: ModelType) -> int: return 128000 elif model == ModelType.STUB: return 4096 + elif model == ModelType.GPT_4O: + return 128000 + elif model == ModelType.GPT_4O_MINI: + return 128000 else: raise ValueError("Unknown model type") diff --git a/chatdev/statistics.py b/chatdev/statistics.py index 548ef7e..d98c9e7 100644 --- a/chatdev/statistics.py +++ b/chatdev/statistics.py @@ -13,6 +13,8 @@ def prompt_cost(model_type: str, num_prompt_tokens: float, num_completion_tokens "gpt-4-0613": 0.03, "gpt-4-32k": 0.06, "gpt-4-turbo": 0.01, + "gpt-4o": 0.005, + "gpt-4o-mini": 0.00015, } output_cost_map = { @@ -24,6 +26,8 @@ def prompt_cost(model_type: str, num_prompt_tokens: float, num_completion_tokens "gpt-4-0613": 0.06, "gpt-4-32k": 0.12, "gpt-4-turbo": 0.03, + "gpt-4o": 0.015, + "gpt-4o-mini": 0.0006, } if model_type not in input_cost_map or model_type not in output_cost_map: @@ -111,6 +115,10 @@ def get_info(dir, log_filepath): model_type = "gpt-4-32k" elif model_type == "GPT_4_TURBO": model_type = "gpt-4-turbo" + elif model_type == "GPT_4O": + model_type = "gpt-4o" + elif model_type == "GPT_4O_MINI": + model_type = "gpt-4o-mini" # print("model_type:", model_type) lines = open(log_filepath, "r", encoding="utf8").read().split("\n") diff --git a/ecl/utils.py b/ecl/utils.py index cb11cda..184d90b 100644 --- a/ecl/utils.py +++ b/ecl/utils.py @@ -65,6 +65,8 @@ def calc_max_token(messages, model): "gpt-4": 8192, "gpt-4-0613": 8192, "gpt-4-32k": 32768, + "gpt-4o": 4096, #100000 + "gpt-4o-mini": 16384, #100000 } num_max_token = num_max_token_map[model] num_max_completion_tokens = num_max_token - num_prompt_tokens @@ -136,6 +138,8 @@ class OpenAIModel(ModelBackend): "gpt-4": 8192, "gpt-4-0613": 8192, "gpt-4-32k": 32768, + "gpt-4o": 4096, #100000 + "gpt-4o-mini": 16384, #100000 } response = client.chat.completions.create(messages = messages, model = "gpt-3.5-turbo-16k", diff --git a/requirements.txt b/requirements.txt index 4b2794d..5aae454 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ openai==1.3.3 regex==2023.6.3 requests==2.31.0 tenacity==8.2.2 -tiktoken==0.4.0 +tiktoken==0.7.0 virtualenv==20.23.0 Werkzeug==3.0.3 Markdown==3.4.4 diff --git a/run.py b/run.py index ca2ea72..29293a7 100644 --- a/run.py +++ b/run.py @@ -79,7 +79,7 @@ parser.add_argument('--task', type=str, default="Develop a basic Gomoku game.", parser.add_argument('--name', type=str, default="Gomoku", help="Name of software, your software will be generated in WareHouse/name_org_timestamp") parser.add_argument('--model', type=str, default="GPT_3_5_TURBO", - help="GPT Model, choose from {'GPT_3_5_TURBO', 'GPT_4', 'GPT_4_TURBO'}") + help="GPT Model, choose from {'GPT_3_5_TURBO', 'GPT_4', 'GPT_4_TURBO', 'GPT_4O', 'GPT_4O_MINI'}") parser.add_argument('--path', type=str, default="", help="Your file directory, ChatDev will build upon your software in the Incremental mode") args = parser.parse_args() @@ -95,6 +95,8 @@ args2type = {'GPT_3_5_TURBO': ModelType.GPT_3_5_TURBO, # 'GPT_4_32K': ModelType.GPT_4_32k, 'GPT_4_TURBO': ModelType.GPT_4_TURBO, # 'GPT_4_TURBO_V': ModelType.GPT_4_TURBO_V + 'GPT_4O': ModelType.GPT_4O, + 'GPT_4O_MINI': ModelType.GPT_4O_MINI, } if openai_new_api: args2type['GPT_3_5_TURBO'] = ModelType.GPT_3_5_TURBO_NEW