1
1
package genai
2
2
3
3
import (
4
- "io"
5
-
6
4
"oss.nandlabs.io/golly/errutils"
7
5
"oss.nandlabs.io/golly/managers"
8
6
)
@@ -34,6 +32,24 @@ var GetUnsupportedProviderErr = errutils.NewCustomError("unsupported provider fo
34
32
35
33
var Providers managers.ItemManager [Provider ] = managers .NewItemManager [Provider ]()
36
34
35
+ type StreamingHandller func (message Message , last bool )
36
+
37
+ type Model struct {
38
+ Id string `json:"id" yaml:"id" bson:"id"`
39
+ Name string `json:"name" yaml:"name" bson:"name"`
40
+ Version string `json:"version" yaml:"version" bson:"version"`
41
+ InMimes []string `json:"in_mimes" yaml:"in_mimes" bson:"in_mimes"`
42
+ OutMimes []string `json:"out_mimes" yaml:"out_mimes" bson:"out_mimes"`
43
+ Options []* ModelOption `json:"options" yaml:"options" bson:"options"`
44
+ }
45
+
46
+ type ModelOption struct {
47
+ Name string `json:"name" yaml:"name" bson:"name"`
48
+ Type string `json:"type" yaml:"type" bson:"type"`
49
+ Required bool `json:"required" yaml:"required" bson:"required"`
50
+ Default any `json:"default" yaml:"default" bson:"default"`
51
+ }
52
+
37
53
// Provider is the interface that represents a generative AI model
38
54
type Provider interface {
39
55
// Name returns the name of the model
@@ -42,20 +58,18 @@ type Provider interface {
42
58
Description () string
43
59
// Version returns the version of the model
44
60
Version () string
45
- // Author returns the author of the model
46
- Author () string
47
- // License returns the license of the model
48
- License () string
49
- // Supports returns true if the model supports the given MIME type as a consumer or provider
50
- Supports (model , mime string ) (consumer bool , provider bool )
51
- // Accepts returns the supported input MIME types accepted by this model
52
- Accepts (model string ) []string
53
- // Produces returns the supported output MIME types thats produced by this model
54
- Produces (model string ) []string
55
- // Generate will invoke the model generation and fetch the result. This is a blocking call.
61
+ //Models returns the list of models supported by the provider
62
+ // Some providers may not have to get this information programatically, in which case this method should return nil
63
+ // and unsupported operation error.
64
+ Models () ([]* Model , error )
65
+ // Generate will invoke the model generation and adds the result to the exhange. This is a blocking call.
56
66
Generate (model string , exchange Exchange , options * Options ) error
57
- // GenerateStream will invoke the model generation and stream the result. This will be a non-blocking call.
58
- GenerateStream (model string , exchange Exchange , handler func (reader io.Reader ), options Options ) error
67
+ // GenerateStream will invoke the model generation and stream the result to handler function.
68
+ // This will be a non-blocking call.
69
+ // The handler function will be called for each message generated by the model.
70
+ // The last parameter will be true for the last message.
71
+ // The exchange will also be updated with the generated messages.
72
+ GenerateStream (model string , exchange Exchange , handler StreamingHandller , options Options ) error
59
73
}
60
74
61
75
// Options represents the options for the Service
@@ -686,86 +700,3 @@ func (o *OptionsBuilder) SetOutputMimes(outputMimes ...string) *OptionsBuilder {
686
700
o .options .values [OptionOutputMimes ] = outputMimes
687
701
return o
688
702
}
689
-
690
- // AbstractModel represents a generic model with metadata information.
691
- // It includes fields for the model's name, description, version, author, license,
692
- // and supported input and output MIME types.
693
- type AbstractModel struct {
694
- name string
695
- description string
696
- version string
697
- author string
698
- license string
699
- inputMime []string
700
- outputMime []string
701
- }
702
-
703
- // Name returns the name of the AbstractModel.
704
- // It retrieves the value of the private field 'name' and returns it as a string.
705
- //
706
- // Returns:
707
- //
708
- // string: The name of the model.
709
- func (m * AbstractModel ) Name () string {
710
- return m .name
711
- }
712
-
713
- // Description returns the description of the AbstractModel.
714
- // It provides a brief summary or details about the model.
715
- //
716
- // Returns:
717
- //
718
- // string: The description of the model.
719
- func (m * AbstractModel ) Description () string {
720
- return m .description
721
- }
722
-
723
- // Version returns the version of the AbstractModel.
724
- // It retrieves the value of the private field 'version' and returns it as a string.
725
- //
726
- // Returns:
727
- //
728
- // string: The version of the model.
729
- func (m * AbstractModel ) Version () string {
730
- return m .version
731
- }
732
-
733
- // Author returns the author of the AbstractModel.
734
- // It retrieves the value of the private field 'author' and returns it as a string.
735
- //
736
- // Returns:
737
- //
738
- // string: The author of the model.
739
- func (m * AbstractModel ) Author () string {
740
- return m .author
741
- }
742
-
743
- // License returns the license of the AbstractModel.
744
- // It retrieves the value of the private field 'license' and returns it as a string.
745
- //
746
- // Returns:
747
- //
748
- // string: The license of the model.
749
- func (m * AbstractModel ) License () string {
750
- return m .license
751
- }
752
-
753
- // InputMimeTypes returns the supported input MIME types for the AbstractModel.
754
- // It retrieves the value of the private field 'inputMime' and returns it as a slice of strings.
755
- //
756
- // Returns:
757
- //
758
- // []string: A slice of strings representing the supported input MIME types.
759
- func (m * AbstractModel ) InputMimeTypes () []string {
760
- return m .inputMime
761
- }
762
-
763
- // OutputMimeTypes returns the supported output MIME types for the AbstractModel.
764
- // It retrieves the value of the private field 'outputMime' and returns it as a slice of strings.
765
- //
766
- // Returns:
767
- //
768
- // []string: A slice of strings representing the supported output MIME types.
769
- func (m * AbstractModel ) OutputMimeTypes () []string {
770
- return m .outputMime
771
- }
0 commit comments