mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
65b2797626
Move CreateModel, BuildReasoningOptions, ReasoningBudgetTokens and related types from internal/agent to internal/models as NewSDKChatModel, SDKModelConfig, etc. This eliminates duplicate ClientType constants and centralises all Twilight AI SDK instance creation in a single package. NewSDKEmbeddingModel now accepts a clientType parameter and dispatches to the native Google embedding provider for google-generative-ai, instead of always using the OpenAI-compatible endpoint.
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
googleembedding "github.com/memohai/twilight-ai/provider/google/embedding"
|
|
openaiembedding "github.com/memohai/twilight-ai/provider/openai/embedding"
|
|
sdk "github.com/memohai/twilight-ai/sdk"
|
|
)
|
|
|
|
// NewSDKEmbeddingModel creates a Twilight AI SDK EmbeddingModel for the given
|
|
// provider configuration. It dispatches to the native Google embedding provider
|
|
// when clientType is "google-generative-ai", and falls back to the
|
|
// OpenAI-compatible /embeddings endpoint for all other provider types.
|
|
func NewSDKEmbeddingModel(clientType, baseURL, apiKey, modelID string, timeout time.Duration) *sdk.EmbeddingModel {
|
|
if timeout <= 0 {
|
|
timeout = 30 * time.Second
|
|
}
|
|
httpClient := &http.Client{Timeout: timeout}
|
|
|
|
switch ClientType(clientType) {
|
|
case ClientTypeGoogleGenerativeAI:
|
|
opts := []googleembedding.Option{
|
|
googleembedding.WithAPIKey(apiKey),
|
|
googleembedding.WithHTTPClient(httpClient),
|
|
}
|
|
if baseURL != "" {
|
|
opts = append(opts, googleembedding.WithBaseURL(baseURL))
|
|
}
|
|
p := googleembedding.New(opts...)
|
|
return p.EmbeddingModel(modelID)
|
|
|
|
default:
|
|
opts := []openaiembedding.Option{
|
|
openaiembedding.WithAPIKey(apiKey),
|
|
openaiembedding.WithHTTPClient(httpClient),
|
|
}
|
|
if baseURL != "" {
|
|
opts = append(opts, openaiembedding.WithBaseURL(baseURL))
|
|
}
|
|
p := openaiembedding.New(opts...)
|
|
return p.EmbeddingModel(modelID)
|
|
}
|
|
}
|