Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
archive/

# UV
.uv/
uv.lock

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
23 changes: 23 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Repository Guidelines

## Project Structure & Module Organization
SmartPilot uses a src-layout: `src/smartpilot` contains `main.py` for the pipeline, `prompts.py` for system prompts, and `streamlit_app.py` for the optional UI. Project metadata sits in `pyproject.toml`, and `tests/` holds mirrored suites such as `test_main.py` and `test_prompts.py`. Add fixtures or assets beside the feature they support so imports remain predictable.

## Build, Test, and Development Commands
- `uv sync --extra dev` – install the package plus dev/test dependencies.
- `uv run python -m smartpilot.main` – launch the CLI pipeline locally.
- `uv run streamlit run src/smartpilot/streamlit_app.py` – start the Streamlit UI for demos.
- `uv run pytest` – execute the full asynchronous test suite.
- `smartpilot` – run the published console script once installed.

## Coding Style & Naming Conventions
Write Python 3.10+ with 4-space indents, type hints, and docstrings patterned after `main.py`. Favor `async` coroutines for OpenAI calls, stream batch progress with `tqdm`, and keep helpers small and composable. Use snake_case for identifiers, PascalCase for classes, and uppercase snake case for prompt constants. Stick to local imports and run your formatter/linter before opening a PR.

## Testing Guidelines
Tests rely on `pytest` and `pytest-asyncio`, so name suites `test_*.py` and decorate coroutine cases with `pytest.mark.asyncio`. Mock OpenAI responses; CI must not call the live API. Add regression tests whenever you edit prompts or pipeline stages, keep analyzer/selector coverage with table-driven inputs, and share the `uv run pytest` (or `-k` filtered) output inside your PR.

## Commit & Pull Request Guidelines
Mirror the imperative, sub-60-character subjects used in `git log` (e.g., “Fix OpenAI API to use Chat Completions API”). Each commit should cover one concern, referencing issues when available. Pull requests need a summary, validation notes (tests, CLI runs, Streamlit checks), any config migrations, and screenshots for UI tweaks. Keep secrets such as `OPENAI_API_KEY` in your environment, not in tracked files.

## Security & Configuration Tips
Export `OPENAI_API_KEY` or store it in `.env`; never commit real keys. Review `pyproject.toml` before adding dependencies and prefer extras (like `streamlit`) for optional stacks. Future provider hooks or logging should be controlled by config flags so the CLI runs without extra setup.
135 changes: 119 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,139 @@
# SmartPilot

SmartPilot is a Python program that generates, analyzes, and selects the best answer to a given question. It leverages the power of OpenAI's language model and a series of prompt-engineered AI models to provide high-quality, reliable, and accurate responses.
SmartPilot is an AI-powered question answering system that generates, analyzes, and selects the best answer to a given question. It leverages OpenAI's Chat Completions API with GPT-4 Turbo to provide high-quality, reliable, and accurate responses through a multi-step reasoning pipeline.

## Overview

SmartPilot consists of several steps:
SmartPilot uses a sophisticated pipeline to improve answer quality:

1. Generate multiple initial answers to a question
2. Analyze the strengths and weaknesses of each answer
3. Resolve each answer by addressing its flaws and enhancing its strengths
4. Select the best answer from the resolved answers
1. **Generate**: Creates multiple initial answers using high-temperature sampling for diversity
2. **Analyze**: Evaluates each answer's strengths, weaknesses, and logical consistency
3. **Resolve**: Improves answers by addressing identified flaws and enhancing strengths
4. **Select**: Chooses the best final answer based on accuracy, completeness, and clarity

## Installation

To install the required packages for SmartPilot, run the following command:
`pip install -r requirements.txt`
This project uses [UV](https://github.com/astral-sh/uv) for modern Python package management.

Add your OpenAI API key to the `OPENAI_API_KEY` environment variable or directly in `main.py`.
### Using UV (Recommended)

```bash
# Install UV if not already installed
pip install uv

# Install the project and dependencies
uv sync

# Install with development dependencies (for testing)
uv sync --extra dev

# Install with Streamlit support
uv sync --extra streamlit
```

### Using pip

```bash
pip install -e .

# With development dependencies
pip install -e ".[dev]"

# With Streamlit support
pip install -e ".[streamlit]"
```

## Configuration

Set your OpenAI API key as an environment variable:

```bash
export OPENAI_API_KEY="your-api-key-here"
```

Or create a `.env` file in the project root:

```
OPENAI_API_KEY=your-api-key-here
```

## Usage

To use SmartPilot, run `main.py` in your terminal:
`python main.py`
### Command Line Interface

You will be prompted to enter your question and the number of initial answers you want. After providing the necessary input, the program will generate answers, analyze them, resolve them, and finally select the best answer.
```bash
# Using UV
uv run python -m smartpilot.main

## Credits
# Or using the installed package
smartpilot
```

You will be prompted to enter your question and the number of initial answers to generate.

This program was inspired by the ideas discussed in the AI Explained YouTube Channel's video on SmartGPT(https://youtu.be/wVzuvf9D9BU)
### Streamlit Web Interface

```bash
# Using UV
uv run streamlit run src/smartpilot/streamlit_app.py

# Or using the installed package
streamlit run src/smartpilot/streamlit_app.py
```

### As a Python Library

```python
import asyncio
from smartpilot.main import run_smartpilot

async def main():
result = await run_smartpilot(
question="What is the best way to learn Python?",
n=3 # Number of initial answers to generate
)

print("Best Answer:", result["selected_answer"])

asyncio.run(main())
```

## Development

### Running Tests

```bash
# Using UV
uv run pytest

# With verbose output
uv run pytest -v

# Using pytest directly
pytest tests/
```

### Project Structure

```
smartpilot/
├── src/
│ └── smartpilot/
│ ├── __init__.py
│ ├── main.py # Core pipeline logic
│ ├── prompts.py # System prompts
│ └── streamlit_app.py # Web interface
├── tests/
│ ├── test_main.py
│ └── test_prompts.py
├── pyproject.toml # Project configuration
└── README.md
```

## Credits

Also uses [LangChain](https://github.com/hwchase17/langchain), a Python library for chaining together multiple language models.
This program was inspired by the ideas discussed in the [AI Explained YouTube Channel's video on SmartGPT](https://youtu.be/wVzuvf9D9BU).

## License

This project is licensed under the MIT License. See the [LICENSE](https://chat.openai.com/LICENSE) file for details.
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
Loading