Python Fehlermeldung "KeyError: 'data'"?

Ich möchte gerne einen KI Discord Server machen. Die KI hab ich schon und diese hat auch eine API(?). Ich hab den Bot auch schon auf dem Server und ich kann auch Prompts eingeben. Aber wenn ich Prompt eingebe, kommt bei diesem Code:

import discord
from gradio_client import Client


TOKEN = 'MeinToken'
FOOOCUS_API_URL = 'http://127.0.0.1:7865/'


fooocus_client = Client(FOOOCUS_API_URL)


intents = discord.Intents.default()
client = discord.Client(intents=intents)


@client.event
async def on_ready():
    print(f'{client.user} ist eingeloggt!')


@client.event
async def on_message(message):
    if message.channel.name == 'prompt-kanal' and message.author != client.user:
        result = fooocus_client.predict(message.content, fn_index=2)
        await message.channel.send(file=discord.File(result))


client.run(TOKEN)

Diese Fehlermeldung:

2024-04-16 15:35:07 ERROR discord.client Ignoring exception in on_message
Traceback (most recent call last):
File "C:...\venv\Lib\site-packages\gradio_client\compatibility.py", line 105, in _predict
output = result["data"]
~~~~~~^^^^^^^^
KeyError: 'data'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:...\venv\Lib\site-packages\discord\client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "c:...\bot.py", line 19, in on_message
result = fooocus_client.predict(message.content, fn_index=2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:...\venv\Lib\site-packages\gradio_client\client.py", line 459, in predict
).result()
^^^^^^^^
File "C:...\venv\Lib\site-packages\gradio_client\client.py", line 1374, in result
return super().result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users..._base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Users..._base.py", line 401, in __get_result
raise self._exception
File "C:\Users...\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:...\compatibility.py", line 65, in _inner
predictions = _predict(*data)
^^^^^^^^^^^^^^^
File "C:...\compatibility.py", line 119, in _predict
raise KeyError(
KeyError: 'Could not find 'data' key in response. Response received: {'detail': [{'type': 'model_attributes_type', 'loc': ['body'], 'msg': 'Input should be a valid dictionary or object to extract fields from', 'input': '{"data": [""], "fn_index": 2, "session_hash": "d7f62bf0-174c-45fe-b3f6-c5e7f00848d3"}', 'url': 'https://errors.pydantic.dev/2.1/v/model_attributes_type'}]}'

Ich checke einfach nicht, woran das liegen könnte...

Linux, Bot, cmd, Code, künstliche Intelligenz, Programmiersprache, Python, Python 3, Pycharm, Discord, Discord Bot, ChatGPT
Minecraft 1.20.4 - Eclipse Programmierung, kann keine Imports machen?

Ich möchte mit Java ein Plugin für 1.20.4 programmieren und habe mir ein Code von ChatGPT schreiben lassen.

package de.diamanthoe.plugin;

import org.bukkit.Material;

import org.bukkit.Particle;

import org.bukkit.command.Command;

import org.bukkit.command.CommandSender;

import org.bukkit.command.CommandExecutor;

import org.bukkit.configuration.ConfigurationSection;

import org.bukkit.configuration.file.FileConfiguration;

import org.bukkit.entity.Player;

import org.bukkit.inventory.Inventory;

import org.bukkit.inventory.ItemStack;

import org.bukkit.inventory.meta.ItemMeta;

import org.bukkit.plugin.java.JavaPlugin;

import org.bukkit.Location;

public class NaviSystem extends JavaPlugin implements CommandExecutor {

  @Override

  public void onEnable() {

    // Register commands

    getCommand("navi").setExecutor(this);

  }

  @Override

  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    if (!(sender instanceof Player)) {

      sender.sendMessage("Dieser Befehl kann nur von Spielern ausgeführt werden.");

      return true;

    }

    Player player = (Player) sender;

    if (cmd.getName().equalsIgnoreCase("navi")) {

      if (args.length >= 1) {

        if (args[0].equalsIgnoreCase("save")) {

          if (args.length >= 2) {

            savePoint(args[1], player.getLocation());

            sender.sendMessage("Punkt gespeichert unter: " + args[1]);

          } else {

            sender.sendMessage("Verwendung: /navi save [Name]");

          }

        } else {

          if (args.length >= 3) {

            try {

              double x = Double.parseDouble(args[0]);

              double y = Double.parseDouble(args[1]);

              double z = Double.parseDouble(args[2]);

              Location target = new Location(player.getWorld(), x, y, z);

              createParticleTrail(player, target);

            } catch (NumberFormatException e) {

              sender.sendMessage("Ungültige Koordinaten.");

            }

          } else {

            sender.sendMessage("Verwendung: /navi <x y z>");

          }

        }

      } else {

        sender.sendMessage("Verwendung: /navi <x y z>");

      }

    }

    return true;

  }

  private void createParticleTrail(Player player, Location target) {

    Location playerLocation = player.getLocation();

    player.spawnParticle(Particle.REDSTONE, playerLocation, 0, target.getX(), target.getY(), target.getZ(), 10);

  }

  private void savePoint(String name, Location location) {

    FileConfiguration config = getConfig();

    config.set("points." + name + ".world", location.getWorld().getName());

    config.set("points." + name + ".x", location.getX());

    config.set("points." + name + ".y", location.getY());

    config.set("points." + name + ".z", location.getZ());

    saveConfig();

  }

  private void openPointsGUI(Player player) {

    Inventory gui = getServer().createInventory(null, 9, "Gespeicherte Punkte");

    ConfigurationSection pointsSection = getConfig().getConfigurationSection("points");

    if (pointsSection != null) {

      for (String pointName : pointsSection.getKeys(false)) {

        ConfigurationSection pointConfig = pointsSection.getConfigurationSection(pointName);

        if (pointConfig != null) {

          String worldName = pointConfig.getString("world");

          double x = pointConfig.getDouble("x");

          double y = pointConfig.getDouble("y");

          double z = pointConfig.getDouble("z");

          ItemStack pointItem = createPointItem(worldName, x, y, z);

          gui.addItem(pointItem);

        }

      }

    }

    player.openInventory(gui);

  }

  private ItemStack createPointItem(String worldName, double x, double y, double z) {

    ItemStack item = new ItemStack(Material.COMPASS);

    ItemMeta meta = item.getItemMeta();

    meta.setDisplayName(worldName + " - " + x + ", " + y + ", " + z);

    item.setItemMeta(meta);

    return item;

  }

}

Das Problem ist, dass da total viel rot unterstrichen wird, was wahrscheinlich auf die Imports zurückzuführen ist. Die Imports selbst sind teilweise ebenso rot interstrichen (org.bukkit).

Ich benutze das JDK 17 und Java SE 1.8.

Java, Minecraft, Code, Minecraft Server, Programmiersprache, Bukkit, Spigot

Meistgelesene Beiträge zum Thema Programmiersprache