-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopics.py
55 lines (50 loc) · 1.84 KB
/
topics.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import openai
from dotenv import load_dotenv
class TopicResearcher:
def __init__(self, api_key):
openai.api_key = api_key
self.client = openai.OpenAI(api_key=api_key)
def get_topics(self, interested_topic, skill_level):
prompt = f"Give important topics for {interested_topic} with {skill_level} level for which research papers are available on arXiv."
response = self.client.chat.completions.create(
messages=[
{
"role": "user",
"content": f"{prompt}",
}
],
model="gpt-3.5-turbo",
)
topics = []
if response and response.choices:
for choice in response.choices:
topics.append(choice.message.content.strip())
return topics
def get_research_papers(self, topic):
prompt = f"Give most important research paper article name and the name of the authors for {topic} only if available on arXiv."
response = self.client.chat.completions.create(
messages=[
{
"role": "user",
"content": f"{prompt}",
}
],
model="gpt-3.5-turbo",
)
research_papers = []
if response and response.choices:
for choice in response.choices:
research_papers.append(choice.message.content.strip())
return research_papers
# Example usage
if __name__ == "__main__":
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
researcher = TopicResearcher(api_key)
topics = researcher.get_topics("Machine Learning", "Beginner")
for topic in topics:
papers = researcher.get_research_papers(topic)
print(f"Topic: {topic}")
for paper in papers:
print(f" - {paper}")