Skip to content

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
Signed-off-by: Zoey <[email protected]>
  • Loading branch information
Zoey2936 authored Dec 17, 2024
1 parent d1916e3 commit f06ce73
Showing 1 changed file with 113 additions and 36 deletions.
149 changes: 113 additions & 36 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,119 @@ async def on_ready():
print("Bot is running!")


#if "OAI_KEY" in os.environ:
# @bot.command(description="Hi by ZoeyVid! (o1-mini) 3$/12$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install})
# @default_permissions(administrator=True)
# async def o1mini(ctx, prompt: discord.Option(str, description="Der Prompt")):
# await ctx.defer()
# print(prompt)
# print("Hi by ZoeyVid! ^(o1-mini) 3$/12$^")
# message = oaiclient.chat.completions.create(
# model="o1-mini",
# messages=[
# {"role": "user", "content": prompt}
# ]
# )
# for i in range(ceil(len(message.choices[0].message.content) / 4096)):
# embed = discord.Embed(title="Hi by ZoeyVid! (o1-mini) 3$/12$")
# embed.description = (message.choices[0].message.content[(4096*i):(4096*(i+1))])
# await ctx.respond(embed=embed)
if "OAI_KEY" in os.environ:
@bot.command(description="Hi by ZoeyVid! (o1-mini) 3$/12$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install})
@default_permissions(administrator=True)
async def o1mini(ctx, prompt: discord.Option(str, description="Der Prompt")):
await ctx.defer()
print(prompt)
print("Hi by ZoeyVid! ^(o1-mini) 3$/12$^")
message = oaiclient.chat.completions.create(
model="o1-mini",
messages=[
{"role": "user", "content": prompt}
]
)
for i in range(ceil(len(message.choices[0].message.content) / 4096)):
embed = discord.Embed(title="Hi by ZoeyVid! (o1-mini) 3$/12$")
embed.description = (message.choices[0].message.content[(4096*i):(4096*(i+1))])
await ctx.respond(embed=embed)

#if "OAI_KEY" in os.environ:
# @bot.command(description="Hi by ZoeyVid! (o1-preview) 15$/60$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install})
# @default_permissions(administrator=True)
# async def o1preview(ctx, prompt: discord.Option(str, description="Der Prompt")):
# await ctx.defer()
# print(prompt)
# print("Hi by ZoeyVid! ^(o1-preview) 15$/60$^")
# message = oaiclient.chat.completions.create(
# model="o1-preview",
# messages=[
# {"role": "user", "content": prompt}
# ]
# )
# for i in range(ceil(len(message.choices[0].message.content) / 4096)):
# embed = discord.Embed(title="Hi by ZoeyVid! (o1-preview) 15$/60$")
# embed.description = (message.choices[0].message.content[(4096*i):(4096*(i+1))])
# await ctx.respond(embed=embed)
if "OAI_KEY" in os.environ:
@bot.command(description="Hi by ZoeyVid! (o1) 15$/60$", contexts={discord.InteractionContextType.guild, discord.InteractionContextType.private_channel}, integration_types={discord.IntegrationType.guild_install, discord.IntegrationType.user_install})
@default_permissions(administrator=True)
async def gpt(ctx, prompt: discord.Option(str, description="Der Prompt"), url: discord.Option(str, required=False, description="URL für file_search"), image: discord.Option(discord.Attachment, required=False, description="Bild"), filesearch: discord.Option(discord.Attachment, required=False, description="Datei für file_search"), codeinterpreter: discord.Option(discord.Attachment, required=False, description="Datei für code_interpreter")):
await ctx.defer()
print(prompt)
print("Hi by ZoeyVid! ^(o1) 15$/60$^")
if url:
async with async_playwright() as playwright:
chromium = playwright.chromium
browser = await chromium.launch()
page = await browser.new_page(locale="de-DE", timezone_id="Europe/Berlin", user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0")
await page.goto(url)
await page.emulate_media(media="screen")
pdf = await page.pdf(width="1440px", height="2560px", landscape=True)
await browser.close()
file = oaiclient.files.create(file=("Webseite.pdf", pdf), purpose="assistants")
assistant = oaiclient.beta.assistants.create(model="o1", tools=[{"type": "file_search"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Webseite, welche du als PDF-Datei im Anhang findest.")
thread = oaiclient.beta.threads.create()
oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "file_search"}]}])
run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id)
while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed":
pass
all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id)
print(all_messages.data[0].content[0].text.value)
oaiclient.files.delete(file.id)
oaiclient.beta.threads.delete(thread.id)
oaiclient.beta.assistants.delete(assistant.id)
for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)):
embed = discord.Embed(title="Hi by ZoeyVid! (o1) 15$/60$")
embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))])
await ctx.respond(embed=embed)
elif filesearch:
file = oaiclient.files.create(file=(filesearch.filename, await filesearch.read()), purpose="assistants")
assistant = oaiclient.beta.assistants.create(model="o1", tools=[{"type": "file_search"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Datei, welche du im Anhang findest.")
thread = oaiclient.beta.threads.create()
oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "file_search"}]}])
run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id)
while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed":
pass
all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id)
print(all_messages.data[0].content[0].text.value)
oaiclient.files.delete(file.id)
oaiclient.beta.threads.delete(thread.id)
oaiclient.beta.assistants.delete(assistant.id)
for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)):
embed = discord.Embed(title="Hi by ZoeyVid! (o1) 15$/60$")
embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))])
await ctx.respond(embed=embed)
elif codeinterpreter:
file = oaiclient.files.create(file=(codeinterpreter.filename, await codeinterpreter.read()), purpose="assistants")
assistant = oaiclient.beta.assistants.create(model="o1", tools=[{"type": "code_interpreter"}], instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die Datei, welche du im Anhang findest.")
thread = oaiclient.beta.threads.create()
oaiclient.beta.threads.messages.create(thread.id, role="user", content=prompt, attachments=[{"file_id": file.id, "tools": [{"type": "code_interpreter"}]}])
run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id)
while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed":
pass
all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id)
print(all_messages.data[0].content[0].text.value)
oaiclient.files.delete(file.id)
oaiclient.beta.threads.delete(thread.id)
oaiclient.beta.assistants.delete(assistant.id)
for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)):
embed = discord.Embed(title="Hi by ZoeyVid! (o1) 15$/60$")
embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))])
await ctx.respond(embed=embed)
elif image:
file = oaiclient.files.create(file=(image.filename, await image.read()), purpose="assistants")
assistant = oaiclient.beta.assistants.create(model="o1", instructions="Du befolgst die dir gegebenen Anweisungen und beachtest dabei das Bild, welche du im Anhang findest.")
thread = oaiclient.beta.threads.create()
oaiclient.beta.threads.messages.create(thread.id, role="user", content=[{"type": "text", "text": prompt}, {"type": "image_file", "image_file": {"file_id": file.id}}])
run = oaiclient.beta.threads.runs.create(thread.id, assistant_id=assistant.id)
while oaiclient.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id).status != "completed":
pass
all_messages = oaiclient.beta.threads.messages.list(thread_id=thread.id)
print(all_messages.data[0].content[0].text.value)
oaiclient.files.delete(file.id)
oaiclient.beta.threads.delete(thread.id)
oaiclient.beta.assistants.delete(assistant.id)
for i in range(ceil(len(all_messages.data[0].content[0].text.value) / 4096)):
embed = discord.Embed(title="Hi by ZoeyVid! (o1) 15$/60$")
embed.description = (all_messages.data[0].content[0].text.value[(4096*i):(4096*(i+1))])
await ctx.respond(embed=embed)
else:
message = oaiclient.chat.completions.create(
model="o1",
messages=[
{"role": "system", "content": "Du befolgst die dir gegebenen Anweisungen."},
{"role": "user", "content": prompt}
]
)
for i in range(ceil(len(message.choices[0].message.content) / 4096)):
embed = discord.Embed(title="Hi by ZoeyVid! (o1) 15$/60$")
embed.description = (message.choices[0].message.content[(4096*i):(4096*(i+1))])
await ctx.respond(embed=embed)


if "OAI_KEY" in os.environ:
Expand Down Expand Up @@ -358,9 +436,8 @@ async def sonnet(ctx, prompt: discord.Option(str, description="Der Prompt"), url
embed.description = (message.content[0].text[(4096*i):(4096*(i+1))])
await ctx.respond(embed=embed)
elif mimetypes.guess_type(file.filename)[0] == "application/pdf":
message = aclient.beta.messages.create(
message = aclient.messages.create(
model="claude-3-5-sonnet-latest",
betas=["pdfs-2024-09-25"],
max_tokens=8192,
system="Du befolgst die dir gegebenen Anweisungen und beachtest dabei die PDF, welche du im Anhang findest.",
messages=[
Expand Down

0 comments on commit f06ce73

Please sign in to comment.