import os import requests base_url = os.getenv("OPENAI_BASE_URL", "http://localhost:8000/v1") api_key = os.getenv("OPENAI_API_KEY", "dummy") def chat_stream(): url = f"{base_url}/chat/completions" payload = { "model": "mk-llm", "messages": [ {"role": "system", "content": "Ти си помошник кој зборува на македонски."}, {"role": "user", "content": "Која е историјата на Охрид?"}, ], "stream": True, } headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} with requests.post(url, headers=headers, json=payload, stream=True) as r: for line in r.iter_lines(): if not line: continue if line.startswith(b"data: "): chunk = line[len(b"data: "):] if chunk == b"[DONE]": break print(chunk.decode("utf-8")) if __name__ == "__main__": chat_stream()