#ChatGPT

1 messages · Page 1 of 1 (latest)

viral geode
#

Why i dont became an answer in the Discord Channel ?

import discord
import os
import io
import asyncio

from discord.ext import commands
from discord.commands import slash_command, option
from openai import AsyncOpenAI

key = "key"

client = AsyncOpenAI(
    api_key=key
)


class TestCommand(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @slash_command(description="hello")
    async def question(self, ctx, frage: str):
        await ctx.defer()
        
        result = client.chat.completions.create(
                    model="gpt-3.5-turbo",
                    messages=[
                        {"role": "system", "content": "You are a helpful assistant."},
                        {"role": "user", "content": frage},
                    ]
                )
        
        msg = result
        
        print(result)


def setup(bot):
    bot.add_cog(TestCommand(bot))
hasty meteor
#

you are never even sending a message

viral geode
#

I became an error when i write so

import discord
import os
import io
import asyncio

from discord.ext import commands
from discord.commands import slash_command, option
from openai import AsyncOpenAI

key = "Key"

client = AsyncOpenAI(
    api_key=key
)


class TestCommand(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @slash_command(description="hello")
    async def question(self, ctx, frage: str):
        await ctx.defer()
        
        result = client.chat.completions.create(
                    model="gpt-3.5-turbo",
                    messages=[
                        {"role": "system", "content": "You are a helpful assistant."},
                        {"role": "user", "content": frage},
                    ]
                )
        
        msg = result.choices[0].message['content']

        await ctx.send(msg)


def setup(bot):
    bot.add_cog(TestCommand(bot))
#
Traceback (most recent call last):
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 978, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "c:\Users\YT197\Desktop\Allgemein\Dev\Python\Discord\NØVΛCØRD\cogs\owner\test.py", line 33, in question
    msg = result.choices[0].message['content']
          ^^^^^^^^^^^^^^
AttributeError: 'coroutine' object has no attribute 'choices'
C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py:80: RuntimeWarning: coroutine 'AsyncCompletions.create' was never awaited
  self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
hasty meteor
#

you aren't awaiting it

#

you literally used the async openai package, you have to await it

viral geode
# hasty meteor you literally used the async openai package, you have to await it

If I do not use the async, the error occurs

[ERROR] Error while executing /question 
Traceback (most recent call last):
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 978, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "c:\Users\YT197\Desktop\Allgemein\Dev\Python\Discord\NØVΛCØRD\cogs\owner\test.py", line 25, in question
    result = client.chat.completions.create(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_utils\_utils.py", line 275, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\resources\chat\completions.py", line 663, in create
    return self._post(
           ^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_base_client.py", line 1200, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_base_client.py", line 889, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_base_client.py", line 965, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_base_client.py", line 1013, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_base_client.py", line 965, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_base_client.py", line 1013, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "C:\Users\YT197\AppData\Local\Programs\Python\Python311\Lib\site-packages\openai\_base_client.py", line 980, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}  
hasty meteor
#

well, read?

#

you dont have any money on your account

#

and all you have to do is just await it
dont use the synchronous one unless you want your bot to be paused every time you generate smth

hasty meteor
#

yea, thanks for confirming what i said

#

pay up

viral geode
hasty meteor
#

this is not openai support

#

they switched to prepaid a while ago so you have to pay then use, not use then pay

viral geode
hasty meteor
#

no

#

use google