gpt-4 model support

This commit is contained in:
Carl Sverre
2023-03-20 17:45:44 -07:00
parent 7e6720f657
commit db6f15bc48

View File

@@ -172,7 +172,7 @@ class OpenAIHelper:
return response.choices[0]['message']['content']
def __max_model_tokens(self):
if self.config['model'] == "gpt-3.5-turbo" or self.config['model'] == "gpt-3.5-turbo-0301":
if self.config['model'] in ("gpt-3.5-turbo","gpt-3.5-turbo-0301","gpt-4"):
return 4096
raise NotImplementedError(
f"Max tokens for model {self.config['model']} is not implemented yet."
@@ -190,7 +190,7 @@ class OpenAIHelper:
encoding = tiktoken.encoding_for_model(model)
except KeyError:
encoding = tiktoken.get_encoding("gpt-3.5-turbo")
if model == "gpt-3.5-turbo" or model == "gpt-3.5-turbo-0301":
if model in ("gpt-3.5-turbo", "gpt-3.5-turbo-0301", "gpt-4"):
num_tokens = 0
for message in messages:
num_tokens += 4 # every message follows <im_start>{role/name}\n{content}<im_end>\n