Skip to content

Conversation

@yatarkan
Copy link
Contributor

Description

This PR deprecates start_chat() / finish_chat() API in LLM pipeline with respect to ChatHistory usage in generate() method.
It also updates remaining samples to use ChatHistory.

CVS-170885

Checklist:

  • Tests have been updated or added to cover the new code.
  • This patch fully addresses the ticket.
  • I have made corresponding changes to the documentation.

@yatarkan yatarkan requested a review from as-suvorov as a code owner January 22, 2026 14:04
Copilot AI review requested due to automatic review settings January 22, 2026 14:04
@github-actions github-actions bot added category: LLM LLM pipeline (stateful, static) category: Python API Python API for GenAI category: LLM samples GenAI LLM samples category: CPP API Changes in GenAI C++ public headers category: Structured Output samples labels Jan 22, 2026
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 deprecates the start_chat() and finish_chat() API methods in the LLMPipeline in favor of using ChatHistory with the generate() method. Deprecation warnings have been added to both C++ and Python bindings.

Changes:

  • Added deprecation warnings to start_chat() and finish_chat() methods in C++ and Python
  • Updated Python and C++ samples to use ChatHistory instead of the deprecated chat API
  • Migrated structured output generation samples to the new chat history pattern

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/python/py_llm_pipeline.cpp Added deprecation warnings to Python bindings for start_chat() and finish_chat()
src/cpp/src/llm/pipeline.cpp Added deprecation warnings to C++ implementation
src/cpp/include/openvino/genai/llm_pipeline.hpp Added OPENVINO_DEPRECATED macro to method declarations
samples/python/text_generation/structured_output_generation.py Migrated sample to use ChatHistory instead of deprecated chat methods
samples/python/text_generation/structural_tags_generation.py Migrated sample to use ChatHistory instead of deprecated chat methods
samples/cpp/text_generation/structured_output_generation.cpp Migrated C++ sample to use ChatHistory instead of deprecated chat methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +85 to 87
json_response = decoded_results.texts[0]
res = json.loads(json_response)
pipe.finish_chat()
print(f"Generated JSON with item quantities: {json_response}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json_response = decoded_results.texts[0]
res = json.loads(json_response)
pipe.finish_chat()
print(f"Generated JSON with item quantities: {json_response}")
res = json.loads(decoded_results.texts[0])
print(f"Generated JSON with item quantities: {res}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to print model response (not deserialized printed json) as this is compared with JS sample and should be aligned.

Copilot AI review requested due to automatic review settings January 22, 2026 14:29
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 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yatarkan yatarkan requested a review from apaniukov January 22, 2026 14:31
Comment on lines 122 to 141
@@ -134,8 +137,11 @@ def main():
)
)
config.do_sample = True
response = pipe.generate(args.prompt, config, streamer=streamer)
pipe.finish_chat()

history.append({"role": "user", "content": args.prompt})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

History creation can be done outside the loop now, because the system and user prompt is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

history.append({"role": "user", "content": args.prompt})
decoded_results = pipe.generate(history, config, streamer=streamer)
response = decoded_results.texts[0]
history.append({"role": "assistant", "content": response})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
history.append({"role": "assistant", "content": response})

