Metadata-Version: 2.3
Name: shraga-common
Version: 0.6.0
Summary: Common infrastructure for Shraga AI
License: Apache-2.0
Author: Itamar Syn-Hershko
Author-email: itamar@bigdataboutique.com
Requires-Python: >=3.11,<4.0
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: bcrypt (>=4.3.0,<5.0.0)
Requires-Dist: beautifulsoup4 (>=4.13.3,<5.0.0)
Requires-Dist: boto3 (>=1.37.10,<2.0.0)
Requires-Dist: cohere (>=5.15.0,<6.0.0)
Requires-Dist: colorlog (>=6.9.0,<7.0.0)
Requires-Dist: elasticsearch (>=8.14.0,<9.0.0)
Requires-Dist: faiss-cpu (>=1.8.0.post1,<2.0.0)
Requires-Dist: fastapi (>=0.112.0,<0.113.0)
Requires-Dist: geopandas (>=1.0.1,<2.0.0)
Requires-Dist: googlemaps (>=4.10.0,<5.0.0)
Requires-Dist: importlib (>=1.0.4,<2.0.0)
Requires-Dist: jinja2 (>=3.1.6,<4.0.0)
Requires-Dist: langchain (>=0.2.12,<0.3.0)
Requires-Dist: langchain-core (>=0.2.29,<0.3.0)
Requires-Dist: nanoid (>=2.0.0,<3.0.0)
Requires-Dist: openai (==1.57.4)
Requires-Dist: opensearch-py (>=2.6.0,<3.0.0)
Requires-Dist: pandas (>=2.2.2,<3.0.0)
Requires-Dist: pathlib (>=1.0.1,<2.0.0)
Requires-Dist: pydantic (>=2.10.6,<3.0.0)
Requires-Dist: pydash (>=8.0.3,<9.0.0)
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
Requires-Dist: requests (>=2.32.2,<3.0.0)
Requires-Dist: snowflake-connector-python (>=3.11.0,<4.0.0)
Requires-Dist: typing-extensions (>=4.12.2,<5.0.0)
Requires-Dist: user-agents (>=2.2.0,<3.0.0)
Requires-Dist: uvicorn (>=0.30.5,<0.31.0)
Requires-Dist: vertexai (>=1.60.0,<2.0.0)
Description-Content-Type: text/markdown

## Shraga

Shraga is a modern AI application with a backend based on FastAPI and a frontend built with React.

## Installation and Setup

### Requirements

1. Python 3.11 or higher
2. Pip
3. Poetry (for dependency management)
4. Node.js and pnpm (for frontend)

### Backend Setup

First, install Poetry if you don't have it already:

```bash
pipx install poetry
```

Clone the repository and install dependencies:

```bash
git clone <repository-url>
cd shraga
poetry install --no-root
poetry run pre-commit install
```

To activate the virtual environment:

```bash
poetry shell
which python  # Verify the correct Python interpreter is being used
```

## Development Tools

Several command-line tools are included with this package to help with development and management tasks:

### User Management

```bash
# Create a user with basic authentication (interactive mode)
poetry run create-basic-auth-user

# Create a user with command-line arguments
poetry run create-basic-auth-user <email> <password> <config_file>

# Example
poetry run create-basic-auth-user user@example.com mypassword123 config.demo.yaml
```
This tool will:
- Prompt you to enter a user email address (with validation)
- Securely collect and validate a password
- Ask for the configuration file to update
- Generate a bcrypt hash of the password
- Save the credentials to a text file for reference
- Update the specified configuration file with the new user

## Running the Application

### Backend

To run the backend server with hot-reloading enabled:

```bash
SHRAGA_FLOWS_PATH=flows CONFIG_PATH=config.demo.yaml uvicorn main:app --reload
```

### Frontend

To run the frontend development server:

```bash
cd frontend
pnpm install  # Only needed first time or when dependencies change
pnpm run dev
```

By default, the frontend will be available at http://localhost:5000 and will connect to the backend API running on http://localhost:8000.

## Configuration

Shraga uses YAML configuration files to manage its settings. The repository includes:

- `config.example.yaml`: A template configuration file with documentation

You can specify which configuration file to use with the `CONFIG_PATH` environment variable.

## Demo Flow

To run the demo flow without requiring an LLM, Elasticsearch, or Opensearch:

1. Use the demo configuration file:
   ```bash
   export CONFIG_PATH=config.demo.yaml
   ```

2. Run the backend with the demo flows:
   ```bash
   export SHRAGA_FLOWS_PATH=flows
   uvicorn main:app --reload
   ```

## Project Structure

- `/shraga_common`: Core library with reusable components
- `/scripts`: Command-line utilities and helper scripts
- `/frontend`: React-based web interface
- `/flows`: Flow definitions for different use cases
- `/terraform`: Infrastructure as code for deployment

### Code Style

This project uses pre-commit hooks to enforce code style. They're installed with:

```bash
poetry run pre-commit install
```

## Report API

For generating chat reports use `/api/report/export` endpoint with params:

```
report_type=history
start="YYYY-MM-DD HH:MM:SS" (Optional)
end="YYYY-MM-DD HH:MM:SS" (Optional)
user_id (Optional)
user_org (Optional)
```

The endpoint is available for users with `analytics` permission and `history` has to be enabled in config.yaml.
Analytics permission can be created in config.yaml:

```
history:
   enabled: true
   analytics: 
     domains:
       - domain.ltd
```

OR

```
history:
   enabled: true
   analytics: 
      users:
         - username_from_auth.users
```


Example:

```bash
curl -X POST "http://localhost:8000/api/report/export" \
  -H "Content-Type: application/json" \
  -H "Authorization: Basic YOUR_TOKEN_HERE" \
  -d '{
    "report_type": "history",
    "start": "2025-04-01 00:00:00",
    "end": "2025-06-01 00:00:00",
    "user_id": "user@domain.ltd",
    "user_org": "company_name",
  }'
```


## License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


