IBHS commited on
Commit
1ece4ad
·
verified ·
1 Parent(s): d031515

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. .DS_Store +0 -0
  2. chroma_store/.DS_Store +0 -0
  3. main.py +25 -23
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
chroma_store/.DS_Store ADDED
Binary file (6.15 kB). View file
 
main.py CHANGED
@@ -88,30 +88,32 @@ def llm_response(query):
88
  titles, links, res_titles, res_links = [], [], [], []
89
  try:
90
  result = chain.invoke({"input": query})
 
 
91
  answer = result['answer']['cited_answer'][0]["answer"]
92
- citations = result['answer']['cited_answer'][1]['citations']
93
- for citation in citations:
94
- edited_item = citation['citation'][1]["source"].replace("Articles/", "")
95
- title, link = get_article_info(df, edited_item)
96
- if title not in titles:
97
- titles.append(title)
98
- if link not in links:
99
- links.append(link)
100
- question_search = retriever.invoke(query)
101
- for res_item in question_search:
102
- edited_item = res_item.metadata["source"].replace("Articles/", "")
103
- res_title, res_link = get_article_info(df, edited_item)
104
- if res_title not in res_titles:
105
- res_titles.append(res_title)
106
- if res_link not in res_links:
107
- res_links.append(res_link)
108
- # markdown_list = f"{answer}\n\nCitations:\n" + "\n".join(
109
- # [f"- [{title}]({link})" for title, link in zip(titles, links)])
110
-
111
- # Build the answer with superscript citations
112
- answer_with_citations = f"{answer}"
113
- for i, (title, link) in enumerate(zip(titles, links), start=1):
114
- answer_with_citations += f" <sup>[[{i}]({link})]</sup> " # Append superscript citation numbers to the answer text
115
 
116
  # Build the references section with clickable links
117
  citations_section = "\n\nCitations:\n" + "\n".join(
 
88
  titles, links, res_titles, res_links = [], [], [], []
89
  try:
90
  result = chain.invoke({"input": query})
91
+ if not result['answer']['cited_answer']:
92
+ return "There are no articles relevant to your inquiry..."
93
  answer = result['answer']['cited_answer'][0]["answer"]
94
+ if result['answer']['cited_answer']:
95
+ citations = result['answer']['cited_answer'][1]['citations']
96
+ for citation in citations:
97
+ edited_item = citation['citation'][1]["source"].replace("Articles/", "")
98
+ title, link = get_article_info(df, edited_item)
99
+ if title not in titles:
100
+ titles.append(title)
101
+ if link not in links:
102
+ links.append(link)
103
+ question_search = retriever.invoke(query)
104
+ for res_item in question_search:
105
+ edited_item = res_item.metadata["source"].replace("Articles/", "")
106
+ res_title, res_link = get_article_info(df, edited_item)
107
+ if res_title not in res_titles:
108
+ res_titles.append(res_title)
109
+ if res_link not in res_links:
110
+ res_links.append(res_link)
111
+ # Build the answer with superscript citations
112
+ answer_with_citations = f"{answer}"
113
+ for i, (title, link) in enumerate(zip(titles, links), start=1):
114
+ answer_with_citations += f" <sup>[[{i}]({link})]</sup> "
115
+ else:
116
+ answer_with_citations = f"{answer}"
117
 
118
  # Build the references section with clickable links
119
  citations_section = "\n\nCitations:\n" + "\n".join(