import discord
import aiohttp
import asyncio
# Создаем объект Intents и включаем все интенты
intents = discord.Intents.default()
# Инициализируем клиента Discord
client = discord.Client(intents=intents)
# Замените <ВАШ_ИДЕНТИФИКАТОР_КАТАЛОГА> и <ВАШ_API_КЛЮЧ> на ваши реальные значения
YANDEX_CLOUD_ID = ''
YANDEX_API_KEY = ''
async def send_dialogue(query):
prompt = {
"modelUri": f"gpt://<ВАШ_ИДЕНТИФИКАТОР_КАТАЛОГА>/yandexgpt/latest",
"completionOptions": {
"stream": False,
"temperature": 0.6,
"maxTokens": "2000"
},
"messages": [
{
"role": "user",
"text": query
}
]
}
url = "https://llm.api.cloud.yandex.net/foundationModels/v1/completion"
headers = {
"Content-Type": "application/json",
"Authorization": f"Api-Key {YANDEX_API_KEY}"
}
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, json=prompt) as response:
result = await response.json()
return result['result']['alternatives'][0]['message']['text']
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if client.user.mentioned_in(message):
query = message.content.replace(client.user.mention, '').strip()
response = await send_dialogue(query)
await message.channel.send(response)
# Запускаем бота
client.run('')