Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@linmx0130
Copy link
Owner

Changes to nah_chat:

  • Add ChatMessageContentValue, and TypedChatMessageContent to support image contents.
  • Add non-streaming chat_completion API.
  • Bump version code to 0.6.0
  • Add an example program.

- Replaced plain `String` content in `ChatMessage` with a new `ChatMessageContentValue` enum that can hold either simple text or typed content (text + image URL).
- Added `TypedChatMessageContent` and `URLObject` structs to represent image payloads.
- Updated every construction site (system, user, tool messages) to wrap text in `ChatMessageContentValue::Text`.
- Adjusted chunk-accumulation logic so only text variants can be appended.
- Added serde round-trip tests for both text and image-url forms.
- Bumped `nah_chat` crate to 0.6.0 and fixed a clippy warning (`choices_arr.get(0)` → `choices_arr.first()`).
- Add `tokio` dev-dependency so examples can run.
- Create `examples/calorie.rs` that streams a vision request: it sends an image URL plus a prompt asking for calorie estimation and prints the response.
- Extend `TypedChatMessageContent` with convenience constructors `text_content` and `image_url_content`.
- Change `ChatMessageContentValue::TypedContent` to `TypedContentList`, now holding a vector, and update `Display` to concatenate all parts.
- Add `ChatMessage::user_text_message` helper for quick text-only user messages.
- Wraps the single image_url content block in an array to match the new
  TypedContentList format
- Adjusts the assertion to compare against a vec![...] instead of a lone
  TypedChatMessageContent
- Introduced `chat_completion()` that returns a single `ChatMessage` instead of a stream.
- Removed streaming logic from `examples/calorie.rs` and switched to the new method.
- Dropped unused `futures_util` imports from the example.
Rewrote non streaming response parser to use mutable `Value` manipulation (`remove`, `as_array_mut`, `as_object_mut`) instead of chained immutable accessors, avoiding unnecessary clones.

Nit change:
- Replaced commented-out `///` doc line with proper `//!` crate-level doc.
- Removed unused `use reqwest;` import in error module.
- Simplified `Error::cause` implementation by replacing `and_then` with `map`.
- Adopted field-init shorthand (`base_url`, `auth_token`) in `ChatClient::init`.
@linmx0130 linmx0130 merged commit 55f68f1 into main Oct 19, 2025
1 check passed
@linmx0130 linmx0130 deleted the image-content-support branch October 19, 2025 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants