-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarizer.py
37 lines (33 loc) · 1.13 KB
/
summarizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import openai
from dotenv import load_dotenv
class PaperSummarizer:
def __init__(self, api_key):
self.api_key = api_key
openai.api_key = api_key
def get_summary(self, text):
client = openai.OpenAI(api_key=api_key)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": "You are a helpful assistant that summarizes research papers.",
},
{
"role": "user",
"content": f"Summarize the following research paper: {text}",
}
]
)
summary = response.choices[0]['message']['content'].strip()
return summary
if __name__ == "__main__":
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
raise ValueError("API key not found. Please set it in the .env file")
text = input("Enter the text you want to summarize: ")
summarizer = PaperSummarizer(api_key)
summary = summarizer.get_summary(text)
print(summary)