We don't need to add the assistant answer to the history, just parse it for the tool calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I wanted to highlight that user needs to add assistant's response to history manually (and to be aligned with other samples). But can remove if not needed.
And don't we need to clear history in loop iterations here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to modify the history in the loop. The idea is to pass the same history with and without structured output config and compare the outputs, so no modification to the [system, prompt] history is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* @param system_message optional system message.
*/
OPENVINO_DEPRECATED(
"start_chat() / finish_chat() API is deprecated and will be removed in future releases. "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's specify in which release explicitly and create a ticket for removal. @Wovchena should it be 2026.2?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

27.0

Copy link
Contributor Author

@yatarkan yatarkan Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, updated to "in the next major release"

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 15 out of 15 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +44
console.warn(
"DEPRECATION WARNING: startChat() / finishChat() API is deprecated and will be removed in the next major release.",
"Please, use generate() with ChatHistory argument.",
);
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation message is split across two separate string arguments to console.warn(). This will output them as separate items rather than a single cohesive message. Combine them into a single string for better readability.

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +58
console.warn(
"DEPRECATION WARNING: startChat() / finishChat() API is deprecated and will be removed in the next major release.",
"Please, use generate() with ChatHistory argument.",
);
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation message is split across two separate string arguments to console.warn(). This will output them as separate items rather than a single cohesive message. Combine them into a single string for better readability.

Copilot uses AI. Check for mistakes.
std::cout << "\n----------\n"
"> ";
}
pipe.finish_chat();
Copy link
Collaborator

@rkazants rkazants Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we show how to finally use (or can be useful) ChatHistory in a sample when it has been filled after generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this is not the main purpose of this sample. ChatHistory details will be covered in docs and other samples.

Copilot AI review requested due to automatic review settings January 26, 2026 08:29
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 16 out of 16 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +247 to +248
"start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please use generate() with ChatHistory argument.",
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation message should be more consistent across all languages. In C++ and Python the message says 'Please use generate() with ChatHistory argument' but in JavaScript it says 'Please, use generate() with ChatHistory argument' (with a comma after 'Please'). Remove the comma for consistency.

Copilot uses AI. Check for mistakes.
Comment on lines +384 to +390
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}

void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation message should be more consistent across all languages. In C++ and Python the message says 'Please, use generate() with ChatHistory argument' (with a comma after 'Please') but in Python it says 'Please use generate() with ChatHistory argument' (without a comma). Remove the comma for consistency with the Python version.

Suggested change
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
"Please use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please use generate() with ChatHistory argument.");

Copilot uses AI. Check for mistakes.
Comment on lines +384 to +390
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}

void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation message should be more consistent across all languages. In C++ and Python the message says 'Please, use generate() with ChatHistory argument' (with a comma after 'Please') but in Python it says 'Please use generate() with ChatHistory argument' (without a comma). Remove the comma for consistency with the Python version.

Suggested change
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
"Please use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please use generate() with ChatHistory argument.");

Copilot uses AI. Check for mistakes.
pipe.start_chat(sys_message);
ov::genai::ChatHistory chat_history;

chat_history.push_back({{"role", "system"}, {"content", std::move(sys_message)}});
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std::move(sys_message) here prevents sys_message from being used later in the function. While the code works because sys_message is not used after this line, this creates a subtle maintenance issue. Consider using sys_message without std::move for clarity, as the string is relatively small and the optimization is negligible for a one-time system message.

Suggested change
chat_history.push_back({{"role", "system"}, {"content", std::move(sys_message)}});
chat_history.push_back({{"role", "system"}, {"content", sys_message}});

Copilot uses AI. Check for mistakes.

