-
Notifications
You must be signed in to change notification settings - Fork 302
Update C chat samples with using ChatHistory class #3045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a C API wrapper for the ChatHistory class and updates chat samples to use it. The implementation provides a JSON-based interface for managing chat conversations, replacing the previous start_chat/finish_chat approach with explicit history management.
Key changes:
- Added comprehensive ChatHistory C API with create, manipulate, and query operations
- Integrated ChatHistory with LLM pipeline via new
generate_with_historyfunction - Updated chat sample to build and manage conversation history explicitly using JSON messages
Reviewed Changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/c/include/openvino/genai/c/chat_history.h | New public C API header defining ChatHistory interface with 14 functions for history management |
| src/c/include/openvino/genai/c/llm_pipeline.h | Added generate_with_history function to support ChatHistory-based generation |
| src/c/src/types_c.h | Added opaque type definition for ChatHistory wrapper |
| src/c/src/chat_history.cpp | New implementation file with full ChatHistory C wrapper implementation |
| src/c/src/llm_pipeline.cpp | Implemented generate_with_history function with streaming support |
| samples/c/text_generation/chat_sample_c.c | Refactored to use ChatHistory API with JSON message formatting |
| samples/c/text_generation/greedy_causal_lm_c.c | Formatting fix (closing brace) |
| samples/c/text_generation/benchmark_genai_c.c | Formatting fix (closing brace) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| */ | ||
| OPENVINO_GENAI_C_EXPORTS ov_genai_chat_history_status_e ov_genai_chat_history_create_from_json( | ||
| const char* messages_json, | ||
| ov_genai_chat_history** history); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other functions have ov_genai_chat_history param in the first place - let's align
| } | ||
| history->object->pop_back(); | ||
| } catch (const ov::Exception& e) { | ||
| return OV_GENAI_CHAT_HISTORY_EMPTY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why reported status for ov::Exception is empty, not error?
| } catch (const ov::Exception& e) { | ||
| return OV_GENAI_CHAT_HISTORY_EMPTY; | ||
| } catch (const std::exception& e) { | ||
| return OV_GENAI_CHAT_HISTORY_ERROR; | ||
| } catch (...) { | ||
| return OV_GENAI_CHAT_HISTORY_ERROR; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why different catch blocks are needed if all of them return the same error status?
| _history->object = std::make_shared<ov::genai::ChatHistory>(messages); | ||
| *history = _history.release(); | ||
| } catch (const ov::Exception& e) { | ||
| return OV_GENAI_CHAT_HISTORY_INVALID_JSON; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also return error status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In C++ ChatHistory mainly works with JsonContainer instances. I think in C we should also expose JsonContainer and use it in C implementation for ChatHistory.
No description provided.