oddluck / limnoria-plugins

Limnoria plugins I wrote or forked.
Do What The F*ck You Want To Public License
39 stars 17 forks source link

ChatGPT: changes needed in plugin.py for openai>=1.0.0 #55

Closed woohooyeah closed 10 months ago

woohooyeah commented 10 months ago

Greetings,

For recent versions (>=1.0.0) of the openai Python package, some minor changes are necessary in the ChatGPT plugin.

Please see this patch:

--- ChatGPT/plugin.py.old       2023-11-14 19:42:28.032663945 +0100
+++ ChatGPT/plugin.py   2023-11-14 19:42:58.888824298 +0100
@@ -31,7 +31,7 @@
 from supybot import utils, plugins, ircutils, callbacks
 from supybot.commands import *
 from supybot.i18n import PluginInternationalization
-import openai
+from openai import OpenAI

 _ = PluginInternationalization("ChatGPT")
@@ -44,9 +44,11 @@

     def chat(self, irc, msg, args, text):
         """Manual Call to the ChatGPT API"""
-        openai.api_key = self.registryValue("api_key")
+        client = OpenAI(
+            api_key = self.registryValue("api_key"),
+        )
         prompt = self.registryValue("prompt", msg.channel).replace("$botnick", irc.nick)
-        completion = openai.ChatCompletion.create(
+        completion = client.chat.completions.create(
             model=self.registryValue("model", msg.channel),
             messages=[
                 {"role": "system", "content": prompt},

Hope this helps.

Best regards, Dorian

felon-efnet commented 10 months ago

thanks will give it a try shortly...

oddluck commented 10 months ago

Thank you, appreciate the heads up!