Here are practical examples showing how to use donew for common scenarios.
Strawberry - Everyones favorite
from donew import DO
from pydantic import BaseModel, Field
from donew.new import LiteLLMModel
class Answer(BaseModel):
word: str = Field(description="The word to check")
count: int = Field(description="The answer number")
doer = DO.New(model=LiteLLMModel(model_id="ollama/qwen2.5-coder:3b")})
result = doer.envision(Answer).enact("how many r's are in the word strawberry?")
assert result.count == 3
print(result)
We deliberately chose a small 3b model here to show that donew can solve problems that are known to be hard for many LLMs.
Complex knowledge and counting - Strawberry++
from donew import DO
from pydantic import BaseModel, Field
from donew.new import LiteLLMModel
class Countries(BaseModel):
countries: List[str] = Field(description="The list of countries whose names begin with 'B' and do not contain the letter 'E'. The names are sorted and each starts with a capital letter.")
doer = DO.New(model=LiteLLMModel(model_id="ollama/qwen2.5-coder:3b"))
result = doer.envision(Countries).enact("fullfill the task")
reference_list = ["Bahamas", "Bahrain", "Barbados", "Bhutan", "Bolivia", "Botswana", "Brazil", "Bulgaria", "Burkina Faso", "Burundi"]
assert result.countries == reference_list
print(result)
API-use example - Get the weather in a city
from donew import DO
from pydantic import BaseModel, Field
from donew.new import LiteLLMModel
class WeatherData(BaseModel):
"""Current weather information"""
temperature: float = Field(description="Current temperature in Celsius")
conditions: str = Field(description="Current weather conditions (e.g., sunny, rainy)")
humidity: Optional[float] = Field(description="Current humidity percentage")
wind_speed: Optional[float] = Field(description="Current wind speed in km/h")
doer = DO.New(
model = LiteLLMModel(model_id="gpt-4o") # use e.g. from dotenv import load_dotenv
)
result = doer.realm([BROWSE]).envision(WeatherData).enact(
"Get the current weather for the given parameters",
city="Berlin, Germany"
)
assert isinstance(result, WeatherData)
assert result.temperature is not None # Ensure we got a temperature
print(result.model_dump_json(indent=2))
return result