add openai.Completion support

This commit is contained in:
better629 2023-10-09 13:52:30 +08:00
parent 6c947945d7
commit 81f716b57e
3 changed files with 36 additions and 2 deletions

View file

@ -11,6 +11,7 @@ ref3: https://github.com/hwchase17/langchain/blob/master/langchain/chat_models/o
import tiktoken
TOKEN_COSTS = {
"gpt-3.5-turbo-instruct": {"prompt": 0.0015, "completion": 0.002},
"gpt-3.5-turbo": {"prompt": 0.0015, "completion": 0.002},
"gpt-3.5-turbo-0301": {"prompt": 0.0015, "completion": 0.002},
"gpt-3.5-turbo-0613": {"prompt": 0.0015, "completion": 0.002},
@ -26,6 +27,7 @@ TOKEN_COSTS = {
TOKEN_MAX = {
"gpt-3.5-turbo-instruct": 4096,
"gpt-3.5-turbo": 4096,
"gpt-3.5-turbo-0301": 4096,
"gpt-3.5-turbo-0613": 4096,
@ -48,6 +50,7 @@ def count_message_tokens(messages, model="gpt-3.5-turbo-0613"):
print("Warning: model not found. Using cl100k_base encoding.")
encoding = tiktoken.get_encoding("cl100k_base")
if model in {
"gpt-3.5-turbo-instruct",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k-0613",
"gpt-4-0314",