Basic OpenAI Summarize Function
This commit is contained in:
@@ -8,6 +8,9 @@ import requests as req
|
||||
from bs4 import BeautifulSoup as soup
|
||||
import pdftotext
|
||||
import sys
|
||||
import openai
|
||||
|
||||
openai.api_key = os.getenv("OPENAI_KEY")
|
||||
|
||||
def eprint(*args, **kwargs):
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
@@ -42,6 +45,18 @@ async def getPDF(url):
|
||||
pages = pdftotext.PDF(pdf)
|
||||
return "\n\n".join(pages)
|
||||
|
||||
async def summarize(pdf):
|
||||
completion = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "user", "content": f"""Please summarize the following research paper:
|
||||
---
|
||||
{pdf}
|
||||
"""}
|
||||
]
|
||||
)
|
||||
return completion
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f'We have logged in as {bot.user}')
|
||||
@@ -61,8 +76,9 @@ async def summarize(
|
||||
return
|
||||
|
||||
msg = await interaction.followup.send(f"""Article Found: {resp['ref']}
|
||||
Parsing PDF...""")
|
||||
Processing PDF...""")
|
||||
pdf = await getPDF(resp['pdf'])
|
||||
|
||||
await msg.edit(f"""Article Found: {resp['ref']}
|
||||
```
|
||||
{pdf[:1000]}
|
||||
|
||||
Reference in New Issue
Block a user