Skip to content

Commit

Permalink
update staging URL with new naming schema, add helpers for staging vs…
Browse files Browse the repository at this point in the history
… production targeting
  • Loading branch information
austin-denoble committed Jun 11, 2024
1 parent ecdd185 commit 326b2d7
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 42 deletions.
18 changes: 14 additions & 4 deletions internal/pkg/assistants/assistant_chat_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ package assistants
import (
"fmt"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/state"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/models"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
)

const (
URL_ASSISTANT_CHAT_COMPLETIONS = "/knowledge/chat/%s/chat/completions"
URL_ASSISTANT_CHAT_COMPLETIONS = "/knowledge/chat/%s/chat/completions"
URL_ASSISTANT_CHAT_COMPLETIONS_STAGING = "/assistant/chat/%s/chat/completions"
)

func getAssistantChatCompletionsUrl() string {
if config.Environment.Get() == "production" {
return URL_ASSISTANT_CHAT_COMPLETIONS
} else {
return URL_ASSISTANT_CHAT_COMPLETIONS_STAGING
}
}

func GetAssistantChatCompletions(kmName string, msg string) (*models.ChatCompletionModel, error) {
outgoingMsg := models.ChatCompletionMessage{
Role: "user",
Expand All @@ -32,14 +42,14 @@ func GetAssistantChatCompletions(kmName string, msg string) (*models.ChatComplet
Messages: chat.Messages,
}

knowledgeDataUrl, err := GetKnowledgeDataBaseUrl()
assistantDataUrl, err := GetAssistantDataBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.PostAndDecode[models.ChatCompletionRequest, models.ChatCompletionModel](
knowledgeDataUrl,
fmt.Sprintf(URL_ASSISTANT_CHAT_COMPLETIONS, kmName),
assistantDataUrl,
fmt.Sprintf(getAssistantChatCompletionsUrl(), kmName),
true,
body,
)
Expand Down
16 changes: 13 additions & 3 deletions internal/pkg/assistants/assistant_file_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@ package assistants
import (
"net/http"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
)

const (
URL_DELETE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
URL_DELETE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
URL_DELETE_ASSISTANT_FILE_STAGING = "/assistant/files/%s/%s"
)

func getDeleteAssistantFileUrl() string {
if config.Environment.Get() == "production" {
return URL_DELETE_ASSISTANT_FILE
} else {
return URL_DELETE_ASSISTANT_FILE_STAGING
}
}

type DeleteAssistantFileResponse string

func DeleteKnowledgeFile(kmName string, fileId string) (*DeleteAssistantFileResponse, error) {
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
assistantDataUrl, err := GetAssistantDataBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.RequestWithoutBodyAndDecode[DeleteAssistantFileResponse](
assistantDataUrl,
pcio.Sprintf(URL_DELETE_ASSISTANT_FILE, kmName, fileId),
pcio.Sprintf(getDeleteAssistantFileUrl(), kmName, fileId),
http.MethodDelete,
true,
)
Expand Down
16 changes: 13 additions & 3 deletions internal/pkg/assistants/assistant_file_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ package assistants
import (
"fmt"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
)

const (
URL_DESCRIBE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
URL_DESCRIBE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
URL_DESCRIBE_ASSISTANT_FILE_STAGING = "/assistant/files/%s/%s"
)

func getDescribeAssistantFileUrl() string {
if config.Environment.Get() == "production" {
return URL_DESCRIBE_ASSISTANT_FILE
} else {
return URL_DESCRIBE_ASSISTANT_FILE_STAGING
}
}

func DescribeAssistantFile(name string, fileId string) (*AssistantFileModel, error) {
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
assistantDataUrl, err := GetAssistantDataBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.GetAndDecode[AssistantFileModel](
assistantDataUrl,
fmt.Sprintf(URL_DESCRIBE_ASSISTANT_FILE, name, fileId),
fmt.Sprintf(getDescribeAssistantFileUrl(), name, fileId),
true,
)
if err != nil {
Expand Down
16 changes: 13 additions & 3 deletions internal/pkg/assistants/assistant_file_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,32 @@ package assistants
import (
"fmt"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
)

const (
URL_ASSISTANT_FILE_UPLOAD = "/knowledge/files/%s"
URL_ASSISTANT_FILE_UPLOAD = "/knowledge/files/%s"
URL_ASSISTANT_FILE_UPLOAD_STAGING = "/assistant/files/%s"
)

func getAssistantFileUploadUrl() string {
if config.Environment.Get() == "production" {
return URL_ASSISTANT_FILE_UPLOAD
} else {
return URL_ASSISTANT_FILE_UPLOAD_STAGING
}
}

func UploadAssistantFile(name string, filePath string) (*AssistantFileModel, error) {
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
assistantDataUrl, err := GetAssistantDataBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.PostAndDecodeMultipartFormData[AssistantFileModel](
assistantDataUrl,
fmt.Sprintf(URL_ASSISTANT_FILE_UPLOAD, name),
fmt.Sprintf(getAssistantFileUploadUrl(), name),
true,
filePath,
)
Expand Down
16 changes: 13 additions & 3 deletions internal/pkg/assistants/assistant_files_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ package assistants
import (
"fmt"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
)

const (
URL_LIST_ASSISTANT_FILES = "/knowledge/files/%s"
URL_LIST_ASSISTANT_FILES = "/knowledge/files/%s"
URL_LIST_ASSISTANT_FILES_STAGING = "/assistant/files/%s"
)

func getListAssistantFilesUrl() string {
if config.Environment.Get() == "production" {
return URL_LIST_ASSISTANT_FILES
} else {
return URL_LIST_ASSISTANT_FILES_STAGING
}
}

type AssistantFileModel struct {
Name string `json:"name"`
Id string `json:"id"`
Expand All @@ -33,14 +43,14 @@ type ListAssistantFilesResponse struct {
}

func ListAssistantFiles(name string) (*ListAssistantFilesResponse, error) {
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
assistantDataUrl, err := GetAssistantDataBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.GetAndDecode[ListAssistantFilesResponse](
assistantDataUrl,
fmt.Sprintf(URL_LIST_ASSISTANT_FILES, name),
fmt.Sprintf(getListAssistantFilesUrl(), name),
true,
)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/assistants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (
"github.com/pinecone-io/cli/internal/pkg/utils/environment"
)

func GetKnowledgeDataBaseUrl() (string, error) {
func GetAssistantDataBaseUrl() (string, error) {
connectionConfigs, err := environment.GetEnvConfig(config.Environment.Get())
if err != nil {
return "", err
}
return connectionConfigs.KnowledgeDataPlaneUrl, nil
return connectionConfigs.AssistantDataPlaneUrl, nil
}

func GetKnowledgeControlBaseUrl() (string, error) {
func GetAssistantControlBaseUrl() (string, error) {
connectionConfigs, err := environment.GetEnvConfig(config.Environment.Get())
if err != nil {
return "", err
}
return connectionConfigs.KnowledgeControlPlaneUrl, nil
return connectionConfigs.AssistantControlPlaneUrl, nil
}
18 changes: 14 additions & 4 deletions internal/pkg/assistants/create.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package assistants

import (
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
)

const (
URL_CREATE_ASSISTANT = "/knowledge/models"
URL_CREATE_ASSISTANT = "/knowledge/models"
URL_CREATE_ASSISTANT_STAGING = "/assistant/assistants"
)

func getCreateAssistantUrl() string {
if config.Environment.Get() == "production" {
return URL_CREATE_ASSISTANT
} else {
return URL_CREATE_ASSISTANT_STAGING
}
}

type CreateAssistantRequest struct {
Name string `json:"name"`
Metadata map[string]interface{} `json:"metadata"`
Expand All @@ -18,14 +28,14 @@ func CreateAssistant(name string) (*AssistantModel, error) {
Name: name,
}

knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
assistantControlUrl, err := GetAssistantControlBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.PostAndDecode[CreateAssistantRequest, AssistantModel](
knowledgeControlUrl,
URL_CREATE_ASSISTANT,
assistantControlUrl,
getCreateAssistantUrl(),
true,
body,
)
Expand Down
18 changes: 14 additions & 4 deletions internal/pkg/assistants/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@ package assistants
import (
"net/http"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
)

const (
URL_DELETE_ASSISTANT = "/knowledge/models/%s"
URL_DELETE_ASSISTANT = "/knowledge/models/%s"
URL_DELETE_ASSISTANT_STAGING = "/assistant/assistants/%s"
)

func getDeleteAssistantUrl() string {
if config.Environment.Get() == "production" {
return URL_DELETE_ASSISTANT
} else {
return URL_DELETE_ASSISTANT_STAGING
}
}

type DeleteKnowledgeModelResponse struct {
Success bool `json:"success"`
}

func DeleteAssistant(name string) (*DeleteKnowledgeModelResponse, error) {

knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
assistantControlUrl, err := GetAssistantControlBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.RequestWithoutBodyAndDecode[DeleteKnowledgeModelResponse](
knowledgeControlUrl,
pcio.Sprintf(URL_DELETE_ASSISTANT, name),
assistantControlUrl,
pcio.Sprintf(getDeleteAssistantUrl(), name),
http.MethodDelete,
true,
)
Expand Down
18 changes: 14 additions & 4 deletions internal/pkg/assistants/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,33 @@ package assistants
import (
"fmt"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
)

const (
URL_DESCRIBE_ASSISTANT = "/knowledge/models/%s"
URL_DESCRIBE_ASSISTANT = "/knowledge/models/%s"
URL_DESCRIBE_ASSISTANT_STAGING = "/assistant/assistants/%s"
)

func getDescribeAssistantUrl() string {
if config.Environment.Get() == "production" {
return URL_DESCRIBE_ASSISTANT
} else {
return URL_DESCRIBE_ASSISTANT_STAGING
}
}

func DescribeAssistant(name string) (*AssistantModel, error) {
knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
assistantControlUrl, err := GetAssistantControlBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.GetAndDecode[AssistantModel](
knowledgeControlUrl,
fmt.Sprintf(URL_DESCRIBE_ASSISTANT, name),
assistantControlUrl,
fmt.Sprintf(getDescribeAssistantUrl(), name),
true,
)
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions internal/pkg/assistants/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ package assistants
import (
"encoding/json"

"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/network"
)

const (
URL_LIST_ASSISTANTS = "/knowledge/models"
URL_LIST_ASSISTANTS = "/knowledge/models"
URL_LIST_ASSISTANTS_STAGING = "/assistant/assistants"
)

func getListAssistantsUrl() string {
if config.Environment.Get() == "production" {
return URL_LIST_ASSISTANTS
} else {
return URL_LIST_ASSISTANTS_STAGING
}
}

type AssistantModel struct {
Name string `json:"name"`
Metadata AssistantMetadata `json:"metadata"`
Expand Down Expand Up @@ -44,14 +54,14 @@ type ListAssistantsResponse struct {
}

func ListAssistants() (*ListAssistantsResponse, error) {
knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
assistantControlUrl, err := GetAssistantControlBaseUrl()
if err != nil {
return nil, err
}

resp, err := network.GetAndDecode[ListAssistantsResponse](
knowledgeControlUrl,
URL_LIST_ASSISTANTS,
assistantControlUrl,
getListAssistantsUrl(),
true,
)
if err != nil {
Expand Down
Loading

0 comments on commit 326b2d7

Please sign in to comment.