File size: 1,452 Bytes
12cca3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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 import feed_articles_to_gpt_with_links
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)
       
        
        # Prepare source metadata for citations
        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)