Added GPT-3.5 16K chat functionality (#306)

This commit is contained in:
maccagnit
2023-06-20 10:47:19 +02:00
committed by GitHub
parent 28e7426c2b
commit 533e6705c8
2 changed files with 22 additions and 6 deletions
+7 -4
View File
@@ -16,7 +16,7 @@ OPENAI_COMPLETION_OPTIONS = {
class ChatGPT: class ChatGPT:
def __init__(self, model="gpt-3.5-turbo"): def __init__(self, model="gpt-3.5-turbo"):
assert model in {"text-davinci-003", "gpt-3.5-turbo", "gpt-4"}, f"Unknown model: {model}" assert model in {"text-davinci-003", "gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}, f"Unknown model: {model}"
self.model = model self.model = model
async def send_message(self, message, dialog_messages=[], chat_mode="assistant"): async def send_message(self, message, dialog_messages=[], chat_mode="assistant"):
@@ -27,7 +27,7 @@ class ChatGPT:
answer = None answer = None
while answer is None: while answer is None:
try: try:
if self.model in {"gpt-3.5-turbo", "gpt-4"}: if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}:
messages = self._generate_prompt_messages(message, dialog_messages, chat_mode) messages = self._generate_prompt_messages(message, dialog_messages, chat_mode)
r = await openai.ChatCompletion.acreate( r = await openai.ChatCompletion.acreate(
model=self.model, model=self.model,
@@ -67,7 +67,7 @@ class ChatGPT:
answer = None answer = None
while answer is None: while answer is None:
try: try:
if self.model in {"gpt-3.5-turbo", "gpt-4"}: if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4"}:
messages = self._generate_prompt_messages(message, dialog_messages, chat_mode) messages = self._generate_prompt_messages(message, dialog_messages, chat_mode)
r_gen = await openai.ChatCompletion.acreate( r_gen = await openai.ChatCompletion.acreate(
model=self.model, model=self.model,
@@ -146,9 +146,12 @@ class ChatGPT:
def _count_tokens_from_messages(self, messages, answer, model="gpt-3.5-turbo"): def _count_tokens_from_messages(self, messages, answer, model="gpt-3.5-turbo"):
encoding = tiktoken.encoding_for_model(model) encoding = tiktoken.encoding_for_model(model)
if model == "gpt-3.5-turbo": if model == "gpt-3.5-turbo-16k":
tokens_per_message = 4 # every message follows <im_start>{role/name}\n{content}<im_end>\n tokens_per_message = 4 # every message follows <im_start>{role/name}\n{content}<im_end>\n
tokens_per_name = -1 # if there's a name, the role is omitted tokens_per_name = -1 # if there's a name, the role is omitted
elif model == "gpt-3.5-turbo":
tokens_per_message = 4
tokens_per_name = -1
elif model == "gpt-4": elif model == "gpt-4":
tokens_per_message = 3 tokens_per_message = 3
tokens_per_name = 1 tokens_per_name = 1
+15 -2
View File
@@ -1,4 +1,4 @@
available_text_models: ["gpt-3.5-turbo", "gpt-4", "text-davinci-003"] available_text_models: ["gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4", "text-davinci-003"]
info: info:
gpt-3.5-turbo: gpt-3.5-turbo:
@@ -6,7 +6,7 @@ info:
name: ChatGPT name: ChatGPT
description: ChatGPT is that well-known model. It's <b>fast</b> and <b>cheap</b>. Ideal for everyday tasks. If there are some tasks it can't handle, try the <b>GPT-4</b>. description: ChatGPT is that well-known model. It's <b>fast</b> and <b>cheap</b>. Ideal for everyday tasks. If there are some tasks it can't handle, try the <b>GPT-4</b>.
price_per_1000_input_tokens: 0.002 price_per_1000_input_tokens: 0.0015
price_per_1000_output_tokens: 0.002 price_per_1000_output_tokens: 0.002
scores: scores:
@@ -14,6 +14,19 @@ info:
Fast: 5 Fast: 5
Cheap: 5 Cheap: 5
gpt-3.5-turbo-16k:
type: chat_completion
name: GPT-16K
description: ChatGPT is that well-known model. It's <b>fast</b> and <b>cheap</b>. Ideal for everyday tasks. If there are some tasks it can't handle, try the <b>GPT-4</b>.
price_per_1000_input_tokens: 0.003
price_per_1000_output_tokens: 0.004
scores:
Smart: 3
Fast: 5
Cheap: 5
gpt-4: gpt-4:
type: chat_completion type: chat_completion
name: GPT-4 name: GPT-4