Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ def generate_minecraft_command(description):
|
|
| 10 |
}
|
| 11 |
|
| 12 |
payload = {
|
| 13 |
-
'
|
| 14 |
'max_tokens': 500,
|
| 15 |
'model': 'gpt-3.5-turbo'
|
| 16 |
}
|
|
@@ -19,13 +19,13 @@ def generate_minecraft_command(description):
|
|
| 19 |
data = json.loads(response.text)
|
| 20 |
|
| 21 |
if 'choices' in data and len(data['choices']) > 0:
|
| 22 |
-
command = data['choices'][0]['
|
| 23 |
return command
|
| 24 |
elif 'error' in data:
|
| 25 |
error_message = data['error']['message']
|
| 26 |
return f'Ошибка: {error_message}'
|
| 27 |
else:
|
| 28 |
-
return f'Не удалось сгенерировать
|
| 29 |
|
| 30 |
iface = gr.Interface(fn=generate_minecraft_command, inputs="text", outputs="text", title="Minecraft Command Generator")
|
| 31 |
-
iface.launch()
|
|
|
|
| 10 |
}
|
| 11 |
|
| 12 |
payload = {
|
| 13 |
+
'messages': [{'role': 'system', 'content': f'Generate Minecraft command for description: {description}'}],
|
| 14 |
'max_tokens': 500,
|
| 15 |
'model': 'gpt-3.5-turbo'
|
| 16 |
}
|
|
|
|
| 19 |
data = json.loads(response.text)
|
| 20 |
|
| 21 |
if 'choices' in data and len(data['choices']) > 0:
|
| 22 |
+
command = data['choices'][0]['message']['content'].strip()
|
| 23 |
return command
|
| 24 |
elif 'error' in data:
|
| 25 |
error_message = data['error']['message']
|
| 26 |
return f'Ошибка: {error_message}'
|
| 27 |
else:
|
| 28 |
+
return f'Не удалось сгенерировать команду для Minecraft. Причина: {data}'
|
| 29 |
|
| 30 |
iface = gr.Interface(fn=generate_minecraft_command, inputs="text", outputs="text", title="Minecraft Command Generator")
|
| 31 |
+
iface.launch()
|