Repository navigation
v0.1.3
馃摝 SQL Agent Tool v0.1.3
This release introduces an interactive chat interface and enhanced LLM flexibility, empowering users to select their preferred language model for natural language to SQL conversion.
馃敡 Updates
- Chat Interface: Added an interactive chat mode for real-time query input and execution.
- LLM Selection: Users can now choose from multiple LLM providers (Groq, Gemini, OpenAI, DeepSeek) to generate SQL, tailored to their needs.
馃搳 Sample Code
# Launch chat interface and select LLM
#this are contents of test1.py for testing of tool
from sql_agent_tool.model import SQLAgentTool, DatabaseConfig, LLMConfig
config = DatabaseConfig(
drivername="postgresql",
username="postgres",
password="password",
host="localhost",
port=5433,
database="P2"
)
llm_config = LLMConfig(provider="gemini", api_key=LLM_API_KEY, model="models/gemini-1.5-flash", max_tokens=500)
sql_tool = SQLAgentTool(config, llm_config)
try:
print("\nQuery 1:")
q1_start = time.time()
result = agent_tool.process_natural_language_query("what are top courses purchased by maximum students?")
print(f"Query 1 total time: {time.time() - q1_start:.2f} seconds")
if result.success:
print(f"Query executed successfully, found {result.row_count} results:")
for row in result.data:
print(row)
print("\nQuery 2:")
q2_start = time.time()
result2 = agent_tool.process_natural_language_query("Are there any student named harsh?")
print(f"Query 2 total time: {time.time() - q2_start:.2f} seconds")
if result2.success:
print(f"Query executed successfully, found {result2.row_count} results:")
for row in result2.data:
print(row)
except Exception as e:
print(f"Error processing queries: {e}")
finally:
agent_tool.close()
print(f"Total time: {time.time() - start_time:.2f} seconds")馃搳 Sample Output
Selected LLM: Gemini
Enter your query: Show me all courses with the most purchases
Generated SQL:
SELECT c.id, c.title, COUNT(p.id) as purchase_count
FROM courses c
JOIN payments p ON c.id = p.course_id
GROUP BY c.id, c.title
ORDER BY purchase_count DESC
LIMIT 500;
Parameters: {}
Query executed successfully, found 14 results:
{'id': ..., 'title': 'Social Media Marketing (SMM)', 'purchase_count': 6}
...
Developed By - @Dadiya-Harsh, @Dadiya-Harsh-wappnet
馃敆 View on PyPI
Notes
- Version: Bumped to
v0.1.3since this is a significant feature update (chat interface + LLM choice) beyond the initialv0.1.2. - Sample Code: Assumed
test1.pynow supports--chatand--llmflags for the chat interface and LLM selection. If your implementation differs (e.g., no CLI flags), let me know, and I鈥檒l adjust it! - Sample Output: Adapted from your latest Groq-based run, simplified for brevity.
Full Changelog: v0.1.2...v0.1.3