# {{name}} - Interactive Streaming Chat

{{description}}

## Overview

This project provides an interactive streaming chat interface for the RAG assistant `{{name}}`. Responses stream in real-time for a better user experience.

## Prerequisites

1. **PyGEAI installed and configured:**
   ```bash
   pip install pygeai
   geai configure --key YOUR_API_KEY --url YOUR_API_URL
   ```

2. **RAG assistant must exist:**
   The assistant `{{name}}` should already be created with documents uploaded.
   
   If not, create it first:
   ```bash
   # Use rag-basic template to create assistant
   geai generate create --template rag-basic --output ./my-rag --name {{name}}
   cd my-rag
   python create_{{name}}.py
   python upload_sample.py
   ```

## Usage

Run the interactive chat:

```bash
python chat_{{name}}.py
```

**Features:**
- ✨ Real-time streaming responses
- 💬 Conversation history maintained
- 🔍 Document-grounded answers
- ⌨️ Simple text interface

**Commands:**
- Type your question and press Enter
- Type `quit`, `exit`, or `q` to end the session
- Press `Ctrl+C` to interrupt

## Example Session

```
💬 Interactive Chat with RAG Assistant: {{name}}
============================================================
Type your questions (or 'quit' to exit)
============================================================

You: What is this document about?

{{name}}: Based on the uploaded documents, this appears to be...

You: Tell me more about the key findings

{{name}}: The key findings include...

You: quit

Goodbye! 👋
```

## Customization

### Modify LLM Settings

Edit `chat_{{name}}.py` to adjust temperature, max tokens, etc:

```python
from pygeai.chat.settings import LLM_SETTINGS

# Override settings
custom_settings = {
    **LLM_SETTINGS,
    "temperature": 0.5,
    "max_tokens": 1000
}

response_stream = client.chat_completion(
    model=f"saia:search:{assistant_name}",
    messages=messages,
    stream=True,
    **custom_settings
)
```

### Add System Prompt

Prepend a system message to guide the assistant:

```python
messages = [{
    "role": "system",
    "content": "You are a helpful assistant. Be concise and accurate."
}]
```

### Disable Streaming

To get complete responses instead of streaming:

```python
response = client.chat_completion(
    model=f"saia:search:{assistant_name}",
    messages=messages,
    stream=False,
    **LLM_SETTINGS
)

answer = response['choices'][0]['message']['content']
print(f"\n{assistant_name}: {answer}\n")
```

## Troubleshooting

**Assistant not found:**
```
❌ Error: Unable to communicate with specified search assistant {{name}}
```
→ Verify the assistant exists: `geai assistants list`

**No documents:**
If the assistant has no documents, responses won't be grounded. Upload documents first.

**API errors:**
Check your configuration: `geai config show`

## Next Steps

- Add file upload capability for dynamic document ingestion
- Implement conversation export
- Add web UI (use chat-web-ui template)
- Integrate with Slack/Discord bots

## Documentation

- [PyGEAI RAG Documentation](https://pygeai.readthedocs.io/)
- [Chat Client API](https://pygeai.readthedocs.io/en/latest/chat/)
