Skip to content

Conversation

@zhaohb
Copy link
Contributor

@zhaohb zhaohb commented Nov 19, 2025

No description provided.

Copilot AI review requested due to automatic review settings November 19, 2025 05:35
Copilot finished reviewing on behalf of zhaohb November 19, 2025 05:37
Copy link
Contributor

Copilot AI left a 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_history function
  • 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.

@Wovchena Wovchena requested a review from yatarkan November 19, 2025 07:57
Copilot AI review requested due to automatic review settings November 19, 2025 10:16
Copilot finished reviewing on behalf of zhaohb November 19, 2025 10:19
Copy link
Contributor

Copilot AI left a 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);
Copy link
Contributor

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;
Copy link
Contributor

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?

Comment on lines +88 to +94
} 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;
}
Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor

@yatarkan yatarkan Nov 19, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants