Files
2026-05-24 20:10:14 +00:00

56 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Stream‑режим AI‑агента
This repository contains a minimal implementation of an **AI agent that streams responses** from OpenAI's ChatCompletion API.
## Features
* **Streaming** receive model output tokenbytoken instead of waiting for the full response.
* **Simple API** expose a single `stream_chat` generator that yields text fragments.
* **Example script** quick demo showing how to use the streaming agent.
## Getting Started
1. **Clone the repository**
```bash
git clone https://git.brojs.ru/RK-A/stream-ai-agent-task6.git
cd stream-ai-agent-task6
```
2. **Create a virtual environment** (optional but recommended)
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Set your OpenAI API key**
```bash
export OPENAI_API_KEY=sk-...
```
5. **Run the demo**
```bash
python main.py
```
The demo will stream a short poem about the sea.
## Usage in Your Own Code
```python
from agent_stream import stream_chat
messages = [
{"role": "user", "content": "Tell me a joke."}
]
for token in stream_chat(messages):
print(token, end='', flush=True)
```
## License
MIT © 2026