Skip to content

Commit

Permalink
support gpt-4o
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaawwa committed May 14, 2024
1 parent 17f03a6 commit 45d7fbe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions check_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def warm_up_modules():
enc.encode("模块预热", disallowed_special=())
enc = model_info["gpt-4"]['tokenizer']
enc.encode("模块预热", disallowed_special=())
enc = model_info["gpt-4o"]['tokenizer']
enc.encode("模块预热", disallowed_special=())

def warm_up_vectordb():
print('正在执行一些模块的预热 ...')
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# [step 3]>> 模型选择是 (注意: LLM_MODEL是默认选中的模型, 它*必须*被包含在AVAIL_LLM_MODELS列表中 )
LLM_MODEL = "gpt-3.5-turbo-16k" # 可选 ↓↓↓
AVAIL_LLM_MODELS = ["gpt-4-1106-preview", "gpt-4-turbo-preview", "gpt-4-vision-preview", "gpt-4-turbo", "gpt-4-turbo-2024-04-09",
"gpt-4o", "gpt-4o-2024-05-13",
"gpt-3.5-turbo-1106", "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "azure-gpt-3.5",
"gpt-4", "gpt-4-32k", "azure-gpt-4", "glm-4", "glm-4v", "glm-3-turbo",
"gemini-pro", "chatglm3"
Expand Down
24 changes: 21 additions & 3 deletions request_llms/bridge_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def __init__(self, model):
@staticmethod
@lru_cache(maxsize=128)
def get_encoder(model):
print('正在加载tokenizer,如果是第一次运行,可能需要一点时间下载参数')
print(f'正在加载 {model} 模型的tokenizer,如果是第一次运行,可能需要一点时间下载参数')
tmp = tiktoken.encoding_for_model(model)
print('加载tokenizer完毕')
print(f'加载 {model} 模型的tokenizer完毕')
return tmp

def encode(self, *args, **kwargs):
Expand Down Expand Up @@ -94,9 +94,10 @@ def decode(self, *args, **kwargs):
# 获取tokenizer
tokenizer_gpt35 = LazyloadTiktoken("gpt-3.5-turbo")
tokenizer_gpt4 = LazyloadTiktoken("gpt-4")
tokenizer_gpt4o = LazyloadTiktoken("gpt-4o")
get_token_num_gpt35 = lambda txt: len(tokenizer_gpt35.encode(txt, disallowed_special=()))
get_token_num_gpt4 = lambda txt: len(tokenizer_gpt4.encode(txt, disallowed_special=()))

get_token_num_gpt4o = lambda txt: len(tokenizer_gpt4o.encode(txt, disallowed_special=()))

# 开始初始化模型
AVAIL_LLM_MODELS, LLM_MODEL = get_conf("AVAIL_LLM_MODELS", "LLM_MODEL")
Expand Down Expand Up @@ -295,6 +296,23 @@ def decode(self, *args, **kwargs):
"token_cnt": get_token_num_gpt4,
},

"gpt-4o": {
"fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui,
"endpoint": openai_endpoint,
"max_token": 128000,
"tokenizer": tokenizer_gpt4o,
"token_cnt": get_token_num_gpt4o,
},

"gpt-4o-2024-05-13": {
"fn_with_ui": chatgpt_ui,
"fn_without_ui": chatgpt_noui,
"endpoint": openai_endpoint,
"max_token": 128000,
"tokenizer": tokenizer_gpt4o,
"token_cnt": get_token_num_gpt4o,
},

"gpt-3.5-random": {
"fn_with_ui": chatgpt_ui,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fastapi==0.110
gradio-client==0.8
pypdf2==2.12.1
zhipuai==2.0.1
tiktoken>=0.3.3
tiktoken>=0.7.0
requests[socks]
pydantic==2.5.2
protobuf==3.18
Expand Down

0 comments on commit 45d7fbe

Please sign in to comment.