Rooni commited on
Commit
d74acb3
·
1 Parent(s): 6eccccd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -5,19 +5,22 @@ import json
5
  def generate_minecraft_command(description):
6
  headers = {
7
  'Content-Type': 'application/json',
8
- 'Authorization': 'Bearer dummy'
9
  }
10
 
11
  payload = {
12
  'prompt': f'Напиши пожалуйста команду для Minecraft JAVA 1.20, под описание: "{description}"',
13
- 'max_tokens': 500
14
  }
15
 
16
- response = requests.post('https://copilot.github1s.tk/', headers=headers, json=payload)
17
  data = json.loads(response.text)
18
  if 'choices' in data and len(data['choices']) > 0:
19
  command = data['choices'][0]['text'].strip()
20
  return command
 
 
 
21
  else:
22
  return 'Не удалось сгенерировать команду для Minecraft.'
23
 
 
5
  def generate_minecraft_command(description):
6
  headers = {
7
  'Content-Type': 'application/json',
8
+ 'Authorization': 'Bearer YOUR_OPENAI_API_KEY' # Замените YOUR_OPENAI_API_KEY на свой API-ключ OpenAI
9
  }
10
 
11
  payload = {
12
  'prompt': f'Напиши пожалуйста команду для Minecraft JAVA 1.20, под описание: "{description}"',
13
+ 'max_tokens': 50
14
  }
15
 
16
+ response = requests.post('https://api.openai.com/v1/engines/davinci-codex/completions', headers=headers, json=payload)
17
  data = json.loads(response.text)
18
  if 'choices' in data and len(data['choices']) > 0:
19
  command = data['choices'][0]['text'].strip()
20
  return command
21
+ elif 'error' in data:
22
+ error_message = data['error']
23
+ return f'Ошибка: {error_message}'
24
  else:
25
  return 'Не удалось сгенерировать команду для Minecraft.'
26