Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for mapping Ollama token usage counts (prompt_eval_count and eval_count) to Genkit's GenerationUsage for both standard and streaming chat/model responses, along with corresponding unit tests. The reviewer suggested optimizing the streaming response parsing by checking for the presence of the "prompt_eval_count" key in the raw JSON chunk before attempting to unmarshal it, which avoids unnecessary JSON parsing overhead on intermediate chunks.
f2b4841 to
196fa87
Compare
|
@jeffdh5 this is done.
Covered the cases from genkit-ai/genkit-python#229: lone |
Message.media and ModelResponse.media now return the first media part, or None, matching JS GenerateResponse.media / Message.media. Document.media stays a list. BREAKING CHANGE: ModelResponse.media is now Media | None instead of list[Media]. Read response.media.url directly; scan message.content to get every media part. Samples, README, and tests are updated. Fixes #6097 Co-authored-by: Cursor <cursoragent@cursor.com>
196fa87 to
13d2937
Compare
|
@jeffdh5 @huangjeff5, could one of you take a look when you have a moment? I rebased this onto current Because this changes |
|
Closing as superseded: Python SDK development has moved to https://github.com/genkit-ai/genkit-python, where singular Message.media / response.media accessors (alongside media_parts) shipped in genkit-ai/genkit-python#47. |
Summary
Add
Message.mediaon the PythonMessagetype so callers can read the image on a message without scanningcontent. The accessor is the first media part, orNone— same shape as JS (message.media.url).AgentResponse.mediais already this (first_media_of).Document.mediastays a list (JSDocument.mediais a list too).Behavior change:
ModelResponse.mediawas alist[Media](empty list whenmessageisNone). It is now first-or-null (Media | None) soresponse.media.urlmatches JSGenerateResponse.media. Anyone iteratingresponse.medianeeds to scancontent(or a futuremedia_parts) instead.Fixes genkit-ai/genkit-python#229
Test plan
MediaPart→message.mediais thatMedia,message.text == ''NoneModelResponse.mediais that first part when a message is present;NonewhenmessageisNoneDocument.mediaremains a list