Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fastllm/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def norm_parts(resp):

# %% ../nbs/04_anthropic.ipynb #a3869e31
def norm_sse_event(ev, **kwargs):
ev = obj2dict(ev)
typ = ev.get("type")
text, thinking, tcs, citations = None, None, [], None
if typ == "content_block_start":
Expand Down
1 change: 1 addition & 0 deletions fastllm/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def norm_parts(resp):
# %% ../nbs/05_gemini.ipynb #9a5024ee
def norm_sse_event(ev, **kwargs):
"Normalize Gemini stream event into Delta."
ev = obj2dict(ev)
cand = nested_idx(ev, 'candidates', 0) or {}
finish_reason = norm_finish(ev)
parts = nested_idx(cand, 'content', 'parts') or []
Expand Down
1 change: 1 addition & 0 deletions fastllm/openai_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def norm_parts(resp):
def norm_sse_event(ev, **kwargs):
"Normalize a chat completion stream event."
# usage always arrives as a single final event with choices: []
ev = obj2dict(ev)
fin = nested_idx(ev, 'choices', 0, 'finish_reason')
tcs = norm_tool_calls(ev, delta=True)
if (dlt:=nested_idx(ev, 'choices', 0, 'delta')) is not None:
Expand Down
1 change: 1 addition & 0 deletions fastllm/openai_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def norm_parts(resp):
# %% ../nbs/02_oai_responses.ipynb #7cd48aa5
def norm_sse_event(ev, **kwargs):
"Normalize OpenAI Responses API stream event into Delta."
ev = obj2dict(ev)
typ = ev.get("type")
if typ == "response.output_text.delta": return Delta(text=ev.get("delta"), raw=ev, **kwargs)
if typ == "response.reasoning_text.delta": return Delta(thinking=ev.get("delta",""), raw=ev, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion fastllm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def register(self, name, finalize_usage=noop, **kwargs): self.apis[name] = Simpl
# %% ../nbs/00_types.ipynb #d58a5f96
def mk_completion(resp, model, api_name, vendor_name):
"Normalize an api response into Completion."
resp = obj2dict(resp)
api = api_registry.apis[api_name]
tcs = api.norm_tool_calls(resp)
parts = api.norm_parts(resp)
Expand Down Expand Up @@ -277,7 +278,7 @@ def get_model_meta(model, vendor_name=None, tfm=noop):
if model in mp: key = model
elif vendor_name=='gemini' and model.startswith('models/'): key = f"gemini/{model.removeprefix('models/')}"
elif vendor_name: key = f"{vendor_name}/{model}"
return dict2obj(tfm(mp.get(key), model, vendor_name))
return dict2obj(tfm(mp.get(key, {}), model, vendor_name))

# %% ../nbs/00_types.ipynb #60607e23
haik45 = "claude-haiku-4-5"
Expand Down
29 changes: 28 additions & 1 deletion nbs/00_types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@
"#| export\n",
"def mk_completion(resp, model, api_name, vendor_name):\n",
" \"Normalize an api response into Completion.\"\n",
" resp = obj2dict(resp)\n",
" api = api_registry.apis[api_name]\n",
" tcs = api.norm_tool_calls(resp)\n",
" parts = api.norm_parts(resp)\n",
Expand Down Expand Up @@ -1015,7 +1016,7 @@
" if model in mp: key = model\n",
" elif vendor_name=='gemini' and model.startswith('models/'): key = f\"gemini/{model.removeprefix('models/')}\"\n",
" elif vendor_name: key = f\"{vendor_name}/{model}\"\n",
" return dict2obj(tfm(mp.get(key), model, vendor_name))"
" return dict2obj(tfm(mp.get(key, {}), model, vendor_name))"
]
},
{
Expand Down Expand Up @@ -1148,6 +1149,32 @@
" supports_vision=True, supports_image_input=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68ae64b7",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ERROR:root:No traceback has been produced, nothing to debug.\n"
]
}
],
"source": [
"%debug"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dea5e0cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
18 changes: 2 additions & 16 deletions nbs/02_oai_responses.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,7 @@
"execution_count": null,
"id": "1f198e96",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[92m16:32:22 - LiteLLM:WARNING\u001b[0m: common_utils.py:979 - litellm: could not pre-load bedrock-runtime response stream shape — Bedrock event-stream decoding will be unavailable. Error: No module named 'botocore'\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[92m16:32:23 - LiteLLM:WARNING\u001b[0m: common_utils.py:24 - litellm: could not pre-load sagemaker-runtime response stream shape — SageMaker event-stream decoding will be unavailable. Error: No module named 'botocore'\n"
]
}
],
"outputs": [],
"source": [
"enable_cachy(hdrs=('content-type',))"
]
Expand Down Expand Up @@ -791,6 +776,7 @@
"#| export\n",
"def norm_sse_event(ev, **kwargs):\n",
" \"Normalize OpenAI Responses API stream event into Delta.\"\n",
" ev = obj2dict(ev)\n",
" typ = ev.get(\"type\")\n",
" if typ == \"response.output_text.delta\": return Delta(text=ev.get(\"delta\"), raw=ev, **kwargs)\n",
" if typ == \"response.reasoning_text.delta\": return Delta(thinking=ev.get(\"delta\",\"\"), raw=ev, **kwargs)\n",
Expand Down
1 change: 1 addition & 0 deletions nbs/03_oai_chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@
"def norm_sse_event(ev, **kwargs):\n",
" \"Normalize a chat completion stream event.\"\n",
" # usage always arrives as a single final event with choices: []\n",
" ev = obj2dict(ev)\n",
" fin = nested_idx(ev, 'choices', 0, 'finish_reason')\n",
" tcs = norm_tool_calls(ev, delta=True)\n",
" if (dlt:=nested_idx(ev, 'choices', 0, 'delta')) is not None:\n",
Expand Down
1 change: 1 addition & 0 deletions nbs/04_anthropic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@
"source": [
"#| export\n",
"def norm_sse_event(ev, **kwargs):\n",
" ev = obj2dict(ev)\n",
" typ = ev.get(\"type\")\n",
" text, thinking, tcs, citations = None, None, [], None\n",
" if typ == \"content_block_start\":\n",
Expand Down
1 change: 1 addition & 0 deletions nbs/05_gemini.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@
"#| export\n",
"def norm_sse_event(ev, **kwargs):\n",
" \"Normalize Gemini stream event into Delta.\"\n",
" ev = obj2dict(ev)\n",
" cand = nested_idx(ev, 'candidates', 0) or {}\n",
" finish_reason = norm_finish(ev)\n",
" parts = nested_idx(cand, 'content', 'parts') or []\n",
Expand Down