jesselau76 / ebook-GPT-translator

Enjoy reading with your favorite style.
https://jesselau.com
MIT License
1.63k stars 210 forks source link

update create_chat_completion, in order to support new version of ope… #67

Closed AlexMeow closed 7 months ago

AlexMeow commented 7 months ago

The new version of openAI library (>=1.0.0) no longer supports the following syntax:

openai.ChatCompletion.create(
  # ...
)

I rewrote it as:

client = openai.Client(api_key=random_api_key())
return client.chat.completions.create(
    # ...
)

Reference: https://github.com/openai/openai-python/blob/main/api.md#completions-1

AlexMeow commented 7 months ago

Some bug exist

completion["choices"][0]
TypeError: 'ChatCompletion' object is not subscriptable