Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions .devcontainer/devcontainer.json

This file was deleted.

9 changes: 9 additions & 0 deletions .env_examp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GROQ_API_KEY=your_groq_api_key_here
GROQ_MODEL_NAME=model/name

APP_NAME=Querypls
APP_VERSION=1.0.0
MAX_TOKENS=1000
TEMPERATURE=0.7
MAX_CHAT_HISTORIES=5
LOG_LEVEL=INFO
3 changes: 0 additions & 3 deletions .env_example

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ jobs:
pip3 install -r requirements.txt

- name: Run Pytest
env:
JUPYTER_PLATFORM_DIRS: "1"
run: |
pytest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ __pycache__/
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
./test_*
run_*

# Unit test / coverage reports
.coverage
Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@
[![License](https://img.shields.io/badge/License-MIT%202.0-blue.svg)](LICENSE)
<img src='https://img.shields.io/github/stars/samadpls/querypls?color=red&label=stars&logoColor=black&style=social'>

# 💬 Querypls - Prompt to SQL
# 💬 Querypls - Intelligent SQL and CSV Analysis

Querypls is a web application that provides an interactive chat interface, simplifying SQL query generation. Users can effortlessly enter SQL queries and receive corresponding results. The application harnesses the capabilities of the language models from Hugging Face to generate SQL queries based on user input.
Querypls is a modern web application that provides an interactive chat interface for SQL query generation and CSV data analysis. Built with Pydantic AI and powered by OpenAI's GPT-OSS-120B model through Groq, it offers intelligent routing between different analysis modes to handle various data-related queries.

🌐 **Try it live**: [querypls.streamlit.app](https://querypls.streamlit.app/)

## Key Features

💬 Interactive chat interface for easy communication.
🔍 Enter SQL queries and receive query results as responses.
🤖 Utilizes language models from Hugging Face for advanced query generation ([Querypls-prompt2sql](https://huggingface.co/samadpls/querypls-prompt2sql)).
💻 User-friendly interface for seamless interaction.
💬 **Interactive Chat Interface** - Natural language conversations for data analysis
🔍 **SQL Query Generation** - Convert natural language to optimized SQL queries
📊 **CSV Data Analysis** - Upload and analyze CSV files with intelligent insights
🤖 **Intelligent Routing** - Automatically determines the best agent for your query
⚡ **Fast Inference** - Powered by Groq's optimized infrastructure
🔒 **Type-Safe Development** - Built with Pydantic AI for robust validation
📈 **Visual Analytics** - Generate charts and visualizations from your data

![QueryplsDemo](https://github.com/samadpls/Querypls/assets/94792103/daa6e37d-a256-4fd8-9607-6e18cf41df3f)



# Acknowledgments

`Querypls` received a shoutout from [🦜 🔗 Langchain](https://www.langchain.com/) on their Twitter, reaching over **60,000 impressions**. Additionally, it was featured under the **Community Favorite Projects** section on `🦜 🔗 Langchain's blog`, leading to a significant increase in stars for this repository and a growing user base. The project was also highlighted in a [YouTube video](https://www.youtube.com/watch?v=htHVb-fK9xU), and it also caught the attention of Backdrop, expressing their interest and liking in an email, inviting the project to be a part of their hackathon.
`Querypls` received a shoutout from [🦜 🔗 Langchain](https://www.langchain.com/) on their Twitter in 2023, reaching over **60,000 impressions**. Additionally, it was featured under the **Community Favorite Projects** section on `🦜 🔗 Langchain's blog`, leading to a significant increase in stars for this repository and a growing user base. The project was also highlighted in a [YouTube video](https://www.youtube.com/watch?v=htHVb-fK9xU), and it also caught the attention of Backdrop, expressing their interest and liking in an email, inviting the project to be a part of their hackathon.

However, due to constant breakdowns and instability issues with the LangChain framework, we made the strategic decision to migrate to **Pydantic AI** - a more stable and reliable framework. This transition has brought improved performance, better type safety, and enhanced maintainability to the project.

| [🔗 Langhchain Twitter Post](https://twitter.com/LangChainAI/status/1729959981523378297?t=Zdpw9ZQYvE3QS-3Bf-xaGw&s=19) | [🔗 Langhcain Blog Post](https://blog.langchain.dev/week-of-11-27-langchain-release-notes/) |
|----------|----------|
Expand All @@ -38,7 +45,7 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file


> [!Note]
> Querypls, while powered by a 7B model of Satablility AI LLM Model, is currently limited in providing optimal responses for simple queries.
> Querypls is now powered by OpenAI's GPT-OSS-120B model through Groq, providing fast and reliable AI-powered SQL generation and CSV analysis capabilities.

---

Expand All @@ -59,11 +66,11 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
pip install -r requirements.txt
```

4. Create a `.env` file based on `.env_example` and set the necessary variables.
4. Create a `.env` file based on `.env_examp` and set the necessary variables.

5. Run the application:
```bash
streamlit run src/app.py
streamlit run src/frontend/app.py
```

6. Open the provided link in your browser to use Querypls.
Expand Down
193 changes: 193 additions & 0 deletions examples/basic_usage_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
#!/usr/bin/env python3
"""
Basic usage demo for Querypls backend functionality.
Demonstrates conversation, SQL generation, and CSV analysis.
"""

import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from src.services.routing_service import IntelligentRoutingService
from src.backend.orchestrator import BackendOrchestrator
from src.schemas.requests import NewChatRequest


def demo_conversation():
"""Demo conversation functionality."""
print("🗣️ CONVERSATION DEMO")
print("=" * 40)

routing_service = IntelligentRoutingService()

# Test different conversation types
conversations = [
"Hello",
"How are you?",
"What can you do?",
"Thanks for your help",
"Goodbye",
]

for query in conversations:
print(f"\nUser: {query}")
response = routing_service.handle_conversation_query(query)
print(f"Assistant: {response}")

print("\n" + "=" * 40)


def demo_sql_generation():
"""Demo SQL generation functionality."""
print("🗃️ SQL GENERATION DEMO")
print("=" * 40)

routing_service = IntelligentRoutingService()

# Test different SQL queries
sql_queries = [
"Show me all users",
"Find customers who made purchases in the last 30 days",
"Get the total sales by month",
"SELECT * FROM users WHERE status = 'active'",
]

for query in sql_queries:
print(f"\nUser: {query}")
response = routing_service.handle_sql_query(query, [])
print(f"Assistant: {response[:200]}...")

print("\n" + "=" * 40)


def demo_csv_analysis():
"""Demo CSV analysis functionality."""
print("📊 CSV ANALYSIS DEMO")
print("=" * 40)

# Sample CSV data
sample_csv = """name,age,salary,department
Alice,25,50000,IT
Bob,30,60000,HR
Charlie,35,70000,IT
Diana,28,55000,Finance
Eve,32,65000,HR"""

print(f"Sample CSV Data:\n{sample_csv}")

routing_service = IntelligentRoutingService()

# Test different CSV analysis queries
csv_queries = [
"Show me the basic statistics of the data",
"Create a bar chart of department distribution",
"What is the average salary by department?",
"Show me the top 3 highest paid employees",
]

for query in csv_queries:
print(f"\nUser: {query}")
response = routing_service.handle_csv_query(query, sample_csv)
print(f"Assistant: {response[:300]}...")

print("\n" + "=" * 40)


def demo_intelligent_routing():
"""Demo intelligent routing functionality."""
print("🧠 INTELLIGENT ROUTING DEMO")
print("=" * 40)

routing_service = IntelligentRoutingService()

# Test different types of queries
test_queries = [
("Hello", "CONVERSATION_AGENT"),
("Show me all users", "SQL_AGENT"),
("Analyze this CSV data", "CSV_AGENT"),
("How are you?", "CONVERSATION_AGENT"),
("SELECT * FROM users", "SQL_AGENT"),
("Create a chart from the data", "CSV_AGENT"),
]

for query, expected_agent in test_queries:
print(f"\nQuery: '{query}'")
decision = routing_service.determine_agent(query, [], csv_loaded=True)
print(f"Expected: {expected_agent}")
print(f"Actual: {decision.agent}")
print(f"Confidence: {decision.confidence}")
print(f"Reasoning: {decision.reasoning}")

print("\n" + "=" * 40)


def demo_orchestrator():
"""Demo the main orchestrator functionality."""
print("🎼 ORCHESTRATOR DEMO")
print("=" * 40)

orchestrator = BackendOrchestrator()

# Create a new session
session_info = orchestrator.create_new_session(
NewChatRequest(session_name="Demo Session")
)
session_id = session_info.session_id
print(f"Created session: {session_id}")

# Test different types of interactions
interactions = [
("Hello", "conversation"),
("Show me all users", "sql"),
("What can you do?", "conversation"),
]

for query, query_type in interactions:
print(f"\nUser ({query_type}): {query}")
response = orchestrator.generate_intelligent_response(session_id, query)
print(f"Assistant: {response.content[:150]}...")

# Test CSV functionality
sample_csv = "name,age,salary\nAlice,25,50000\nBob,30,60000\nCharlie,35,70000"
result = orchestrator.load_csv_data(session_id, sample_csv)
print(f"\nCSV Load Result: {result['status']}")

response = orchestrator.generate_intelligent_response(
session_id, "Analyze this data"
)
print(f"CSV Analysis: {response.content[:200]}...")

print("\n" + "=" * 40)


def main():
"""Run all demos."""
print("🚀 Querypls Backend Functionality Demo")
print("=" * 50)

demos = [
("Conversation", demo_conversation),
("SQL Generation", demo_sql_generation),
("CSV Analysis", demo_csv_analysis),
("Intelligent Routing", demo_intelligent_routing),
("Orchestrator", demo_orchestrator),
]

for demo_name, demo_func in demos:
try:
demo_func()
except Exception as e:
print(f"❌ {demo_name} demo failed: {str(e)}")

print("\n🎉 Demo completed! All backend functionality is working correctly.")
print("\n📝 Summary:")
print("- Conversation: Natural responses for greetings and help")
print("- SQL Generation: Convert natural language to SQL queries")
print("- CSV Analysis: Analyze CSV data with Python code")
print("- Intelligent Routing: Automatically choose the right agent")
print("- Orchestrator: Complete session management")


if __name__ == "__main__":
main()
Loading
Loading