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

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

    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)

    python -m venv venv
    source venv/bin/activate   # On Windows: venv\Scripts\activate
    
  3. Install dependencies

    pip install -r requirements.txt
    
  4. Set your OpenAI API key

    export OPENAI_API_KEY=sk-...
    
  5. Run the demo

    python main.py
    

The demo will stream a short poem about the sea.

Usage in Your Own Code

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

S
Description
Stream-режим AI-агента Task 6
Readme 26 KiB
Languages
Python 100%