File size: 1,122 Bytes
f92a51b
 
6eccccd
f92a51b
6eccccd
d8abe74
6eccccd
d74acb3
d8abe74
6eccccd
 
 
d74acb3
d8abe74
6eccccd
d74acb3
6eccccd
 
 
 
d74acb3
 
 
10954e8
6eccccd
10954e8
6eccccd
32a7af3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
import requests
import json

def generate_minecraft_command(description):
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer YOUR_OPENAI_API_KEY' # Замените YOUR_OPENAI_API_KEY на свой API-ключ OpenAI
    }

    payload = {
        'prompt': f'Напиши пожалуйста команду для Minecraft JAVA 1.20, под описание: "{description}"',
        'max_tokens': 50
    }

    response = requests.post('https://api.openai.com/v1/engines/davinci-codex/completions', headers=headers, json=payload)
    data = json.loads(response.text)
    if 'choices' in data and len(data['choices']) > 0:
        command = data['choices'][0]['text'].strip()
        return command
    elif 'error' in data:
        error_message = data['error']
        return f'Ошибка: {error_message}'
    else:
        return 'Не удалось сгенерировать команду для Minecraft.'

iface = gr.Interface(fn=generate_minecraft_command, inputs="text", outputs="text", title="Minecraft Command Generator")
iface.launch()