Async Basic Stream.Py

Code

1import asyncio
2
3from kern.agent import Agent
4from kern.models.huggingface import HuggingFace
5
6agent = Agent(
7 model=HuggingFace(
8 id="mistralai/Mistral-7B-Instruct-v0.2", max_tokens=4096, temperature=0
9 ),
10)
11asyncio.run(
12 agent.aprint_response(
13 "What is meaning of life and then recommend 5 best books to read about it",
14 stream=True,
15 )
16)

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export HF_TOKEN=xxx

Install dependencies

1uv pip install -U huggingface_hub kern-ai

Run Agent

1python cookbook/11_models/huggingface/async_basic_stream.py