Crewai Code Interpreter Agent, um eine Verbindung zu meiner lokalen MySQL -Datenbank herzustellenPython

Python-Programme
Guest
 Crewai Code Interpreter Agent, um eine Verbindung zu meiner lokalen MySQL -Datenbank herzustellen

Post by Guest »

Ich baue einen Multi-Agent-Workflow mit crewai < /em>, der aus zwei Hauptteilen besteht: < /p>

< Strong> SQL -Abfragegenerierung: < /strong>

Ich habe einen Agenten, der benutzerdefinierte SQL -Tools (basierend auf Crewai) verwendet, um SQL -Abfragen zu generieren. Zum Beispiel verwende ich solche Tools: < /p>
@tool("list_tables")
def list_tables() -> str:
"""List the available tables in the database"""
return ListSQLDatabaseTool(db=db).invoke("")

@tool("tables_schema")
def tables_schema(tables: str) -> str:
"""
Input: a comma-separated list of tables.
Output: the schema and sample rows for those tables.
"""
tool_instance = InfoSQLDatabaseTool(db=db)
return tool_instance.invoke(tables)

@tool("execute_sql")
def execute_sql(sql_query: str) -> str:
"""Execute a SQL query against the database and return the result."""
return QuerySQLDataBaseTool(db=db).invoke(sql_query)

@tool("check_sql")
def check_sql(sql_query: str) -> str:
"""
Check the SQL query for common errors before executing it.
Input: a string containing the SQL query.
"""
return QuerySQLCheckerTool(db=db, llm=LLM).invoke({"query": sql_query})
< /code>
< /li>
Datenanalyse und Diagrammgenerierung: < /strong>

Ich habe dann einen separaten Python -Code Interpreter -Agent, um die SQL -Ergebnisse zu analysieren und Diagramme zu generieren. Ich bekomme die SQL-Abfrage aus dem vorherigen Agenten und mache die Analyse mit Python.coding_agent = Agent(
role="Python Code Interpreter Agent",
goal="Run code to achieve a task given by the user",
backstory="You are an agent that helps users run Python code.",
allow_code_execution=True,
llm=LLM,
)
< /code>
< /li>
< /ol>
Meine lokale MySQL -Datenbank wird mit der Verbindungszeichenfolge ausgeführt: < /p>
SQL_LOCALHOST = "mysql+mysqldb://root:[email protected]:3306/analytics_db"
< /code>

Probleme < /strong> < /p>

modulenotFounderror: < /strong>

Beim Ausführen von Code im Code -Interpreter -Agenten begegne ich den folgenden Fehler: < /li>
< /ol>

modulenotFoundError: Kein Modul mit dem Namen 'MySQLDB'

Es scheint p>

Datenbankverbindung: < /strong>

Ich möchte DB. < /li>
< /ol>

Gibt es eine empfohlene Möglichkeit, das erforderliche MySQLDB < /code> -Modul (oder MySQLClient < /zu installieren < / Code>) im Docker -Bild des Code -Interpreter? Welche Schritte sollten ich unternehmen, um das Bild oder die Umgebung zu ändern, um dieses Modul zu unterstützen?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post