Compare commits
7
Commits
89300e74e5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d4a2af01f | ||
|
|
8f4b2d6c11 | ||
|
|
5ae7fbb628 | ||
|
|
0d734024dc | ||
|
|
87f4e40cce | ||
|
|
bd631ad61a | ||
|
|
43e073cbd1 |
+8
-6
@@ -24,9 +24,10 @@ async def on_ready():
|
||||
print(f'Failed to sync commands: {e}')
|
||||
|
||||
|
||||
@bot.tree.command(name='hello', description='Replies with Hello World!')
|
||||
@bot.tree.command(name='hello', description='Screams at you!')
|
||||
async def hello_command(interaction: discord.Interaction):
|
||||
await interaction.response.send_message('AAAAAAAAAAAAAAAAAAAAA!')
|
||||
async with interaction.channel.typing():
|
||||
await interaction.response.send_message('AAAAAAAAAAAAAAAAAAAAA!')
|
||||
|
||||
|
||||
@bot.event
|
||||
@@ -35,10 +36,11 @@ async def on_message(message: discord.Message):
|
||||
return
|
||||
|
||||
if message.attachments and bot.user in message.mentions:
|
||||
message_attachments = [
|
||||
{'filename': i_attachment.filename, 'url': i_attachment.url} for i_attachment in message.attachments
|
||||
]
|
||||
await message.channel.send(await image_recognition(message.content, message_attachments))
|
||||
async with message.channel.typing():
|
||||
message_attachments = [
|
||||
{'filename': i_attachment.filename, 'url': i_attachment.url} for i_attachment in message.attachments
|
||||
]
|
||||
await message.channel.send(await image_recognition(message.content, message_attachments))
|
||||
|
||||
await bot.process_commands(message)
|
||||
# endregion
|
||||
|
||||
@@ -1,28 +1,9 @@
|
||||
import asyncio
|
||||
from openai import OpenAI
|
||||
|
||||
client = OpenAI()
|
||||
SUPPORTED_IMAGE_EXTENSIONS = ('.png', '.jpg', '.jpeg', '.webp', '.gif')
|
||||
|
||||
# response = client.responses.create(
|
||||
# model="gpt-4.1-mini",
|
||||
# input=[{
|
||||
# "role": "user",
|
||||
# "content": [
|
||||
# {"type": "input_text", "text": "Что на этих картинках и в этом PDF файле?"},
|
||||
# {
|
||||
# "type": "input_image",
|
||||
# "image_url": "https://cdn.discordapp.com/attachments/1381924995994882150/1388385230108360855/2a264d9a62e7420586ee7873f53552d7.webp?ex=6860ca01&is=685f7881&hm=e8e21d0829cc9be3a21f63cb8f0c5065bf76c1de3952dbb524640694dd5037be&'>, <Attachment id=1388385230582321253 filename='",
|
||||
# },
|
||||
# {
|
||||
# "type": "input_image",
|
||||
# "image_url": "https://cdn.discordapp.com/attachments/1381924995994882150/1388385230582321253/u_312c5f5306d0913c58dd0639fe493bdd_800.png?ex=6860ca01&is=685f7881&hm=d0ebcfaecc2e69551da0cdefdf88c3833f8cbd59d04b035b787ea3150382bdd2&'>",
|
||||
# },
|
||||
# ],
|
||||
# }],
|
||||
# )
|
||||
#
|
||||
# print(response.output_text)
|
||||
|
||||
|
||||
async def image_recognition(content: str, files: list[dict[str: str]]) -> str:
|
||||
input_data = [{'type': 'input_text', 'text': content}]
|
||||
@@ -35,7 +16,6 @@ async def image_recognition(content: str, files: list[dict[str: str]]) -> str:
|
||||
for i_url in files if i_url.get('filename').lower().endswith(SUPPORTED_IMAGE_EXTENSIONS)
|
||||
]
|
||||
)
|
||||
print(input_data)
|
||||
response = client.responses.create(
|
||||
model='gpt-4.1-mini',
|
||||
input=[{
|
||||
@@ -51,12 +31,12 @@ if __name__ == '__main__':
|
||||
'content': 'What\'s on these images?',
|
||||
'files': [
|
||||
{
|
||||
'filename': '2a264d9a62e7420586ee7873f53552d7.webp',
|
||||
'url': 'https://cdn.discordapp.com/attachments/1381924995994882150/1388385230108360855/2a264d9a62e7420586ee7873f53552d7.webp?ex=6860ca01&is=685f7881&hm=e8e21d0829cc9be3a21f63cb8f0c5065bf76c1de3952dbb524640694dd5037be&',
|
||||
'filename': 'Вы_продоёте_рыбов.jpg',
|
||||
'url': 'https://upload.wikimedia.org/wikipedia/ru/8/8a/%D0%92%D1%8B_%D0%BF%D1%80%D0%BE%D0%B4%D0%BE%D1%91%D1%82%D0%B5_%D1%80%D1%8B%D0%B1%D0%BE%D0%B2.jpg',
|
||||
},
|
||||
{
|
||||
'filename': 'u_312c5f5306d0913c58dd0639fe493bdd_800.png',
|
||||
'url': 'https://cdn.discordapp.com/attachments/1381924995994882150/1388385230582321253/u_312c5f5306d0913c58dd0639fe493bdd_800.png?ex=6860ca01&is=685f7881&hm=d0ebcfaecc2e69551da0cdefdf88c3833f8cbd59d04b035b787ea3150382bdd2&',
|
||||
'filename': 'Putin_and_Macron_meeting_with_a_large_table.jpg',
|
||||
'url': 'https://upload.wikimedia.org/wikipedia/commons/a/a9/Putin_and_Macron_meeting_with_a_large_table.jpg',
|
||||
},
|
||||
{
|
||||
'filename': 'shitty_pdf_file.pdf',
|
||||
@@ -64,4 +44,5 @@ if __name__ == '__main__':
|
||||
}
|
||||
],
|
||||
}
|
||||
print(image_recognition(**data))
|
||||
result = asyncio.run(image_recognition(**data))
|
||||
print(result)
|
||||
|
||||
Reference in New Issue
Block a user