Initial commit: my-brain-importer RAG knowledge management agent
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
76
internal/config/config.go
Executable file
76
internal/config/config.go
Executable file
@@ -0,0 +1,76 @@
|
||||
// config.go – Konfiguration, Clients und gemeinsame Verbindungen
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
openai "github.com/sashabaranov/go-openai"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Qdrant struct {
|
||||
Host string `yaml:"host"`
|
||||
Port string `yaml:"port"`
|
||||
APIKey string `yaml:"api_key"`
|
||||
Collection string `yaml:"collection"`
|
||||
} `yaml:"qdrant"`
|
||||
|
||||
Embedding struct {
|
||||
URL string `yaml:"url"`
|
||||
Model string `yaml:"model"`
|
||||
Dimensions uint64 `yaml:"dimensions"`
|
||||
} `yaml:"embedding"`
|
||||
|
||||
Chat struct {
|
||||
URL string `yaml:"url"`
|
||||
Model string `yaml:"model"`
|
||||
} `yaml:"chat"`
|
||||
|
||||
BrainRoot string `yaml:"brain_root"`
|
||||
TopK uint64 `yaml:"top_k"`
|
||||
}
|
||||
|
||||
var Cfg Config
|
||||
|
||||
// NewQdrantConn öffnet eine gRPC-Verbindung zur Qdrant-Instanz.
|
||||
// Der Aufrufer ist verantwortlich für conn.Close().
|
||||
func NewQdrantConn() *grpc.ClientConn {
|
||||
conn, err := grpc.Dial(
|
||||
fmt.Sprintf("%s:%s", Cfg.Qdrant.Host, Cfg.Qdrant.Port),
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("❌ Qdrant Verbindung fehlgeschlagen: %v", err)
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
||||
// NewEmbeddingClient erstellt einen Client für LocalAI (Embeddings).
|
||||
func NewEmbeddingClient() *openai.Client {
|
||||
c := openai.DefaultConfig("localai")
|
||||
c.BaseURL = Cfg.Embedding.URL
|
||||
return openai.NewClientWithConfig(c)
|
||||
}
|
||||
|
||||
// NewChatClient erstellt einen Client für Chat-Completion (LocalAI).
|
||||
func NewChatClient() *openai.Client {
|
||||
c := openai.DefaultConfig("localai")
|
||||
c.BaseURL = Cfg.Chat.URL
|
||||
return openai.NewClientWithConfig(c)
|
||||
}
|
||||
|
||||
// LoadConfig liest config.yml aus dem aktuellen Verzeichnis.
|
||||
func LoadConfig() {
|
||||
data, err := os.ReadFile("config.yml")
|
||||
if err != nil {
|
||||
log.Fatalf("❌ config.yml nicht gefunden: %v\n Lege config.yml im selben Verzeichnis an.", err)
|
||||
}
|
||||
if err := yaml.Unmarshal(data, &Cfg); err != nil {
|
||||
log.Fatalf("❌ config.yml ungültig: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user