added gpt4 vision, and changed the gpt4 model to a cheaper one!
This commit is contained in:
parent
2951f210cd
commit
5103821b9c
1 changed files with 38 additions and 1 deletions
|
|
@ -869,7 +869,44 @@ async def question(ctx):
|
|||
)
|
||||
async def question_gpt4(ctx):
|
||||
question = ctx.message.content.split(" ", maxsplit=1)[1]
|
||||
answer = await answer_question(question, "gpt-4")
|
||||
answer = await answer_question(question, "gpt-4-vision-preview")
|
||||
chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)]
|
||||
for chunk in chunks:
|
||||
await ctx.send(chunk)
|
||||
|
||||
@bot.command(
|
||||
description="Image GPT4",
|
||||
help="Ask GPT4 a question about an image. Usage: !question_gpt4 (link) (question)",
|
||||
brief="Get an answer"
|
||||
)
|
||||
async def image_gpt4(ctx):
|
||||
image_link = ctx.message.content.split(" ", maxsplit=2)[1]
|
||||
question = ctx.message.content.split(" ", maxsplit=2)[2]
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': f'Bearer {os.getenv("openai.api_key")}',
|
||||
}
|
||||
|
||||
data = {
|
||||
"model": "gpt-4-vision-preview",
|
||||
"messages": [{"role": "user", "content": [{"type": "text", "text": question},{"type": "image_url","image_url": {"url": image_link}}]}]
|
||||
}
|
||||
|
||||
url = "https://api.openai.com/v1/chat/completions"
|
||||
|
||||
#try:
|
||||
async with bot.http_session.post(url, headers=headers, json=data) as resp:
|
||||
response_data = await resp.json()
|
||||
print(response_data)
|
||||
answer = response_data['choices'][0]['message']['content']
|
||||
|
||||
|
||||
#except Exception as error:
|
||||
# return await handle_error(error)
|
||||
|
||||
|
||||
#answer = await answer_question(question, "gpt-4-1106-vision-preview")
|
||||
chunks = [answer[i:i+1999] for i in range(0, len(answer), 1999)]
|
||||
for chunk in chunks:
|
||||
await ctx.send(chunk)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue