#Image to text api

1 messages · Page 1 of 1 (latest)

feral anchor
#

im making a discord bot but having trouble getting it to recognize images . works fine for asking it questions just doesnt seem to work for images im assuming because im not using any image logic . but i dont know where to begin

``import os

import discord
import openai
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()

TOKEN = os.getenv('DISCORD_BOT_TOKEN')
intents = discord.Intents.default()
bot = commands.Bot(command_prefix='!', intents=intents)
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

openai.api_key = OPENAI_API_KEY

@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')

@bot.event
async def on_message(message):
#check if the message is from a user
if not message.author.bot and bot.user.mentioned_in(message):

    user_message = message.content.split(' ', 1)[1]

    response = 'Nothing yet!'

    if user_message.startswith('!ask'):
        question = message.content[5:] #remove !ask from last message content 

        response = openai.ChatCompletion.create(
            model="gpt-4",
            messages=[
                {"role": "system", "content": "you are a helpful assistant."},
                {"role": "user", "content": question}
            ],
        )
await message.channel.send(response['choices'][0]['message']['content'])



await bot.process_commands(message)

def run_chat_gpt_bot():
bot.run(TOKEN) ``

misty fossil
feral anchor
misty fossil