#getting this error with the API (solved)

20 messages · Page 1 of 1 (latest)

steady palm
#

ERROR discord.client Ignoring exception in on_message Traceback (most recent call last): \AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\api_requestor.py", line 687, in _interpret_response_line raise self.handle_error_response( openai.error.InvalidRequestError: Invalid URL (POST /v1/engines/gpt-3.5-turbo/chat/completions)
for the code

    def __init__(self, *, intents: discord.Intents):
        super().__init__(intents=intents)
        self.tree = app_commands.CommandTree(self)
        self.conversation_history = []

    async def setup_hook(self):
        self.tree.copy_global_to(guild=GUILD)
        await self.tree.sync(guild=GUILD)

    async def on_message(self, message):
        author = message.author

        if message.author == self.user:
            return

        input_content = message.content
        print(f"{message.author}: {input_content}")

        self.conversation_history.append({"role": "system", "content": f"The user is {author.display_name}. {SYSTEM_MESSAGE}"})
        self.conversation_history.append({"role": "user", "content": input_content})
        self.conversation_history = trim_conversation_history(self.conversation_history)

        try:
            prompt = "\n".join([item["content"] for item in self.conversation_history if item["role"] != "system"])
            response = openai.ChatCompletion.create(
                engine="gpt-3.5-turbo",
                prompt= prompt,
                max_tokens=1024,
                n=1,
                stop=None,
                temperature=0.5,
            )

            assistant_response = response.choices[0].text
            self.conversation_history.append({"role": "assistant", "content": assistant_response})
            self.conversation_history = trim_conversation_history(self.conversation_history)
tight river
steady palm
#

Yes, my bad corrected that already

#

Now I'm getting attribute error even when the openai library is up to date

tight river
#

Well I'm more concerned with why people are using engine.

#

Where did you get the code from?

steady palm
#

GitHub

tight river
#

Okay. Can you read it effectively?

#

You really need to consult with the docs before you try to just copy and paste code from github. There's lots of bad code there.

#

Can you post the new error you're getting?

steady palm
#

Yes let me

#
Traceback (most recent call last):
  File "C:\Users\\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\openai_object.py", line 59, in __getattr__
    return self[k]
           ~~~~^^^
KeyError: 'text'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\\Documents\Python\Discord Bots\AlexBot\main2.py", line 61, in on_message
    assistant_response = response.choices[0].text
                         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\openai_object.py", line 61, in __getattr__
    raise AttributeError(*err.args)
AttributeError: text
tight river
steady palm
#

Yes got it

tight river
#

Please consult with the API to ensure you are selecting the proper attributes.

steady palm
#

works fine now, I should have gone through the docs first there was so much

#

thanks a bunch!

#

can I mark this as solved?

tight river
steady palm
#

okai dokei