-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added action-level and generate-level middleware.
- Loading branch information
Showing
25 changed files
with
543 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ai | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/firebase/genkit/go/core" | ||
) | ||
|
||
// ValidateSupport creates middleware that validates whether a model supports the requested features. | ||
func ValidateSupport(name string, supports *ModelInfoSupports) ModelMiddleware { | ||
return func(ctx context.Context, input *ModelRequest, cb ModelStreamingCallback, next core.Func[*ModelRequest, *ModelResponse, *ModelResponseChunk]) (*ModelResponse, error) { | ||
if supports == nil { | ||
supports = &ModelInfoSupports{} | ||
} | ||
|
||
if !supports.Media { | ||
for _, msg := range input.Messages { | ||
for _, part := range msg.Content { | ||
if part.IsMedia() { | ||
return nil, fmt.Errorf("model %q does not support media, but media was provided. Request: %+v", name, input) | ||
} | ||
} | ||
} | ||
} | ||
|
||
if !supports.Tools && len(input.Tools) > 0 { | ||
return nil, fmt.Errorf("model %q does not support tool use, but tools were provided. Request: %+v", name, input) | ||
} | ||
|
||
if !supports.Multiturn && len(input.Messages) > 1 { | ||
return nil, fmt.Errorf("model %q does not support multiple messages, but %d were provided. Request: %+v", name, len(input.Messages), input) | ||
} | ||
|
||
return next(ctx, input, cb) | ||
} | ||
} |
Oops, something went wrong.