from langchain.chat_models import ChatOpenAI from langchain.schema import AIMessage, HumanMessage import openai import gradio as gr from full_chain import get_response import os api_key = os.getenv("OPENAI_API_KEY") client = openai.OpenAI(api_key=api_key) def create_hyperlink(url, title, domain): return f"{title}" + " (" + domain + ")" def predict(message, history): print("get_responses: ") # print(get_response(message, rerank_type="crossencoder")) responder, links, titles, domains = get_response(message, rerank_type="crossencoder") for i in range(len(links)): links[i] = create_hyperlink(links[i], titles[i], domains[i]) out = responder + "\n" + "\n".join(links) return out gr.ChatInterface(predict, examples = [ "How many Americans Smoke?", "What are some measures taken by the Indian Government to reduce the smoking population?", "Does smoking negatively affect my health?" ] ).launch()