|
| 1 | +package mistral |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + |
| 7 | + "github.com/mutablelogic/go-client" |
| 8 | + "github.com/mutablelogic/go-llm" |
| 9 | +) |
| 10 | + |
| 11 | +/////////////////////////////////////////////////////////////////////////////// |
| 12 | +// TYPES |
| 13 | + |
| 14 | +type model struct { |
| 15 | + meta Model |
| 16 | +} |
| 17 | + |
| 18 | +type Model struct { |
| 19 | + Name string `json:"id"` |
| 20 | + Description string `json:"description,omitempty"` |
| 21 | + Type string `json:"type,omitempty"` |
| 22 | + CreatedAt *uint64 `json:"created,omitempty"` |
| 23 | + OwnedBy string `json:"owned_by,omitempty"` |
| 24 | + MaxContextLength uint64 `json:"max_context_length,omitempty"` |
| 25 | + Aliases []string `json:"aliases,omitempty"` |
| 26 | + Deprecation *string `json:"deprecation,omitempty"` |
| 27 | + DefaultModelTemperature *float64 `json:"default_model_temperature,omitempty"` |
| 28 | + Capabilities struct { |
| 29 | + CompletionChat bool `json:"completion_chat,omitempty"` |
| 30 | + CompletionFim bool `json:"completion_fim,omitempty"` |
| 31 | + FunctionCalling bool `json:"function_calling,omitempty"` |
| 32 | + FineTuning bool `json:"fine_tuning,omitempty"` |
| 33 | + Vision bool `json:"vision,omitempty"` |
| 34 | + } `json:"capabilities,omitempty"` |
| 35 | +} |
| 36 | + |
| 37 | +/////////////////////////////////////////////////////////////////////////////// |
| 38 | +// STRINGIFY |
| 39 | + |
| 40 | +func (m model) MarshalJSON() ([]byte, error) { |
| 41 | + return json.Marshal(m.meta) |
| 42 | +} |
| 43 | + |
| 44 | +func (m model) String() string { |
| 45 | + data, err := json.MarshalIndent(m, "", " ") |
| 46 | + if err != nil { |
| 47 | + return err.Error() |
| 48 | + } |
| 49 | + return string(data) |
| 50 | +} |
| 51 | + |
| 52 | +/////////////////////////////////////////////////////////////////////////////// |
| 53 | +// PUBLIC METHODS - API |
| 54 | + |
| 55 | +// ListModels returns all the models |
| 56 | +func (c *Client) ListModels(ctx context.Context) ([]llm.Model, error) { |
| 57 | + // Response |
| 58 | + var response struct { |
| 59 | + Data []Model `json:"data"` |
| 60 | + } |
| 61 | + if err := c.DoWithContext(ctx, nil, &response, client.OptPath("models")); err != nil { |
| 62 | + return nil, err |
| 63 | + } |
| 64 | + |
| 65 | + // Make models |
| 66 | + result := make([]llm.Model, 0, len(response.Data)) |
| 67 | + for _, meta := range response.Data { |
| 68 | + result = append(result, &model{meta: meta}) |
| 69 | + } |
| 70 | + |
| 71 | + // Return models |
| 72 | + return result, nil |
| 73 | +} |
| 74 | + |
| 75 | +/////////////////////////////////////////////////////////////////////////////// |
| 76 | +// PUBLIC METHODS - MODEL |
| 77 | + |
| 78 | +// Return the name of the model |
| 79 | +func (m model) Name() string { |
| 80 | + return m.meta.Name |
| 81 | +} |
| 82 | + |
| 83 | +// Return am empty session context object for the model, |
| 84 | +// setting session options |
| 85 | +func (m model) Context(...llm.Opt) llm.Context { |
| 86 | + return nil |
| 87 | +} |
| 88 | + |
| 89 | +// Convenience method to create a session context object |
| 90 | +// with a user prompt |
| 91 | +func (m model) UserPrompt(string, ...llm.Opt) llm.Context { |
| 92 | + return nil |
| 93 | +} |
| 94 | + |
| 95 | +// Embedding vector generation |
| 96 | +func (m model) Embedding(context.Context, string, ...llm.Opt) ([]float64, error) { |
| 97 | + return nil, llm.ErrNotImplemented |
| 98 | +} |
0 commit comments