Spaces:
Sleeping
Sleeping
reflexion pour maths
Browse files- agent.py +29 -0
- requirements.txt +4 -1
agent.py
CHANGED
|
@@ -6,8 +6,16 @@ from langchain.chat_models import init_chat_model
|
|
| 6 |
import os
|
| 7 |
from langchain_openai import ChatOpenAI
|
| 8 |
from langgraph.prebuilt import create_react_agent
|
|
|
|
| 9 |
from openai import OpenAI
|
| 10 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
api_open_ai_agent_key=os.environ["OPENAI_API_KEY"]
|
| 13 |
client = OpenAI(api_key=api_open_ai_agent_key)
|
|
@@ -123,6 +131,27 @@ def divide(a: float, b: float):
|
|
| 123 |
"""Divide two numbers."""
|
| 124 |
return a / b
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
research_agent = create_react_agent(
|
| 127 |
model=llm_4o,
|
| 128 |
tools=[wiki_search, arvix_search],
|
|
|
|
| 6 |
import os
|
| 7 |
from langchain_openai import ChatOpenAI
|
| 8 |
from langgraph.prebuilt import create_react_agent
|
| 9 |
+
from langchain_experimental.agents import create_pandas_dataframe_agent
|
| 10 |
from openai import OpenAI
|
| 11 |
import re
|
| 12 |
+
from pydantic import BaseModel
|
| 13 |
+
from typing import List, Dict
|
| 14 |
+
import pandas as pd
|
| 15 |
+
|
| 16 |
+
class ToolInput(BaseModel):
|
| 17 |
+
data: List[Dict]
|
| 18 |
+
question: str
|
| 19 |
|
| 20 |
api_open_ai_agent_key=os.environ["OPENAI_API_KEY"]
|
| 21 |
client = OpenAI(api_key=api_open_ai_agent_key)
|
|
|
|
| 131 |
"""Divide two numbers."""
|
| 132 |
return a / b
|
| 133 |
|
| 134 |
+
|
| 135 |
+
@tool
|
| 136 |
+
def open_xlsx_doc(path: str) -> pd.DataFrame:
|
| 137 |
+
""" Open a pandas DataFrame from a xlsx file path"""
|
| 138 |
+
df = pd.read_excel(path)
|
| 139 |
+
return df.to_dict(orient="records")
|
| 140 |
+
@tool
|
| 141 |
+
def create_agent_and_answer(input: ToolInput) -> str:
|
| 142 |
+
""" From a dataframe, can anwser any question
|
| 143 |
+
The input should be like : input_data = ToolInput(
|
| 144 |
+
question="Quel est l'âge moyen ?",
|
| 145 |
+
data= 'ouput of the open_xlsx_doc tool'
|
| 146 |
+
"""
|
| 147 |
+
df = pd.DataFrame(input.data)
|
| 148 |
+
question = input.question
|
| 149 |
+
agent_excel = create_pandas_dataframe_agent(llm_4o, df, verbose=True, allow_dangerous_code=True)
|
| 150 |
+
text = agent_excel.run(question)
|
| 151 |
+
|
| 152 |
+
return text
|
| 153 |
+
|
| 154 |
+
|
| 155 |
research_agent = create_react_agent(
|
| 156 |
model=llm_4o,
|
| 157 |
tools=[wiki_search, arvix_search],
|
requirements.txt
CHANGED
|
@@ -7,4 +7,7 @@ langgraph-supervisor
|
|
| 7 |
langchain-openai
|
| 8 |
wikipedia
|
| 9 |
arxiv
|
| 10 |
-
pymupdf
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
langchain-openai
|
| 8 |
wikipedia
|
| 9 |
arxiv
|
| 10 |
+
pymupdf
|
| 11 |
+
langchain-experimental
|
| 12 |
+
tabulate
|
| 13 |
+
pandas
|