Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ paste = "1.0.15"
pem = "3.0.4"
percent-encoding = "2.3.1"
pin-project = "1.1"
postcard = { version = "1.1.1", features = ["use-std"] }
prometheus = "0.13"
r2d2 = "0.8.10"
regex = "1.10.3"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<a href="https://github.com/spiceai/spiceai/actions/workflows/pr.yml"><img alt="GitHub Actions Workflow Status - unit tests" src="https://img.shields.io/github/actions/workflow/status/spiceai/spiceai/pr.yml?event=merge_group&label=unit%20tests" /></a>
<a href="https://github.com/spiceai/spiceai/actions/workflows/integration.yml"><img alt="GitHub Actions Workflow Status - integration tests" src="https://img.shields.io/github/actions/workflow/status/spiceai/spiceai/integration.yml?event=pull_request&label=integration%20tests" /></a>
<a href="https://github.com/spiceai/spiceai/actions/workflows/integration_models.yml"><img alt="GitHub Actions Workflow Status - integration tests (models)" src="https://img.shields.io/github/actions/workflow/status/spiceai/spiceai/integration_models.yml?event=pull_request&label=integration%20tests%20(models)" /></a>
<a href="https://github.com/spiceai/spiceai/actions/workflows/benchmarks.yml"><img alt="GitHub Actions Workflow Status - benchmark tests" src="https://img.shields.io/github/actions/workflow/status/spiceai/spiceai/benchmarks.yml?branch=trunk&label=benchmark%20tests" /></a>
<a href="https://github.com/spiceai/spiceai/actions/workflows/benchmarks.yml"><img alt="GitHub Actions Workflow Status - benchmark tests" src="https://img.shields.io/github/actions/workflow/status/spiceai/spiceai/testoperator_run_bench.yml?branch=trunk&label=benchmark%20tests" /></a>
</p>

<p align="center">
Expand Down
19 changes: 10 additions & 9 deletions bin/spice/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func init() {

func getAddOrConnectCmdHandler(connect bool) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
ctx := context.NewContext()
err := ctx.Init()
rtcontext := context.NewContext()
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("could not initialize runtime context", "error", err)
slog.Error("failed to initialize runtime context", "error", err)
os.Exit(1)
}

