Download platform/dbops/binaries/weaviate-src/modules/generative-openai/module.go from LevelUp2x/adaptai: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/main/platform/dbops/binaries/weaviate-src/modules/generative-openai/module.go
- Command line
-
hf download hf://datasets/LevelUp2x/adaptai/platform/dbops/binaries/weaviate-src/modules/generative-openai/module.go
-
curl -L -o module.go https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/main/platform/dbops/binaries/weaviate-src/modules/generative-openai/module.go
2.52 kB
| // _ _ | |
| // __ _____ __ ___ ___ __ _| |_ ___ | |
| // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ | |
| // \ V V / __/ (_| |\ V /| | (_| | || __/ | |
| // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| | |
| // | |
| // Copyright © 2016 - 2025 Weaviate B.V. All rights reserved. | |
| // | |
| // CONTACT: hello@weaviate.io | |
| // | |
| package modgenerativeopenai | |
| import ( | |
| "context" | |
| "os" | |
| "time" | |
| "github.com/pkg/errors" | |
| "github.com/sirupsen/logrus" | |
| "github.com/weaviate/weaviate/entities/modulecapabilities" | |
| "github.com/weaviate/weaviate/entities/moduletools" | |
| "github.com/weaviate/weaviate/modules/generative-openai/clients" | |
| "github.com/weaviate/weaviate/modules/generative-openai/parameters" | |
| ) | |
| const Name = "generative-openai" | |
| func New() *GenerativeOpenAIModule { | |
| return &GenerativeOpenAIModule{} | |
| } | |
| type GenerativeOpenAIModule struct { | |
| generative generativeClient | |
| additionalPropertiesProvider map[string]modulecapabilities.GenerativeProperty | |
| } | |
| type generativeClient interface { | |
| modulecapabilities.GenerativeClient | |
| MetaInfo() (map[string]interface{}, error) | |
| } | |
| func (m *GenerativeOpenAIModule) Name() string { | |
| return Name | |
| } | |
| func (m *GenerativeOpenAIModule) Type() modulecapabilities.ModuleType { | |
| return modulecapabilities.Text2TextGenerative | |
| } | |
| func (m *GenerativeOpenAIModule) Init(ctx context.Context, | |
| params moduletools.ModuleInitParams, | |
| ) error { | |
| if err := m.initAdditional(ctx, params.GetConfig().ModuleHttpClientTimeout, params.GetLogger()); err != nil { | |
| return errors.Wrapf(err, "init %s", Name) | |
| } | |
| return nil | |
| } | |
| func (m *GenerativeOpenAIModule) initAdditional(ctx context.Context, timeout time.Duration, | |
| logger logrus.FieldLogger, | |
| ) error { | |
| openAIApiKey := os.Getenv("OPENAI_APIKEY") | |
| openAIOrganization := os.Getenv("OPENAI_ORGANIZATION") | |
| azureApiKey := os.Getenv("AZURE_APIKEY") | |
| client := clients.New(openAIApiKey, openAIOrganization, azureApiKey, timeout, logger) | |
| m.generative = client | |
| m.additionalPropertiesProvider = parameters.AdditionalGenerativeParameters(m.generative) | |
| return nil | |
| } | |
| func (m *GenerativeOpenAIModule) MetaInfo() (map[string]interface{}, error) { | |
| return m.generative.MetaInfo() | |
| } | |
| func (m *GenerativeOpenAIModule) AdditionalGenerativeProperties() map[string]modulecapabilities.GenerativeProperty { | |
| return m.additionalPropertiesProvider | |
| } | |
| // verify we implement the modules.Module interface | |
| var ( | |
| _ = modulecapabilities.Module(New()) | |
| _ = modulecapabilities.MetaProvider(New()) | |
| _ = modulecapabilities.AdditionalGenerativeProperties(New()) | |
| ) | |