-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from grafana/vector-service
Add vector service concept, and resource endpoint to handle vector search
- Loading branch information
Showing
15 changed files
with
668 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package plugin | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/grafana/grafana-llm-app/pkg/plugin/vector" | ||
"github.com/grafana/grafana-plugin-sdk-go/backend" | ||
) | ||
|
||
const openAIKey = "openAIKey" | ||
|
||
type OpenAISettings struct { | ||
URL string `json:"url"` | ||
OrganizationID string `json:"organizationId"` | ||
apiKey string | ||
} | ||
|
||
type Settings struct { | ||
OpenAI OpenAISettings `json:"openAI"` | ||
|
||
openAIKey string | ||
|
||
Vector vector.VectorSettings `json:"vector"` | ||
} | ||
|
||
func loadSettings(appSettings backend.AppInstanceSettings) Settings { | ||
settings := Settings{ | ||
OpenAI: OpenAISettings{ | ||
URL: "https://api.openai.com", | ||
}, | ||
} | ||
_ = json.Unmarshal(appSettings.JSONData, &settings) | ||
|
||
settings.openAIKey = appSettings.DecryptedSecureJSONData[openAIKey] | ||
return settings | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package embed | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/grafana/grafana-plugin-sdk-go/backend/log" | ||
) | ||
|
||
type EmbedderType string | ||
|
||
const ( | ||
EmbedderOpenAI EmbedderType = "openai" | ||
) | ||
|
||
type Embedder interface { | ||
Embed(ctx context.Context, model string, text string) ([]float32, error) | ||
} | ||
|
||
type Settings struct { | ||
Type string `json:"type"` | ||
|
||
OpenAI openAISettings `json:"openai"` | ||
} | ||
|
||
// NewEmbedder creates a new embedder. | ||
func NewEmbedder(s Settings, secrets map[string]string) (Embedder, error) { | ||
switch EmbedderType(s.Type) { | ||
case EmbedderOpenAI: | ||
log.DefaultLogger.Debug("Creating OpenAI embedder") | ||
return newOpenAIEmbedder(s.OpenAI, secrets), nil | ||
} | ||
return nil, nil | ||
} |
Oops, something went wrong.