mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
925fdee478
* feat: expand speech provider support with new client types and configuration schema * feat: add icon support for speech providers and update related configurations * feat: add SVG support for Deepgram and Elevenlabs with Vue components * feat: except *-speech client type in llm provider * feat: enhance speech provider functionality with advanced settings and model import capabilities * chore: remove go.mod replace * feat: enhance speech provider functionality with advanced settings and model import capabilities * chore: update go module dependencies * feat: Ear and Mouth * fix: separate ear/mouth page * fix: separate audio domain and restore transcription templates Move speech and transcription internals into the audio domain, restore template-driven transcription providers, and regenerate Swagger/SDK so the frontend can stop hand-calling /transcription-* APIs. --------- Co-authored-by: aki <arisu@ieee.org>
182 lines
5.3 KiB
Go
182 lines
5.3 KiB
Go
package models
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type ModelType string
|
|
|
|
const (
|
|
ModelTypeChat ModelType = "chat"
|
|
ModelTypeEmbedding ModelType = "embedding"
|
|
ModelTypeSpeech ModelType = "speech"
|
|
ModelTypeTranscription ModelType = "transcription"
|
|
)
|
|
|
|
type ClientType string
|
|
|
|
const (
|
|
ClientTypeOpenAIResponses ClientType = "openai-responses"
|
|
ClientTypeOpenAICompletions ClientType = "openai-completions"
|
|
ClientTypeAnthropicMessages ClientType = "anthropic-messages"
|
|
ClientTypeGoogleGenerativeAI ClientType = "google-generative-ai"
|
|
ClientTypeOpenAICodex ClientType = "openai-codex"
|
|
ClientTypeGitHubCopilot ClientType = "github-copilot"
|
|
ClientTypeEdgeSpeech ClientType = "edge-speech"
|
|
ClientTypeOpenAISpeech ClientType = "openai-speech"
|
|
ClientTypeOpenAITranscription ClientType = "openai-transcription"
|
|
ClientTypeOpenRouterSpeech ClientType = "openrouter-speech"
|
|
ClientTypeOpenRouterTranscription ClientType = "openrouter-transcription"
|
|
ClientTypeElevenLabsSpeech ClientType = "elevenlabs-speech"
|
|
ClientTypeElevenLabsTranscription ClientType = "elevenlabs-transcription"
|
|
ClientTypeDeepgramSpeech ClientType = "deepgram-speech"
|
|
ClientTypeDeepgramTranscription ClientType = "deepgram-transcription"
|
|
ClientTypeMiniMaxSpeech ClientType = "minimax-speech"
|
|
ClientTypeVolcengineSpeech ClientType = "volcengine-speech"
|
|
ClientTypeAlibabaSpeech ClientType = "alibabacloud-speech"
|
|
ClientTypeMicrosoftSpeech ClientType = "microsoft-speech"
|
|
ClientTypeGoogleSpeech ClientType = "google-speech"
|
|
ClientTypeGoogleTranscription ClientType = "google-transcription"
|
|
)
|
|
|
|
const (
|
|
CompatVision = "vision"
|
|
CompatToolCall = "tool-call"
|
|
CompatImageOutput = "image-output"
|
|
CompatReasoning = "reasoning"
|
|
)
|
|
|
|
const (
|
|
ReasoningEffortNone = "none"
|
|
ReasoningEffortLow = "low"
|
|
ReasoningEffortMedium = "medium"
|
|
ReasoningEffortHigh = "high"
|
|
ReasoningEffortXHigh = "xhigh"
|
|
)
|
|
|
|
// validCompatibilities enumerates accepted compatibility tokens.
|
|
var validCompatibilities = map[string]struct{}{
|
|
CompatVision: {}, CompatToolCall: {}, CompatImageOutput: {}, CompatReasoning: {},
|
|
}
|
|
|
|
var validReasoningEfforts = map[string]struct{}{
|
|
ReasoningEffortNone: {},
|
|
ReasoningEffortLow: {},
|
|
ReasoningEffortMedium: {},
|
|
ReasoningEffortHigh: {},
|
|
ReasoningEffortXHigh: {},
|
|
}
|
|
|
|
// ModelConfig holds the JSONB config stored per model.
|
|
type ModelConfig struct {
|
|
Dimensions *int `json:"dimensions,omitempty"`
|
|
Compatibilities []string `json:"compatibilities,omitempty"`
|
|
ContextWindow *int `json:"context_window,omitempty"`
|
|
ReasoningEfforts []string `json:"reasoning_efforts,omitempty"`
|
|
}
|
|
|
|
type Model struct {
|
|
ModelID string `json:"model_id"`
|
|
Name string `json:"name"`
|
|
ProviderID string `json:"provider_id"`
|
|
Type ModelType `json:"type"`
|
|
Config ModelConfig `json:"config"`
|
|
}
|
|
|
|
func (m *Model) Validate() error {
|
|
if m.ModelID == "" {
|
|
return errors.New("model ID is required")
|
|
}
|
|
if m.ProviderID == "" {
|
|
return errors.New("provider ID is required")
|
|
}
|
|
if _, err := uuid.Parse(m.ProviderID); err != nil {
|
|
return errors.New("provider ID must be a valid UUID")
|
|
}
|
|
if m.Type != ModelTypeChat && m.Type != ModelTypeEmbedding && m.Type != ModelTypeSpeech && m.Type != ModelTypeTranscription {
|
|
return errors.New("invalid model type")
|
|
}
|
|
if m.Type == ModelTypeEmbedding {
|
|
if m.Config.Dimensions == nil || *m.Config.Dimensions <= 0 {
|
|
return errors.New("dimensions must be greater than 0 for embedding models")
|
|
}
|
|
}
|
|
for _, c := range m.Config.Compatibilities {
|
|
if _, ok := validCompatibilities[c]; !ok {
|
|
return errors.New("invalid compatibility: " + c)
|
|
}
|
|
}
|
|
for _, effort := range m.Config.ReasoningEfforts {
|
|
if _, ok := validReasoningEfforts[effort]; !ok {
|
|
return errors.New("invalid reasoning effort: " + effort)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// HasCompatibility checks whether the model config includes the given capability.
|
|
func (m *Model) HasCompatibility(c string) bool {
|
|
for _, v := range m.Config.Compatibilities {
|
|
if v == c {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
type AddRequest Model
|
|
|
|
type AddResponse struct {
|
|
ID string `json:"id"`
|
|
ModelID string `json:"model_id"`
|
|
}
|
|
|
|
type GetRequest struct {
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type GetResponse struct {
|
|
ID string `json:"id"`
|
|
ModelID string `json:"model_id"`
|
|
Model
|
|
}
|
|
|
|
type UpdateRequest Model
|
|
|
|
type ListRequest struct {
|
|
Type ModelType `json:"type,omitempty"`
|
|
}
|
|
|
|
type DeleteRequest struct {
|
|
ID string `json:"id,omitempty"`
|
|
ModelID string `json:"model_id,omitempty"`
|
|
}
|
|
|
|
type DeleteResponse struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type CountResponse struct {
|
|
Count int64 `json:"count"`
|
|
}
|
|
|
|
// TestStatus represents the outcome of probing a model.
|
|
type TestStatus string
|
|
|
|
const (
|
|
TestStatusOK TestStatus = "ok"
|
|
TestStatusAuthError TestStatus = "auth_error"
|
|
TestStatusModelNotSupported TestStatus = "model_not_supported"
|
|
TestStatusError TestStatus = "error"
|
|
)
|
|
|
|
// TestResponse is returned by POST /models/:id/test.
|
|
type TestResponse struct {
|
|
Status TestStatus `json:"status"`
|
|
Reachable bool `json:"reachable"`
|
|
LatencyMs int64 `json:"latency_ms,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|