-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateCitation.py
40 lines (30 loc) · 1.3 KB
/
GenerateCitation.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
import openai
import arxiv
from ArxivSearchQueries import generate_arxiv_search_queries
from ArxivSearch import arxiv_search
from CitationFilter import find_citations
from AnalysisText import analyze_text_for_citations
from MatchStyle import match_style
from openai import OpenAI
def GenerateCitation(input_text, citation_style = "APA style"):
messages = []
# Client initialization or configuration goes here
client = OpenAI(api_key="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")
print("client initialized")
# Step 1: Analyze text for citations
step_1_out = analyze_text_for_citations(input_text, client, citation_style=citation_style)
print("step 1 output:")
print(step_1_out)
messages.append("Step 1 completed: " + str(step_1_out))
# Step 2: Generate arXiv search queries
queries_arxiv = generate_arxiv_search_queries(step_1_out, client)
print("queries_arxiv generated")
# Step 3: Search arXiv
out_dic = arxiv_search(queries_arxiv)
print("arxiv search finished")
# Step 4: Find citations
citations = find_citations(step_1_out, out_dic, client)
print("find citations finished")
# Step 5: Match style
response = match_style(client, input_text, step_1_out, citations, citation_style=citation_style)
return response, messages