@@ -291,83 +291,6 @@ func (h *Host) callHostModelExecute(ctx context.Context, request []byte) ([]byte
291291 })
292292}
293293
294- func (h * Host ) callHostModelExecuteStream (ctx context.Context , request []byte ) ([]byte , error ) {
295- var req rpcHostModelExecutionRequest
296- if errUnmarshal := json .Unmarshal (request , & req ); errUnmarshal != nil {
297- return nil , fmt .Errorf ("decode host model execution stream request: %w" , errUnmarshal )
298- }
299- if ! req .Stream {
300- return nil , fmt .Errorf ("host.model.execute_stream requires stream=true" )
301- }
302- executor := h .currentModelExecutor ()
303- if executor == nil {
304- return nil , fmt .Errorf ("host model executor is unavailable" )
305- }
306- skipPluginID := h .callbackCallerPluginID (ctx , req .HostCallbackID )
307- ctx = h .resolveCallbackContext (req .HostCallbackID , ctx )
308- if ctx == nil {
309- ctx = context .Background ()
310- }
311- streamCtx , cancel := context .WithCancel (ctx )
312- stream , errMsg := executor .ExecuteModelStream (streamCtx , modelExecutionRequestFromPlugin (req .HostModelExecutionRequest , skipPluginID ))
313- if errMsg != nil {
314- cancel ()
315- return nil , modelExecutionError (errMsg )
316- }
317- streamID := ""
318- if h != nil && h .modelStreams != nil {
319- streamID = h .modelStreams .open (req .HostCallbackID , stream .Chunks , cancel )
320- }
321- if streamID == "" {
322- cancel ()
323- return nil , fmt .Errorf ("host model stream bridge is unavailable" )
324- }
325- if req .HostCallbackID != "" {
326- h .addCallbackCleanup (req .HostCallbackID , func () {
327- h .modelStreams .close (streamID )
328- })
329- }
330- return marshalRPCResult (pluginapi.HostModelStreamResponse {
331- StatusCode : stream .StatusCode ,
332- Headers : cloneHeader (stream .Headers ),
333- StreamID : streamID ,
334- })
335- }
336-
337- func (h * Host ) callHostModelStreamRead (ctx context.Context , request []byte ) ([]byte , error ) {
338- var req pluginapi.HostModelStreamReadRequest
339- if errUnmarshal := json .Unmarshal (request , & req ); errUnmarshal != nil {
340- return nil , fmt .Errorf ("decode host model stream read request: %w" , errUnmarshal )
341- }
342- if h == nil || h .modelStreams == nil {
343- return nil , fmt .Errorf ("host model stream bridge is unavailable" )
344- }
345- chunk , done , errRead := h .modelStreams .read (ctx , req .StreamID )
346- if errRead != nil {
347- return nil , errRead
348- }
349- resp := pluginapi.HostModelStreamReadResponse {
350- Payload : append ([]byte (nil ), chunk .Payload ... ),
351- Done : done ,
352- }
353- if chunk .Err != nil {
354- resp .Error = chunk .Err .Error ()
355- resp .Done = true
356- }
357- return marshalRPCResult (resp )
358- }
359-
360- func (h * Host ) callHostModelStreamClose (request []byte ) ([]byte , error ) {
361- var req pluginapi.HostModelStreamCloseRequest
362- if errUnmarshal := json .Unmarshal (request , & req ); errUnmarshal != nil {
363- return nil , fmt .Errorf ("decode host model stream close request: %w" , errUnmarshal )
364- }
365- if h != nil && h .modelStreams != nil {
366- h .modelStreams .close (req .StreamID )
367- }
368- return marshalRPCResult (rpcEmptyResponse {})
369- }
370-
371294func modelExecutionRequestFromPlugin (req pluginapi.HostModelExecutionRequest , skipPluginID string ) handlers.ModelExecutionRequest {
372295 return handlers.ModelExecutionRequest {
373296 EntryProtocol : req .EntryProtocol ,
0 commit comments