Example 4: Basic Streaming
Step 1: Create basic_stream.py
from typing import Iterator
from agno.agent import Agent, RunResponse
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.models.ollama import Ollama
from ollama import Client as OllamaClient
agent = Agent(
model=Ollama(id="llama3.2", client=OllamaClient()),
)
# Get the response in a variable
run_response: Iterator[RunResponse] = agent.run("Share a 2
sentence about Quantum Computing", stream=True)
for chunk in run_response:
print(chunk.content)
# Print the response in the terminal
agent.print_response("Share a 2 sentence about Quantum computing",
stream=True)
Expected Response
Quantum computing is a revolutionary technology that uses the principles of quantum
mechanics to perform calculations exponentially faster than classical computers.
By harnessing qubits and quantum gates, quantum computers can process vast amounts
of information in parallel, leading to breakthroughs in cryptography, optimization,
and simulation.
No comments:
Post a Comment