Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalandi committed Jan 29, 2025
1 parent 408e4a3 commit 0488f3f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion samples/python/text_generation/chat_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
def streamer(subword):
print(subword, end='', flush=True)
# Return flag corresponds whether generation should be stopped.
# False means continue generation.
return openvino_genai.StreamerRunningStatus.RUNNING

def main():
Expand Down
4 changes: 2 additions & 2 deletions samples/python/text_generation/multinomial_causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def get_stop_flag(self):
Checks whether the generation process should be stopped.
Returns:
bool: Always returns False in this implementation.
openvino_genai.StreamerRunningStatus: Always returns RUNNING in this implementation.
"""
return False
return openvino_genai.StreamerRunningStatus.RUNNING

def put_word(self, word: str):
"""
Expand Down
3 changes: 1 addition & 2 deletions samples/python/text_generation/prompt_lookup_decoding_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
def streamer(subword):
print(subword, end='', flush=True)
# Return flag corresponds whether generation should be stopped.
# False means continue generation.
return False
return openvino_genai.StreamerRunningStatus.RUNNING

def main():
parser = argparse.ArgumentParser()
Expand Down
3 changes: 1 addition & 2 deletions samples/python/text_generation/speculative_decoding_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
def streamer(subword):
print(subword, end='', flush=True)
# Return flag corresponds whether generation should be stopped.
# False means continue generation.
return False
return openvino_genai.StreamerRunningStatus.RUNNING

def main():
parser = argparse.ArgumentParser()
Expand Down
1 change: 1 addition & 0 deletions src/cpp/include/openvino/genai/generation_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ GenerationHandleImpl {

bool is_canceled();

OPENVINO_DEPRECATED("Please, use `stop()` instead of `drop()`.")
void drop();

void stop();
Expand Down
4 changes: 3 additions & 1 deletion src/cpp/include/openvino/genai/llm_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
namespace ov {
namespace genai {

// Return flag corresponds whether generation should be stopped: false means continue generation, true means stop.
// Return flag corresponds whether generation should be stopped. It could be:
// ov::genai::StreamerRunningStatus flag, RUNNING means continue generation, STOP means stop generation, CANCEL means stop generation and remove last propmt and answer from history
// *DEPRECATED* bool flag, false means continue generation, true means stop. Please, use `ov::genai::StreamerRunningStatus` instead.
using StreamerVariant = std::variant<std::function<bool(std::string)>, std::function<StreamerRunningStatus(std::string)>, std::shared_ptr<StreamerBase>, std::monostate>;
using OptionalGenerationConfig = std::optional<GenerationConfig>;
using EncodedInputs = std::variant<ov::Tensor, TokenizedInputs>;
Expand Down
8 changes: 6 additions & 2 deletions src/cpp/include/openvino/genai/streamer_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ using CallbackTypeVariant = std::variant<bool, StreamerRunningStatus, std::monos
* @param m_tokenizer tokenizer
*/
class OPENVINO_GENAI_EXPORTS StreamerBase {
public:
protected:
StreamerRunningStatus m_streaming_finish_status = StreamerRunningStatus::RUNNING;

public:
/// @brief put is called every time new token is decoded,
/// @return bool flag to indicate whether generation should be stopped, if return true generation stops
virtual bool put(int64_t token) = 0;

/// @brief end is called at the end of generation. It can be used to flush cache if your own streamer has one
virtual void end() = 0;

StreamerRunningStatus get_streaming_status() {
/// @brief get_streaming_status() is called by the pipline to take more detailed about streaming status. m_streaming_finish_status, which contains streaming status info, could be set in put().
/// @return ov::genai::StreamerRunningStatus to determine the streaming status of generation, whether generation is running, stopped or cancelled
virtual StreamerRunningStatus get_streaming_status() {
return m_streaming_finish_status;
}

Expand Down
1 change: 1 addition & 0 deletions src/cpp/src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Config from_config_json_if_exists(const std::filesystem::path& models_path, cons
return std::filesystem::exists(config_file_path) ? Config{config_file_path} : Config{};
}

OPENVINO_DEPRECATED("Callback streamer with `bool` return value is depricated. Please, use `ov::genai::StreamerRunningStatus` instead.")
ov::genai::StreamerVariant get_streamer_from_map(const ov::AnyMap& config_map);

ov::genai::OptionalGenerationConfig get_config_from_map(const ov::AnyMap& config_map);
Expand Down

0 comments on commit 0488f3f

Please sign in to comment.