Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
"""finito.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1rNnk3xajWzVdyH2eXJ58ghLpk-zejGw- | |
""" | |
!pip install -r requirements.txt | |
!pip install gradio | |
from langchain.prompts import StringPromptTemplate | |
import re | |
import langchain | |
from qa_txt import conversation_chain | |
from key_extract import chain | |
from bs4 import BeautifulSoup | |
import requests | |
from data_process import * | |
from langchain.tools.base import StructuredTool | |
from langchain.agents import initialize_agent | |
from qa_txt import llm | |
import gradio as gr | |
def faq(query: str) -> str: | |
reponse = conversation_chain({"question": query, "chat_history": []}) | |
return reponse['answer'] | |
qa_faq = StructuredTool.from_function( | |
func = faq , | |
description=""" | |
Repondre à des questions general . | |
Parameters : | |
- query (string) : the same input as the user input no more no less and dont translate it even if it is in another language. | |
Returns : | |
- string : the output as returned from the function in french. | |
""" | |
) | |
def request_data(query: str) -> str: | |
request = chain.run(query) | |
mot_cle = nettoyer_string(request) | |
mots = mot_cle.split() | |
ui = mots[0] | |
rg = chercher_data(ui) | |
if len(rg[0]): | |
reponse_final = format_reponse(rg) | |
return reponse_final | |
else: | |
return "Désolé, il semble que nous n'ayons pas de données correspondant à votre demande pour le moment. Avez-vous une autre question ou avez-vous besoin d'aide sur quelque chose d'autre?" | |
fetch_data = StructuredTool.from_function( | |
func=request_data, | |
description=""" | |
Rechercher des données. | |
Parameters : | |
- query (string) : the same input as the user input no more no less and dont translate it even if it is in another language. | |
Returns : | |
- string : the output as returned from the function in french. | |
""", | |
) | |
tools_add = [ | |
qa_faq, | |
fetch_data, | |
] | |
agent = initialize_agent( | |
tools = tools_add, | |
llm = llm, | |
agent = "zero-shot-react-description", | |
verbose = True | |
) | |
agent.invoke("bonjour je veux l'addresse de contact. Et donner moi les donnée de la finance") | |
gr.ChatInterface(agent.invoke).launch() |