while (std::getline(std::cin, prompt)) {
pipe.generate(prompt, config, streamer);
chat_history.push_back({{"role", "user"}, {"content", std::move(prompt)}});
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std::move(prompt) here invalidates prompt which is still needed for the loop condition std::getline(std::cin, prompt) in the next iteration. While std::getline will overwrite the string, this creates an unnecessary dependency on that behavior. Remove std::move to make the code more robust.

Suggested change
chat_history.push_back({{"role", "user"}, {"content", std::move(prompt)}});
chat_history.push_back({{"role", "user"}, {"content", prompt}});

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings January 27, 2026 04:51
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 17 out of 17 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

async startChat(systemMessage: string = "") {
console.warn(
"DEPRECATION WARNING: startChat() / finishChat() API is deprecated and will be removed in the next major release.",
"Please, use generate() with ChatHistory argument.",
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma after 'Please' is inconsistent with the C++ and Python deprecation messages which use 'Please use' without a comma.

Copilot uses AI. Check for mistakes.
async finishChat() {
console.warn(
"DEPRECATION WARNING: startChat() / finishChat() API is deprecated and will be removed in the next major release.",
"Please, use generate() with ChatHistory argument.",
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma after 'Please' is inconsistent with the C++ and Python deprecation messages which use 'Please use' without a comma.

Copilot uses AI. Check for mistakes.
Comment on lines +392 to +398
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}

void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma after 'Please' is inconsistent with the Python deprecation message and standard English usage.

Suggested change
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
"Please use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please use generate() with ChatHistory argument.");

Copilot uses AI. Check for mistakes.
Comment on lines +392 to +398
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}

void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma after 'Please' is inconsistent with the Python deprecation message and standard English usage.

Suggested change
"Please, use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.");
"Please use generate() with ChatHistory argument.");
m_pimpl->start_chat(system_message);
}
void ov::genai::LLMPipeline::finish_chat() {
GENAI_WARN("start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please use generate() with ChatHistory argument.");

Copilot uses AI. Check for mistakes.
*/
OPENVINO_DEPRECATED(
"start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.")
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma after 'Please' is inconsistent with the Python deprecation message and standard English usage.

Copilot uses AI. Check for mistakes.
*/
OPENVINO_DEPRECATED(
"start_chat() / finish_chat() API is deprecated and will be removed in the next major release. "
"Please, use generate() with ChatHistory argument.")
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra comma after 'Please' is inconsistent with the Python deprecation message and standard English usage.

Copilot uses AI. Check for mistakes.
@Wovchena Wovchena added this pull request to the merge queue Jan 28, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 28, 2026
@yatarkan yatarkan added this pull request to the merge queue Jan 28, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 28, 2026
@yatarkan yatarkan added this pull request to the merge queue Jan 28, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 28, 2026
Copilot AI review requested due to automatic review settings January 28, 2026 21:17
@yatarkan yatarkan enabled auto-merge January 28, 2026 21:17
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 17 out of 17 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

json_strs = pipe.generate(prompt, config)
decoded_results = pipe.generate(history, config)
json_strs = decoded_results.texts[0]
# Validate generated JSON
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment does not add value as the code below (json.loads(json_strs)) is self-explanatory. Consider removing the comment or making it more descriptive about what validation errors are expected or how failures are handled.

Suggested change
# Validate generated JSON
# Validate that the model output is well-formed JSON; this will raise if parsing fails

Copilot uses AI. Check for mistakes.
ov::genai::generation_config(generation_config),
ov::genai::streamer(print_subword));

history.push_back({{"role", "user"}, {"content", std::move(prompt)}});
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std::move on prompt here makes it unavailable for later use. While this works in the current code flow, it could lead to subtle bugs if the code is refactored. Consider whether this optimization is necessary given that prompt is reassigned in the loop anyway.

Copilot uses AI. Check for mistakes.
ov::genai::generation_config(generation_config),
ov::genai::streamer(print_subword));

history.push_back({{"role", "user"}, {"content", std::move(prompt)}});
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std::move on prompt here makes it unavailable for later use. While this works in the current code flow, it could lead to subtle bugs if the code is refactored. Consider whether this optimization is necessary given that prompt is reassigned in the loop anyway.

Copilot uses AI. Check for mistakes.
pipe.start_chat(sys_message);
ov::genai::ChatHistory chat_history;

chat_history.push_back({{"role", "system"}, {"content", std::move(sys_message)}});
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using std::move on sys_message makes it unavailable after this line. This is problematic because if the loop iterates, sys_message would be in an undefined state. Ensure this variable is not used again, or avoid using std::move here.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: CPP API Changes in GenAI C++ public headers category: JS API GenAI JS API category: LLM samples GenAI LLM samples category: LLM LLM pipeline (stateful, static) category: Python API Python API for GenAI category: Structured Output samples category: VLM samples GenAI VLM samples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants