-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial Pulze Provider #153
base: main
Are you sure you want to change the base?
Changes from 15 commits
d7e9e13
d143856
5573668
b80b3f1
ffabfe9
a076e33
13e8649
66bda7c
151873e
4c9ac19
039a073
eadc9f6
d04ed8c
7bb7308
da46e32
04942e8
0581a53
1aa4769
c027ac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,11 @@ import ( | |
"github.com/grafana/grafana-plugin-sdk-go/build" | ||
) | ||
|
||
var openAIModels = []string{"gpt-3.5-turbo", "gpt-4"} | ||
// Define models for each provider to be included in the health check. | ||
var providerModels = map[string][]string{ | ||
"openai": {"gpt-3.5-turbo", "gpt-4"}, | ||
"pulze": {"pulze", "openai/gpt-4"}, | ||
} | ||
|
||
type healthCheckClient interface { | ||
Do(req *http.Request) (*http.Response, error) | ||
|
@@ -79,20 +83,24 @@ func (a *App) testOpenAIModel(ctx context.Context, model string) error { | |
return nil | ||
} | ||
|
||
// openAIHealth checks the health of the OpenAI configuration and caches the | ||
// openAIHealth performs a health check for the selected provider and caches the | ||
// result if successful. The caller must lock a.healthCheckMutex. | ||
func (a *App) openAIHealth(ctx context.Context, req *backend.CheckHealthRequest) (openAIHealthDetails, error) { | ||
func (a *App) openAIHealth(ctx context.Context, req *backend.CheckHealthRequest) openAIHealthDetails { | ||
if a.healthOpenAI != nil { | ||
return *a.healthOpenAI, nil | ||
return *a.healthOpenAI | ||
} | ||
|
||
d := openAIHealthDetails{ | ||
OK: true, | ||
Configured: a.settings.OpenAI.apiKey != "" || a.settings.OpenAI.Provider == openAIProviderGrafana, | ||
Models: map[string]openAIModelHealth{}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing the condition for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed the logic here (e.g. all "providers" are listed in |
||
} | ||
models := providerModels["openai"] | ||
if a.settings.OpenAI.Provider == openAIProviderPulze { | ||
models = providerModels["pulze"] | ||
} | ||
|
||
for _, model := range openAIModels { | ||
for _, model := range models { | ||
health := openAIModelHealth{OK: false, Error: "OpenAI not configured"} | ||
if d.Configured { | ||
health.OK = true | ||
|
@@ -121,7 +129,7 @@ func (a *App) openAIHealth(ctx context.Context, req *backend.CheckHealthRequest) | |
if d.OK { | ||
a.healthOpenAI = &d | ||
} | ||
return d, nil | ||
return d | ||
} | ||
|
||
// testVectorService checks the health of VectorAPI and caches the result if | ||
|
@@ -137,6 +145,8 @@ func (a *App) testVectorService(ctx context.Context) error { | |
return nil | ||
} | ||
|
||
// vectorHealth performs a health check for the Vector service and caches the | ||
// result if successful. The caller must lock a.healthCheckMutex. | ||
func (a *App) vectorHealth(ctx context.Context) vectorHealthDetails { | ||
if a.healthVector != nil { | ||
return *a.healthVector | ||
|
@@ -169,10 +179,9 @@ func (a *App) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) | |
a.healthCheckMutex.Lock() | ||
defer a.healthCheckMutex.Unlock() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'm thinking we can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought so too, but at the moment it's required to ensure |
||
openAI, err := a.openAIHealth(ctx, req) | ||
if err != nil { | ||
openAI.OK = false | ||
openAI.Error = err.Error() | ||
openAI := a.openAIHealth(ctx, req) | ||
if openAI.Error == "" { | ||
a.healthOpenAI = &openAI | ||
} | ||
|
||
vector := a.vectorHealth(ctx) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,17 @@ import ( | |
"github.com/grafana/grafana-plugin-sdk-go/backend/log" | ||
) | ||
|
||
const openAIKey = "openAIKey" | ||
const encodedTenantAndTokenKey = "base64EncodedAccessToken" | ||
|
||
type openAIProvider string | ||
|
||
const ( | ||
openAIProviderOpenAI openAIProvider = "openai" | ||
openAIProviderAzure openAIProvider = "azure" | ||
openAIProviderGrafana openAIProvider = "grafana" // via llm-gateway | ||
openAIProviderPulze openAIProvider = "pulze" | ||
|
||
openAIKey = "openAIKey" | ||
llmGatewayKey = "llmGatewayKey" | ||
encodedTenantAndTokenKey = "base64EncodedAccessToken" | ||
) | ||
|
||
// OpenAISettings contains the user-specified OpenAI connection details | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think at some point we'll have to consider renaming this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, agree. We initially planned to include this, but it's better to have a separate PR for this 👍 |
||
|
@@ -38,6 +40,9 @@ type OpenAISettings struct { | |
// Model mappings required for Azure's OpenAI | ||
AzureMapping [][]string `json:"azureModelMapping"` | ||
|
||
// The pulze model to use | ||
PulzeModel string `json:"pulzeModel"` | ||
|
||
// apiKey is the user-specified api key needed to authenticate requests to the OpenAI | ||
// provider (excluding the LLMGateway). Stored securely. | ||
apiKey string | ||
|
@@ -121,6 +126,10 @@ func loadSettings(appSettings backend.AppInstanceSettings) (*Settings, error) { | |
log.DefaultLogger.Warn("Cannot use LLM Gateway as no URL specified, disabling it") | ||
settings.OpenAI.Provider = "" | ||
} | ||
case openAIProviderPulze: | ||
if settings.OpenAI.URL == "" { | ||
settings.OpenAI.URL = "https://api.pulze.ai/v1" | ||
} | ||
default: | ||
// Default to disabled LLM support if an unknown provider was specified. | ||
log.DefaultLogger.Warn("Unknown OpenAI provider", "provider", settings.OpenAI.Provider) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this would be more type-safe if it was a
map[openAIProvider][]string