-
Notifications
You must be signed in to change notification settings - Fork 0
add sql database tool #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,4 @@ requirements.txt | |
assets/ | ||
.langgraph_api | ||
generated/ | ||
*.db |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
from template_langgraph.llms.azure_openais import AzureOpenAiWrapper | ||
from template_langgraph.tools.cosmosdb_tool import search_cosmosdb | ||
from template_langgraph.tools.dify_tool import run_dify_workflow | ||
from template_langgraph.tools.elasticsearch_tool import search_elasticsearch | ||
from template_langgraph.tools.qdrant_tool import search_qdrant | ||
from template_langgraph.tools.sql_database_tool import SqlDatabaseClientWrapper | ||
|
||
DEFAULT_TOOLS = [ | ||
search_cosmosdb, | ||
run_dify_workflow, | ||
search_qdrant, | ||
search_elasticsearch, | ||
] | ||
] + SqlDatabaseClientWrapper().get_tools( | ||
llm=AzureOpenAiWrapper().chat_model, | ||
) | ||
Comment on lines
8
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creating SqlDatabaseClientWrapper and AzureOpenAiWrapper instances at module import time can cause initialization delays and potential connection issues. Consider lazy initialization or moving this to a function that's called when needed. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||
from functools import lru_cache | ||||||
|
||||||
from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit | ||||||
from langchain_community.utilities.sql_database import SQLDatabase | ||||||
from langchain_core.language_models import BaseLanguageModel | ||||||
from langchain_core.tools.base import BaseTool | ||||||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||||||
|
||||||
|
||||||
class Settings(BaseSettings): | ||||||
sql_database_uri: str = "sqlite:///template_langgraph.db" | ||||||
|
||||||
model_config = SettingsConfigDict( | ||||||
env_file=".env", | ||||||
env_ignore_empty=True, | ||||||
extra="ignore", | ||||||
) | ||||||
|
||||||
|
||||||
@lru_cache | ||||||
def get_sql_database_settings() -> Settings: | ||||||
"""Get SQL Database settings.""" | ||||||
return Settings() | ||||||
|
||||||
|
||||||
class SqlDatabaseClientWrapper: | ||||||
def __init__( | ||||||
self, | ||||||
settings: Settings = None, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Using mutable default arguments with None and then reassigning is a common pattern, but using 'settings: Settings | None = None' would be more explicit about the type annotation in modern Python.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
): | ||||||
if settings is None: | ||||||
settings = get_sql_database_settings() | ||||||
self.db = SQLDatabase.from_uri( | ||||||
database_uri=settings.sql_database_uri, | ||||||
) | ||||||
|
||||||
def get_tools( | ||||||
self, | ||||||
llm: BaseLanguageModel, | ||||||
) -> list[BaseTool]: | ||||||
"""Get SQL Database tools.""" | ||||||
return SQLDatabaseToolkit( | ||||||
db=self.db, | ||||||
llm=llm, | ||||||
).get_tools() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mixed message format handling (dict vs object with .content attribute) suggests inconsistent data structures. Consider standardizing the message format or adding type hints to clarify the expected structure.
Copilot uses AI. Check for mistakes.