Compare commits

...
7 Commits
2 changed files with 15 additions and 32 deletions
+3 -1
View File
@@ -24,8 +24,9 @@ async def on_ready():
print(f'Failed to sync commands: {e}') 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): async def hello_command(interaction: discord.Interaction):
async with interaction.channel.typing():
await interaction.response.send_message('AAAAAAAAAAAAAAAAAAAAA!') await interaction.response.send_message('AAAAAAAAAAAAAAAAAAAAA!')
@@ -35,6 +36,7 @@ async def on_message(message: discord.Message):
return return
if message.attachments and bot.user in message.mentions: if message.attachments and bot.user in message.mentions:
async with message.channel.typing():
message_attachments = [ message_attachments = [
{'filename': i_attachment.filename, 'url': i_attachment.url} for i_attachment in message.attachments {'filename': i_attachment.filename, 'url': i_attachment.url} for i_attachment in message.attachments
] ]
+7 -26
View File
@@ -1,28 +1,9 @@
import asyncio
from openai import OpenAI from openai import OpenAI
client = OpenAI() client = OpenAI()
SUPPORTED_IMAGE_EXTENSIONS = ('.png', '.jpg', '.jpeg', '.webp', '.gif') 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: async def image_recognition(content: str, files: list[dict[str: str]]) -> str:
input_data = [{'type': 'input_text', 'text': content}] 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) for i_url in files if i_url.get('filename').lower().endswith(SUPPORTED_IMAGE_EXTENSIONS)
] ]
) )
print(input_data)
response = client.responses.create( response = client.responses.create(
model='gpt-4.1-mini', model='gpt-4.1-mini',
input=[{ input=[{
@@ -51,12 +31,12 @@ if __name__ == '__main__':
'content': 'What\'s on these images?', 'content': 'What\'s on these images?',
'files': [ 'files': [
{ {
'filename': '2a264d9a62e7420586ee7873f53552d7.webp', 'filename': 'Вы_продоёте_рыбов.jpg',
'url': 'https://cdn.discordapp.com/attachments/1381924995994882150/1388385230108360855/2a264d9a62e7420586ee7873f53552d7.webp?ex=6860ca01&is=685f7881&hm=e8e21d0829cc9be3a21f63cb8f0c5065bf76c1de3952dbb524640694dd5037be&', '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', 'filename': 'Putin_and_Macron_meeting_with_a_large_table.jpg',
'url': 'https://cdn.discordapp.com/attachments/1381924995994882150/1388385230582321253/u_312c5f5306d0913c58dd0639fe493bdd_800.png?ex=6860ca01&is=685f7881&hm=d0ebcfaecc2e69551da0cdefdf88c3833f8cbd59d04b035b787ea3150382bdd2&', 'url': 'https://upload.wikimedia.org/wikipedia/commons/a/a9/Putin_and_Macron_meeting_with_a_large_table.jpg',
}, },
{ {
'filename': 'shitty_pdf_file.pdf', 'filename': 'shitty_pdf_file.pdf',
@@ -64,4 +44,5 @@ if __name__ == '__main__':
} }
], ],
} }
print(image_recognition(**data)) result = asyncio.run(image_recognition(**data))
print(result)