@@ -124,74 +124,6 @@ VLMMaster::~VLMMaster() {
124124 }
125125}
126126
127- void VLMMaster::handle_request (const std::vector<Message>& messages,
128- const MMInput& mm_inputs,
129- RequestParams sp,
130- OutputCallback callback) {
131- MMData mm_data;
132- if (!mm_inputs.empty () && !image_processor_->process (mm_inputs, mm_data)) {
133- LOG (ERROR) << " image processor process failed" ;
134- }
135-
136- this ->handle_request (messages, mm_data, sp, callback);
137- }
138-
139- void VLMMaster::handle_batch_request (const std::vector<std::string>& prompts,
140- const std::vector<MMData>& mm_datas,
141- std::vector<RequestParams> sps,
142- BatchOutputCallback callback) {
143- CHECK (prompts.size () == sps.size () || sps.size () == 1 )
144- << " Number of prompts and sampling parameters should be the same" ;
145-
146- const size_t num_requests = prompts.size ();
147- for (size_t i = 0 ; i < num_requests; ++i) {
148- handle_request (std::move (prompts[i]),
149- std::move (mm_datas[i]),
150- // the sampling parameter may be shared
151- sps.size () == 1 ? sps[0 ] : std::move (sps[i]),
152- [i, callback](const RequestOutput& output) {
153- output.log_request_status ();
154- return callback (i, output);
155- });
156- }
157- }
158-
159- void VLMMaster::handle_batch_request (
160- const std::vector<std::vector<Message>>& conversations,
161- const std::vector<MMData>& mm_datas,
162- std::vector<RequestParams> sps,
163- BatchOutputCallback callback) {
164- CHECK (conversations.size () == sps.size () || sps.size () == 1 )
165- << " Number of conversations and sampling parameters should be the same" ;
166-
167- const size_t num_requests = conversations.size ();
168- for (size_t i = 0 ; i < num_requests; ++i) {
169- handle_request (std::move (conversations[i]),
170- std::move (mm_datas[i]),
171- // the sampling parameter may be shared
172- sps.size () == 1 ? sps[0 ] : std::move (sps[i]),
173- [i, callback](const RequestOutput& output) {
174- output.log_request_status ();
175- return callback (i, output);
176- });
177- }
178- }
179-
180- void VLMMaster::handle_request (const std::vector<MMChatMessage>& raw_input_data,
181- RequestParams sp,
182- OutputCallback callback) {
183- static MMInputHelper helper;
184- std::vector<Message> messages;
185- MMInput mm_inputs;
186-
187- if (!helper.trans (raw_input_data, messages, mm_inputs.items_ )) {
188- LOG (ERROR) << " MMInputHelper trans failed, ingnore this input." ;
189- return ;
190- }
191-
192- handle_request (std::move (messages), std::move (mm_inputs), sp, callback);
193- }
194-
195127void VLMMaster::handle_request (const std::string& prompt,
196128 const MMData& mm_data,
197129 RequestParams sp,
@@ -232,6 +164,18 @@ void VLMMaster::handle_request(const std::string& prompt,
232164 });
233165}
234166
167+ void VLMMaster::handle_request (const std::vector<Message>& messages,
168+ const MMInput& mm_inputs,
169+ RequestParams sp,
170+ OutputCallback callback) {
171+ MMData mm_data;
172+ if (!mm_inputs.empty () && !image_processor_->process (mm_inputs, mm_data)) {
173+ LOG (ERROR) << " image processor process failed" ;
174+ }
175+
176+ this ->handle_request (messages, mm_data, sp, callback);
177+ }
178+
235179void VLMMaster::handle_request (const std::vector<Message>& messages,
236180 const MMData& mm_data,
237181 RequestParams sp,
@@ -270,6 +214,62 @@ void VLMMaster::handle_request(const std::vector<Message>& messages,
270214 });
271215}
272216
217+ void VLMMaster::handle_request (const std::vector<MMChatMessage>& raw_input_data,
218+ RequestParams sp,
219+ OutputCallback callback) {
220+ static MMInputHelper helper;
221+ std::vector<Message> messages;
222+ MMInput mm_inputs;
223+
224+ if (!helper.trans (raw_input_data, messages, mm_inputs.items_ )) {
225+ LOG (ERROR) << " MMInputHelper trans failed, ingnore this input." ;
226+ return ;
227+ }
228+
229+ handle_request (std::move (messages), std::move (mm_inputs), sp, callback);
230+ }
231+
232+ void VLMMaster::handle_batch_request (const std::vector<std::string>& prompts,
233+ const std::vector<MMData>& mm_datas,
234+ const std::vector<RequestParams>& sps,
235+ BatchOutputCallback callback) {
236+ CHECK (prompts.size () == sps.size () || sps.size () == 1 )
237+ << " Number of prompts and sampling parameters should be the same" ;
238+
239+ const size_t num_requests = prompts.size ();
240+ for (size_t i = 0 ; i < num_requests; ++i) {
241+ handle_request (std::move (prompts[i]),
242+ std::move (mm_datas[i]),
243+ // the sampling parameter may be shared
244+ sps.size () == 1 ? sps[0 ] : std::move (sps[i]),
245+ [i, callback](const RequestOutput& output) {
246+ output.log_request_status ();
247+ return callback (i, output);
248+ });
249+ }
250+ }
251+
252+ void VLMMaster::handle_batch_request (
253+ const std::vector<std::vector<Message>>& conversations,
254+ const std::vector<MMData>& mm_datas,
255+ const std::vector<RequestParams>& sps,
256+ BatchOutputCallback callback) {
257+ CHECK (conversations.size () == sps.size () || sps.size () == 1 )
258+ << " Number of conversations and sampling parameters should be the same" ;
259+
260+ const size_t num_requests = conversations.size ();
261+ for (size_t i = 0 ; i < num_requests; ++i) {
262+ handle_request (std::move (conversations[i]),
263+ std::move (mm_datas[i]),
264+ // the sampling parameter may be shared
265+ sps.size () == 1 ? sps[0 ] : std::move (sps[i]),
266+ [i, callback](const RequestOutput& output) {
267+ output.log_request_status ();
268+ return callback (i, output);
269+ });
270+ }
271+ }
272+
273273void VLMMaster::run () {
274274 const bool already_running = running_.load (std::memory_order_relaxed);
275275 if (already_running) {
0 commit comments