feat: initial commit
This commit is contained in:
31
internal/setup/api_handler.go
Normal file
31
internal/setup/api_handler.go
Normal file
@ -0,0 +1,31 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/config"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/http/handler/api"
|
||||
"github.com/bornholm/genai/llm/provider"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
_ "github.com/bornholm/genai/llm/provider/all"
|
||||
)
|
||||
|
||||
func NewAPIHandlerFromConfig(ctx context.Context, conf *config.Config) (*api.Handler, error) {
|
||||
store, err := getStoreFromConfig(ctx, conf)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
llm, err := provider.Create(ctx, provider.WithChatCompletionOptions(provider.ClientOptions{
|
||||
Provider: conf.LLM.Provider,
|
||||
BaseURL: conf.LLM.BaseURL,
|
||||
APIKey: conf.LLM.APIKey,
|
||||
Model: conf.LLM.Model,
|
||||
}))
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return api.NewHandler(store, llm, conf.Quiz.PlayInterval, conf.Quiz.PlayPeriod), nil
|
||||
}
|
Reference in New Issue
Block a user