Spaces:
Sleeping
Sleeping
File size: 1,573 Bytes
4863f6e aea1727 4863f6e aea1727 |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
from langchain.tools import tool
from langchain_community.document_loaders import WikipediaLoader
@tool
def multiply(a: float, b: float) -> float:
"""
Multiplie deux nombres.
:param a: Le premier nombre à multiplier.
:param b: Le deuxième nombre à multiplier.
:return: Le produit de a et b.
"""
return a * b
@tool
def substract(a: float, b: float) -> float:
"""
Soustrait b de a.
:param a: Le nombre duquel soustraire.
:param b: Le nombre à soustraire.
:return: La différence entre a et b.
"""
return a - b
@tool
def add(a: float, b: float) -> float:
"""
Additionne deux nombres.
:param a: Le premier nombre.
:param b: Le deuxième nombre.
:return: La somme de a et b.
"""
return a + b
@tool
def divide(a: float, b: float) -> float:
"""
Divise a par b.
:param a: Le numérateur.
:param b: Le dénominateur.
:return: Le résultat de la division de a par b.
:raises ZeroDivisionError: Si b est égal à zéro.
"""
return a / b
@tool
def wiki_search(query: str) -> str:
"""Search Wikipedia for a query and return maximum 2 results.
Args:
query: The search query."""
search_docs = WikipediaLoader(query=query, load_max_docs=2).load()
formatted_search_docs = "\n\n---\n\n".join(
[
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
for doc in search_docs
])
return {"wiki_results": formatted_search_docs} |