Skip to content

Commit 326b2d7

Browse files
update staging URL with new naming schema, add helpers for staging vs production targeting
1 parent ecdd185 commit 326b2d7

11 files changed

+132
-42
lines changed

internal/pkg/assistants/assistant_chat_completions.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,26 @@ package assistants
33
import (
44
"fmt"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/state"
78
"github.com/pinecone-io/cli/internal/pkg/utils/log"
89
"github.com/pinecone-io/cli/internal/pkg/utils/models"
910
"github.com/pinecone-io/cli/internal/pkg/utils/network"
1011
)
1112

1213
const (
13-
URL_ASSISTANT_CHAT_COMPLETIONS = "/knowledge/chat/%s/chat/completions"
14+
URL_ASSISTANT_CHAT_COMPLETIONS = "/knowledge/chat/%s/chat/completions"
15+
URL_ASSISTANT_CHAT_COMPLETIONS_STAGING = "/assistant/chat/%s/chat/completions"
1416
)
1517

18+
func getAssistantChatCompletionsUrl() string {
19+
if config.Environment.Get() == "production" {
20+
return URL_ASSISTANT_CHAT_COMPLETIONS
21+
} else {
22+
return URL_ASSISTANT_CHAT_COMPLETIONS_STAGING
23+
}
24+
}
25+
1626
func GetAssistantChatCompletions(kmName string, msg string) (*models.ChatCompletionModel, error) {
1727
outgoingMsg := models.ChatCompletionMessage{
1828
Role: "user",
@@ -32,14 +42,14 @@ func GetAssistantChatCompletions(kmName string, msg string) (*models.ChatComplet
3242
Messages: chat.Messages,
3343
}
3444

35-
knowledgeDataUrl, err := GetKnowledgeDataBaseUrl()
45+
assistantDataUrl, err := GetAssistantDataBaseUrl()
3646
if err != nil {
3747
return nil, err
3848
}
3949

4050
resp, err := network.PostAndDecode[models.ChatCompletionRequest, models.ChatCompletionModel](
41-
knowledgeDataUrl,
42-
fmt.Sprintf(URL_ASSISTANT_CHAT_COMPLETIONS, kmName),
51+
assistantDataUrl,
52+
fmt.Sprintf(getAssistantChatCompletionsUrl(), kmName),
4353
true,
4454
body,
4555
)

internal/pkg/assistants/assistant_file_delete.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@ package assistants
33
import (
44
"net/http"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/network"
78
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
89
)
910

1011
const (
11-
URL_DELETE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
12+
URL_DELETE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
13+
URL_DELETE_ASSISTANT_FILE_STAGING = "/assistant/files/%s/%s"
1214
)
1315

16+
func getDeleteAssistantFileUrl() string {
17+
if config.Environment.Get() == "production" {
18+
return URL_DELETE_ASSISTANT_FILE
19+
} else {
20+
return URL_DELETE_ASSISTANT_FILE_STAGING
21+
}
22+
}
23+
1424
type DeleteAssistantFileResponse string
1525

1626
func DeleteKnowledgeFile(kmName string, fileId string) (*DeleteAssistantFileResponse, error) {
17-
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
27+
assistantDataUrl, err := GetAssistantDataBaseUrl()
1828
if err != nil {
1929
return nil, err
2030
}
2131

2232
resp, err := network.RequestWithoutBodyAndDecode[DeleteAssistantFileResponse](
2333
assistantDataUrl,
24-
pcio.Sprintf(URL_DELETE_ASSISTANT_FILE, kmName, fileId),
34+
pcio.Sprintf(getDeleteAssistantFileUrl(), kmName, fileId),
2535
http.MethodDelete,
2636
true,
2737
)

internal/pkg/assistants/assistant_file_get.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,34 @@ package assistants
33
import (
44
"fmt"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
78
"github.com/pinecone-io/cli/internal/pkg/utils/log"
89
"github.com/pinecone-io/cli/internal/pkg/utils/network"
910
)
1011

1112
const (
12-
URL_DESCRIBE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
13+
URL_DESCRIBE_ASSISTANT_FILE = "/knowledge/files/%s/%s"
14+
URL_DESCRIBE_ASSISTANT_FILE_STAGING = "/assistant/files/%s/%s"
1315
)
1416

17+
func getDescribeAssistantFileUrl() string {
18+
if config.Environment.Get() == "production" {
19+
return URL_DESCRIBE_ASSISTANT_FILE
20+
} else {
21+
return URL_DESCRIBE_ASSISTANT_FILE_STAGING
22+
}
23+
}
24+
1525
func DescribeAssistantFile(name string, fileId string) (*AssistantFileModel, error) {
16-
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
26+
assistantDataUrl, err := GetAssistantDataBaseUrl()
1727
if err != nil {
1828
return nil, err
1929
}
2030

2131
resp, err := network.GetAndDecode[AssistantFileModel](
2232
assistantDataUrl,
23-
fmt.Sprintf(URL_DESCRIBE_ASSISTANT_FILE, name, fileId),
33+
fmt.Sprintf(getDescribeAssistantFileUrl(), name, fileId),
2434
true,
2535
)
2636
if err != nil {

internal/pkg/assistants/assistant_file_upload.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,32 @@ package assistants
33
import (
44
"fmt"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/network"
78
)
89

910
const (
10-
URL_ASSISTANT_FILE_UPLOAD = "/knowledge/files/%s"
11+
URL_ASSISTANT_FILE_UPLOAD = "/knowledge/files/%s"
12+
URL_ASSISTANT_FILE_UPLOAD_STAGING = "/assistant/files/%s"
1113
)
1214

15+
func getAssistantFileUploadUrl() string {
16+
if config.Environment.Get() == "production" {
17+
return URL_ASSISTANT_FILE_UPLOAD
18+
} else {
19+
return URL_ASSISTANT_FILE_UPLOAD_STAGING
20+
}
21+
}
22+
1323
func UploadAssistantFile(name string, filePath string) (*AssistantFileModel, error) {
14-
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
24+
assistantDataUrl, err := GetAssistantDataBaseUrl()
1525
if err != nil {
1626
return nil, err
1727
}
1828

1929
resp, err := network.PostAndDecodeMultipartFormData[AssistantFileModel](
2030
assistantDataUrl,
21-
fmt.Sprintf(URL_ASSISTANT_FILE_UPLOAD, name),
31+
fmt.Sprintf(getAssistantFileUploadUrl(), name),
2232
true,
2333
filePath,
2434
)

internal/pkg/assistants/assistant_files_list.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ package assistants
33
import (
44
"fmt"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/log"
78
"github.com/pinecone-io/cli/internal/pkg/utils/network"
89
)
910

1011
const (
11-
URL_LIST_ASSISTANT_FILES = "/knowledge/files/%s"
12+
URL_LIST_ASSISTANT_FILES = "/knowledge/files/%s"
13+
URL_LIST_ASSISTANT_FILES_STAGING = "/assistant/files/%s"
1214
)
1315

16+
func getListAssistantFilesUrl() string {
17+
if config.Environment.Get() == "production" {
18+
return URL_LIST_ASSISTANT_FILES
19+
} else {
20+
return URL_LIST_ASSISTANT_FILES_STAGING
21+
}
22+
}
23+
1424
type AssistantFileModel struct {
1525
Name string `json:"name"`
1626
Id string `json:"id"`
@@ -33,14 +43,14 @@ type ListAssistantFilesResponse struct {
3343
}
3444

3545
func ListAssistantFiles(name string) (*ListAssistantFilesResponse, error) {
36-
assistantDataUrl, err := GetKnowledgeDataBaseUrl()
46+
assistantDataUrl, err := GetAssistantDataBaseUrl()
3747
if err != nil {
3848
return nil, err
3949
}
4050

4151
resp, err := network.GetAndDecode[ListAssistantFilesResponse](
4252
assistantDataUrl,
43-
fmt.Sprintf(URL_LIST_ASSISTANT_FILES, name),
53+
fmt.Sprintf(getListAssistantFilesUrl(), name),
4454
true,
4555
)
4656
if err != nil {

internal/pkg/assistants/constants.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import (
55
"github.com/pinecone-io/cli/internal/pkg/utils/environment"
66
)
77

8-
func GetKnowledgeDataBaseUrl() (string, error) {
8+
func GetAssistantDataBaseUrl() (string, error) {
99
connectionConfigs, err := environment.GetEnvConfig(config.Environment.Get())
1010
if err != nil {
1111
return "", err
1212
}
13-
return connectionConfigs.KnowledgeDataPlaneUrl, nil
13+
return connectionConfigs.AssistantDataPlaneUrl, nil
1414
}
1515

16-
func GetKnowledgeControlBaseUrl() (string, error) {
16+
func GetAssistantControlBaseUrl() (string, error) {
1717
connectionConfigs, err := environment.GetEnvConfig(config.Environment.Get())
1818
if err != nil {
1919
return "", err
2020
}
21-
return connectionConfigs.KnowledgeControlPlaneUrl, nil
21+
return connectionConfigs.AssistantControlPlaneUrl, nil
2222
}

internal/pkg/assistants/create.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package assistants
22

33
import (
4+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
45
"github.com/pinecone-io/cli/internal/pkg/utils/network"
56
)
67

78
const (
8-
URL_CREATE_ASSISTANT = "/knowledge/models"
9+
URL_CREATE_ASSISTANT = "/knowledge/models"
10+
URL_CREATE_ASSISTANT_STAGING = "/assistant/assistants"
911
)
1012

13+
func getCreateAssistantUrl() string {
14+
if config.Environment.Get() == "production" {
15+
return URL_CREATE_ASSISTANT
16+
} else {
17+
return URL_CREATE_ASSISTANT_STAGING
18+
}
19+
}
20+
1121
type CreateAssistantRequest struct {
1222
Name string `json:"name"`
1323
Metadata map[string]interface{} `json:"metadata"`
@@ -18,14 +28,14 @@ func CreateAssistant(name string) (*AssistantModel, error) {
1828
Name: name,
1929
}
2030

21-
knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
31+
assistantControlUrl, err := GetAssistantControlBaseUrl()
2232
if err != nil {
2333
return nil, err
2434
}
2535

2636
resp, err := network.PostAndDecode[CreateAssistantRequest, AssistantModel](
27-
knowledgeControlUrl,
28-
URL_CREATE_ASSISTANT,
37+
assistantControlUrl,
38+
getCreateAssistantUrl(),
2939
true,
3040
body,
3141
)

internal/pkg/assistants/delete.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,38 @@ package assistants
33
import (
44
"net/http"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/network"
78
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
89
)
910

1011
const (
11-
URL_DELETE_ASSISTANT = "/knowledge/models/%s"
12+
URL_DELETE_ASSISTANT = "/knowledge/models/%s"
13+
URL_DELETE_ASSISTANT_STAGING = "/assistant/assistants/%s"
1214
)
1315

16+
func getDeleteAssistantUrl() string {
17+
if config.Environment.Get() == "production" {
18+
return URL_DELETE_ASSISTANT
19+
} else {
20+
return URL_DELETE_ASSISTANT_STAGING
21+
}
22+
}
23+
1424
type DeleteKnowledgeModelResponse struct {
1525
Success bool `json:"success"`
1626
}
1727

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

20-
knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
30+
assistantControlUrl, err := GetAssistantControlBaseUrl()
2131
if err != nil {
2232
return nil, err
2333
}
2434

2535
resp, err := network.RequestWithoutBodyAndDecode[DeleteKnowledgeModelResponse](
26-
knowledgeControlUrl,
27-
pcio.Sprintf(URL_DELETE_ASSISTANT, name),
36+
assistantControlUrl,
37+
pcio.Sprintf(getDeleteAssistantUrl(), name),
2838
http.MethodDelete,
2939
true,
3040
)

internal/pkg/assistants/get.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,33 @@ package assistants
33
import (
44
"fmt"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/log"
78
"github.com/pinecone-io/cli/internal/pkg/utils/network"
89
)
910

1011
const (
11-
URL_DESCRIBE_ASSISTANT = "/knowledge/models/%s"
12+
URL_DESCRIBE_ASSISTANT = "/knowledge/models/%s"
13+
URL_DESCRIBE_ASSISTANT_STAGING = "/assistant/assistants/%s"
1214
)
1315

16+
func getDescribeAssistantUrl() string {
17+
if config.Environment.Get() == "production" {
18+
return URL_DESCRIBE_ASSISTANT
19+
} else {
20+
return URL_DESCRIBE_ASSISTANT_STAGING
21+
}
22+
}
23+
1424
func DescribeAssistant(name string) (*AssistantModel, error) {
15-
knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
25+
assistantControlUrl, err := GetAssistantControlBaseUrl()
1626
if err != nil {
1727
return nil, err
1828
}
1929

2030
resp, err := network.GetAndDecode[AssistantModel](
21-
knowledgeControlUrl,
22-
fmt.Sprintf(URL_DESCRIBE_ASSISTANT, name),
31+
assistantControlUrl,
32+
fmt.Sprintf(getDescribeAssistantUrl(), name),
2333
true,
2434
)
2535
if err != nil {

internal/pkg/assistants/list.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ package assistants
33
import (
44
"encoding/json"
55

6+
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/config"
67
"github.com/pinecone-io/cli/internal/pkg/utils/log"
78
"github.com/pinecone-io/cli/internal/pkg/utils/network"
89
)
910

1011
const (
11-
URL_LIST_ASSISTANTS = "/knowledge/models"
12+
URL_LIST_ASSISTANTS = "/knowledge/models"
13+
URL_LIST_ASSISTANTS_STAGING = "/assistant/assistants"
1214
)
1315

16+
func getListAssistantsUrl() string {
17+
if config.Environment.Get() == "production" {
18+
return URL_LIST_ASSISTANTS
19+
} else {
20+
return URL_LIST_ASSISTANTS_STAGING
21+
}
22+
}
23+
1424
type AssistantModel struct {
1525
Name string `json:"name"`
1626
Metadata AssistantMetadata `json:"metadata"`
@@ -44,14 +54,14 @@ type ListAssistantsResponse struct {
4454
}
4555

4656
func ListAssistants() (*ListAssistantsResponse, error) {
47-
knowledgeControlUrl, err := GetKnowledgeControlBaseUrl()
57+
assistantControlUrl, err := GetAssistantControlBaseUrl()
4858
if err != nil {
4959
return nil, err
5060
}
5161

5262
resp, err := network.GetAndDecode[ListAssistantsResponse](
53-
knowledgeControlUrl,
54-
URL_LIST_ASSISTANTS,
63+
assistantControlUrl,
64+
getListAssistantsUrl(),
5565
true,
5666
)
5767
if err != nil {

0 commit comments

Comments
 (0)