Skip to content

Commit 1a2213f

Browse files
committed
litellm
1 parent 4dbc9eb commit 1a2213f

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

.githooks/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22
set -e
33
uv run ruff check .
4-
uv run ruff format --check .
4+
uv run ruff format --check . || { echo "Run 'uv run ruff format .' to fix formatting."; exit 1; }
55
uv run pytest -m "not e2e" -q

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ the `ctx.entry` dict.
2323

2424
## LLM skill
2525

26-
Self-contained with a fake model so the snippet runs as-is:
27-
2826
```python
27+
from litellm import completion
2928
from tk.llmbda import Skill, SkillContext, StepResult, lm, run_skill
3029

31-
def fake_model(*, messages, **_):
32-
return "2025-01-15"
30+
def call_lm(*, messages, **kw):
31+
resp = completion(model="gpt-4o-mini", messages=messages, **kw)
32+
return resp.choices[0].message.content
3333

34-
@lm(fake_model, system_prompt="Extract a date. Return ISO format.")
34+
@lm(call_lm, system_prompt="Extract a date. Return ISO format.")
3535
def extract_date(ctx: SkillContext, call) -> StepResult:
3636
"""Extract a date from natural language."""
3737
raw = call(messages=[{"role": "user", "content": ctx.entry["text"]}])
38-
return StepResult(value=raw)
38+
return StepResult(value=raw.strip())
3939

4040
skill = Skill(name="dates", steps=[Skill("extract", fn=extract_date)])
4141
result = run_skill(skill, text="let's meet on the 15th of January 2025")

examples/calendar_booking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def parse_topic(ctx: SkillContext) -> StepResult:
106106
# ## Scripted caller
107107
#
108108
# Defined before the LLM step so `@lm(...)` can capture it at decoration time.
109-
# Real usage swaps this for an OpenAI-style caller (see README).
109+
# Real usage swaps this for a litellm caller (see README).
110110

111111
# %%
112112
_CANNED = {
@@ -144,7 +144,7 @@ def parse_topic(ctx: SkillContext) -> StepResult:
144144

145145

146146
def scripted_caller(*, messages: list[dict[str, str]], **_kw: object) -> str:
147-
"""Pretend to be an OpenAI caller; returns a JSON string."""
147+
"""Scripted LMCaller for examples; returns a JSON string."""
148148
user_msg = messages[1]["content"]
149149
for key, payload in _CANNED.items():
150150
if key in user_msg:

examples/support_triage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def _read_json_user_message(messages: list[dict[str, str]]) -> dict[str, Any]:
174174

175175

176176
def scripted_support_model(*, messages: list[dict[str, str]], **_kw: Any) -> str:
177-
"""OpenAI-shaped deterministic caller for examples."""
177+
"""Scripted LMCaller for examples."""
178178
system = (
179179
messages[0]["content"].lower()
180180
if messages and messages[0]["role"] == "system"

0 commit comments

Comments
 (0)