Expand All @@ -62,20 +62,21 @@ func getAddOrConnectCmdHandler(connect bool) func(cmd *cobra.Command, args []str
slog.Info(fmt.Sprintf("Getting Spicepod %s ...\n", podPath))

if connect {
if ctx.GetApiKey() == "" {
slog.Error("A valid Spice.ai Cloud Platform API key was not provided. Run `spice login` to authenticate before proceeding.")
apiKey, err := rtcontext.GetApiKey()
if err != nil || apiKey == "" {
slog.Error("Missing or invalid Spice.ai Cloud API key. Run `spice login` to authenticate and continue.")
os.Exit(1)
}

headers := map[string]string{
"Spice-Target-Source": "spice.ai",
"X-API-Key": ctx.GetApiKey(),
"X-API-Key": apiKey,
}
ctx.AddHeaders(headers)
rtcontext.AddHeaders(headers)
}

r := registry.GetRegistry(podPath)
downloadPath, err := r.GetPod(ctx, podPath)
downloadPath, err := r.GetPod(rtcontext, podPath)
if err != nil {
var itemNotFound *registry.RegistryItemNotFound
if errors.As(err, &itemNotFound) {
Expand Down Expand Up @@ -146,7 +147,7 @@ func getAddOrConnectCmdHandler(connect bool) func(cmd *cobra.Command, args []str

slog.Info(fmt.Sprintf("added %s\n", relativePath))

err = checkLatestCliReleaseVersion()
err = checkLatestCliReleaseVersion(rtcontext)
if err != nil && util.IsDebug() {
slog.Error("failed to check for latest CLI release version", "error", err)
}
Expand Down
12 changes: 7 additions & 5 deletions bin/spice/cmd/catalogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ var catalogsCmd = &cobra.Command{
spice catalogs
`,
Run: func(cmd *cobra.Command, args []string) {
rtcontext := context.NewContext()
var rtcontext *context.RuntimeContext
if rootCertPath, err := cmd.Flags().GetString("tls-root-certificate-file"); err == nil && rootCertPath != "" {
rtcontext = context.NewHttpsContext(rootCertPath)
} else {
rtcontext = context.NewContext()
}

apiKey, _ := cmd.Flags().GetString("api-key")
if apiKey != "" {
rtcontext.SetApiKey(apiKey)
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("failed to initialize runtime context", "error", err)
return
}

catalogs, err := api.GetData[api.Catalog](rtcontext, "/v1/catalogs")
Expand Down
18 changes: 2 additions & 16 deletions bin/spice/cmd/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,12 @@ spice chat --model <model> "What is Spice.ai?"
Run: func(cmd *cobra.Command, args []string) {
cloud, _ := cmd.Flags().GetBool(cloudKeyFlag)
rtcontext := context.NewContext().WithCloud(cloud)
err := rtcontext.Init()
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("could not initialize runtime context", "error", err)
slog.Error("failed to initialize runtime context", "error", err)
os.Exit(1)
}

apiKey, _ := cmd.Flags().GetString("api-key")
if apiKey != "" {
rtcontext.SetApiKey(apiKey)
}

temperature, err := cmd.Flags().GetFloat32("temperature")
if err != nil {
slog.Error("could not get temperature flag", "error", err)
Expand All @@ -181,15 +176,6 @@ spice chat --model <model> "What is Spice.ai?"
rtcontext.RequireModelsFlavor(cmd)
}

httpEndpoint, err := cmd.Flags().GetString("http-endpoint")
if err != nil {
slog.Error("could not get http-endpoint flag", "error", err)
os.Exit(1)
}
if httpEndpoint != "" {
rtcontext.SetHttpEndpoint(httpEndpoint)
}

model, err := cmd.Flags().GetString(modelKeyFlag)
if err != nil {
slog.Error("could not get model flag", "error", err)
Expand Down
8 changes: 4 additions & 4 deletions bin/spice/cmd/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spice datasets
if rootCertPath, err := cmd.Flags().GetString("tls-root-certificate-file"); err == nil && rootCertPath != "" {
rtcontext = context.NewHttpsContext(rootCertPath)
}

apiKey, _ := cmd.Flags().GetString("api-key")
if apiKey != "" {
rtcontext.SetApiKey(apiKey)
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("failed to initialize runtime context", "error", err)
return
}

datasets, err := api.GetDatasetsWithStatus(rtcontext)
Expand Down
18 changes: 9 additions & 9 deletions bin/spice/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/spf13/cobra"
"github.com/spiceai/spiceai/bin/spice/pkg/constants"
"github.com/spiceai/spiceai/bin/spice/pkg/context"
"github.com/spiceai/spiceai/bin/spice/pkg/runtime"
"github.com/spiceai/spiceai/bin/spice/pkg/util"
)

Expand All @@ -39,9 +38,16 @@ spice install ai
# See more at: https://spiceai.org/docs/
`,
Run: func(cmd *cobra.Command, args []string) {
rtcontext := context.NewContext()
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("failed to initialize runtime context", "error", err)
os.Exit(1)
}

slog.Info("Checking for latest Spice runtime release...")

err := checkLatestCliReleaseVersion()
err = checkLatestCliReleaseVersion(rtcontext)
if err != nil && util.IsDebug() {
slog.Error("failed to check for latest CLI release version", "error", err)
}
Expand Down Expand Up @@ -75,20 +81,14 @@ spice install ai
}

if force {
rtcontext := context.NewContext()
err := rtcontext.Init()
if err != nil {
slog.Error("initializing runtime context", "error", err)
os.Exit(1)
}
err = rtcontext.InstallMatchingRuntime(flavor, !cpu)
if err != nil {
slog.Error("installing runtime", "error", err)
os.Exit(1)
}
installed = true
} else {
installed, err = runtime.EnsureInstalled(flavor, true, !cpu)
installed, err = rtcontext.EnsureInstalled(flavor, true, !cpu)
if err != nil {
slog.Error("verifying runtime install", "error", err)
os.Exit(1)
Expand Down
8 changes: 4 additions & 4 deletions bin/spice/cmd/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spice models
if rootCertPath, err := cmd.Flags().GetString("tls-root-certificate-file"); err == nil && rootCertPath != "" {
rtcontext = context.NewHttpsContext(rootCertPath)
}

apiKey, _ := cmd.Flags().GetString("api-key")
if apiKey != "" {
rtcontext.SetApiKey(apiKey)
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("failed to initialize runtime context", "error", err)
return
}

model_statuses, _, err := api.GetComponentStatuses(rtcontext)
Expand Down
16 changes: 3 additions & 13 deletions bin/spice/cmd/nsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ nsql> How much money have I made in each country?

cloud, _ := cmd.Flags().GetBool(cloudKeyFlag)
rtcontext := context.NewContext().WithCloud(cloud)

apiKey, _ := cmd.Flags().GetString("api-key")
if apiKey != "" {
rtcontext.SetApiKey(apiKey)
if err := rtcontext.Init(cmd.Flags()); err != nil {
slog.Error("failed to initialize runtime context", "error", err)
os.Exit(1)
}

userAgent, _ := cmd.Flags().GetString("user-agent")
Expand Down Expand Up @@ -127,15 +126,6 @@ nsql> How much money have I made in each country?
model = selectedModel
}

httpEndpoint, err := cmd.Flags().GetString(httpEndpointKeyFlag)
if err != nil {
slog.Error("getting http-endpoint flag", "error", err)
os.Exit(1)
}
if httpEndpoint != "" {
rtcontext.SetHttpEndpoint(httpEndpoint)
}

cmd.Println("")
cmd.Println("Enter a query in natural language.")

Expand Down
8 changes: 4 additions & 4 deletions bin/spice/cmd/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ spice pods
if rootCertPath, err := cmd.Flags().GetString("tls-root-certificate-file"); err == nil && rootCertPath != "" {
rtcontext = context.NewHttpsContext(rootCertPath)
}

apiKey, _ := cmd.Flags().GetString("api-key")
if apiKey != "" {
rtcontext.SetApiKey(apiKey)
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("failed to initialize runtime context", "error", err)
return
}

spicepods, err := api.GetData[api.Spicepod](rtcontext, "/v1/spicepods")
Expand Down
8 changes: 4 additions & 4 deletions bin/spice/cmd/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ spice refresh taxi_trips
if rootCertPath, err := cmd.Flags().GetString("tls-root-certificate-file"); err == nil && rootCertPath != "" {
rtcontext = context.NewHttpsContext(rootCertPath)
}

apiKey, _ := cmd.Flags().GetString("api-key")
if apiKey != "" {
rtcontext.SetApiKey(apiKey)
err := rtcontext.Init(cmd.Flags())
if err != nil {
slog.Error("failed to initialize runtime context", "error", err)
return
}

url := fmt.Sprintf("/v1/datasets/%s/acceleration/refresh", dataset)
Expand Down
Loading
Loading