|
import os
|
|
import pandas as pd
|
|
from get_keywords import get_keywords
|
|
from get_articles import save_solr_articles_full
|
|
from rerank import langchain_rerank_answer, langchain_with_sources, crossencoder_rerank_answer, \
|
|
crossencoder_rerank_sentencewise, crossencoder_rerank_sentencewise_articles, no_rerank
|
|
|
|
from feed_to_llm_v2 import feed_articles_to_gpt_with_links
|
|
|
|
|
|
def get_response(question, rerank_type="crossencoder", llm_type="chat"):
|
|
|
|
try:
|
|
|
|
csv_path = save_solr_articles_full(question, keyword_type="rake")
|
|
|
|
reranked_out = crossencoder_rerank_answer(csv_path, question)
|
|
|
|
|
|
|
|
citations = [
|
|
{"title": article["title"], "url": article["url"], "source": article["source"]}
|
|
for article in reranked_out
|
|
]
|
|
|
|
|
|
result = feed_articles_to_gpt_with_links(reranked_out, question, citations)
|
|
|
|
|
|
return result
|
|
except Exception as e:
|
|
return "", [], [], []
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
question = "How is United States fighting against tobacco addiction?"
|
|
rerank_type = "crossencoder"
|
|
llm_type = "chat"
|
|
response, links, titles, domains = get_response(question, rerank_type, llm_type)
|
|
print(response)
|
|
print(links)
|
|
print(titles)
|
|
print(domains) |