Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to outdated OpenAI API references #119

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions shortGPT/gpt/gpt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import re
from time import sleep, time

import openai
from openai import OpenAI
from shortGPT.config.api_db import ApiKeyManager

import tiktoken
import yaml

from shortGPT.config.api_db import ApiKeyManager

client = OpenAI(api_key=ApiKeyManager.get_api_key("OPENAI"))

def num_tokens_from_messages(texts, model="gpt-3.5-turbo-0301"):
"""Returns the number of tokens used by a list of messages."""
Expand Down Expand Up @@ -70,7 +71,7 @@ def open_file(filepath):


def gpt3Turbo_completion(chat_prompt="", system="You are an AI that can give the answer to anything", temp=0.7, model="gpt-3.5-turbo", max_tokens=1000, remove_nl=True, conversation=None):
openai.api_key = ApiKeyManager.get_api_key("OPENAI")

max_retry = 5
retry = 0
while True:
Expand All @@ -82,11 +83,10 @@ def gpt3Turbo_completion(chat_prompt="", system="You are an AI that can give the
{"role": "system", "content": system},
{"role": "user", "content": chat_prompt}
]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
max_tokens=max_tokens,
temperature=temp)
response = client.chat.completions.create(model=model,
messages=messages,
max_tokens=max_tokens,
temperature=temp)
text = response['choices'][0]['message']['content'].strip()
if remove_nl:
text = re.sub('\s+', ' ', text)
Expand Down