@@ -54,6 +54,14 @@ class OPENVINO_GENAI_EXPORTS VLMPipeline {
54
54
std::string m_templated_chat_history;
55
55
size_t image_id = 0 ; // Used to insert <image_id>i</image_id> per image (not a slice).
56
56
57
+ // / @brief Construct a pipeline form a folder containing tokenizer
58
+ // / and model IRs.
59
+ // / @param model_dir A folder to read tokenizer and model IRs.
60
+ // / @param device Inference device. A tokenizer is always compiled
61
+ // / for CPU.
62
+ // / @param device_config A config to pass to ov::Core.set_property()
63
+ // / and ov::Core::compile_model().
64
+ // / @param core ov::Core instance to use.
57
65
explicit VLMPipeline (
58
66
const std::filesystem::path& model_dir,
59
67
const std::string& device=" CPU" ,
@@ -67,6 +75,14 @@ class OPENVINO_GENAI_EXPORTS VLMPipeline {
67
75
core
68
76
} {}
69
77
78
+ // / @brief Construct a pipeline form a folder containing model IRs
79
+ // / and from a Tokenizer instance.
80
+ // / @param model_dir A folder to read model IRs.
81
+ // / @param tokenizer An instance of Tokenizer to use.
82
+ // / @param device Inference device.
83
+ // / @param device_config A config to pass to ov::Core.set_property()
84
+ // / and ov::Core::compile_model().
85
+ // / @param core ov::Core instance to use.
70
86
VLMPipeline (
71
87
const std::filesystem::path& model_dir,
72
88
const ov::genai::Tokenizer& tokenizer,
@@ -78,16 +94,37 @@ class OPENVINO_GENAI_EXPORTS VLMPipeline {
78
94
// / @brief Default destructor.
79
95
~VLMPipeline ();
80
96
97
+ // / @brief Generate a response given a prompt and any number of
98
+ // / uint8 RGB images.
99
+ // / @param prompt A prompt to respond to.
100
+ // / @param images Images to be prepended to a prompt.
101
+ // / @param generation_config A config to follow for text generation.
102
+ // / @param streamer A streamer to acquire intermidiate result.
103
+ // / @return A string generated by a model.
81
104
DecodedResults generate (
82
105
const std::string& prompt,
83
- const std::vector<ov::Tensor>& images ,
106
+ const std::vector<ov::Tensor>& rgbs ,
84
107
const GenerationConfig& generation_config,
85
108
const StreamerVariant& streamer
86
109
);
110
+ // / @brief Generate a response given a prompt and config.
111
+ // / @param prompt A prompt to respond to.
112
+ // / @param config_map A config may contain GenerationConfig, values
113
+ // / for its members, StreamerVariant a single image or multiple
114
+ // / images.
115
+ // / @return A string generated by a model.
87
116
DecodedResults generate (
88
117
const std::string& prompt,
89
118
const ov::AnyMap& config_map
90
119
);
120
+ // / @brief Generate a response given a prompt and arbitrary number
121
+ // / of ov::Property instances.
122
+ // / Example:
123
+ // / generate("text", image(std::move(rgb)), do_sample(true));
124
+ // / @param prompt A prompt to respond to.
125
+ // / @param ...properties ov::Property instances to be combined into
126
+ // / ov::AnyMap.
127
+ // / @return A string generated by a model.
91
128
template <typename ... Properties>
92
129
util::EnableIfAllStringAny<DecodedResults, Properties...> generate (
93
130
const std::string& prompt,
@@ -97,9 +134,30 @@ class OPENVINO_GENAI_EXPORTS VLMPipeline {
97
134
prompt, AnyMap{std::forward<Properties>(properties)...}
98
135
);
99
136
}
137
+ // / @brief Activate chat mode. Chat preserves previous history and
138
+ // / applies chat_template to input prompts. Calling start_chat()
139
+ // / again or finish_chat() drops the memorized history.
140
+ // / It's possible to disable
141
+ // / chat_template application by calling
142
+ // / set_chat_template("{% for message in messages %}{{ message['content'] }}{% endfor %}")
143
+ // / @param system_message Some chat_templates contain system role
144
+ // / in addition to user and assistant roles. Set a message for that
145
+ // / role.
100
146
void start_chat (const std::string& system_message=" " );
147
+ // / @brief Deactivate chat mode.
101
148
void finish_chat () {m_is_chat_conversation = false ;}
149
+ // / @brief Set a custom chat template. Can be used to deactivate
150
+ // / chat_template application for chat mode if called with
151
+ // / "{% for message in messages %}{{ message['content'] }}{% endfor %}"
152
+ // / or workaround unsupported chat_template entries in a default
153
+ // / model chat_template.
154
+ // / @param new_template A new template to override with.
155
+ void set_chat_template (const std::string& new_template);
156
+ // / @brief Extract GenerationConfig used to get default values.
157
+ // / @return Default values used.
102
158
GenerationConfig get_generation_config () const ;
159
+ // / @brief Override default values for GenerationConfig
160
+ // / @param new_config A config to override default values with.
103
161
void set_generation_config (const GenerationConfig& new_config);
104
162
private:
105
163
class VLMPipelineImpl ;
0 commit comments