still works
This commit is contained in:
parent
64607d16a5
commit
736ad6f438
@ -358,11 +358,7 @@ func (c *Client) Embeddings(ctx context.Context, req *EmbeddingRequest) (*Embedd
|
||||
|
||||
// CreateBlob creates a blob from a file on the server. digest is the
|
||||
// expected SHA256 digest of the file, and r represents the file.
|
||||
func (c *Client) CreateBlob(ctx context.Context, digest string, local bool, r io.Reader) error {
|
||||
headers := make(http.Header)
|
||||
if local {
|
||||
headers.Set("X-Redirect-Create", "1")
|
||||
}
|
||||
func (c *Client) CreateBlob(ctx context.Context, digest string, r io.Reader) error {
|
||||
return c.do(ctx, http.MethodPost, fmt.Sprintf("/api/blobs/%s", digest), r, nil)
|
||||
}
|
||||
|
||||
|
18
cmd/cmd.go
18
cmd/cmd.go
@ -265,6 +265,8 @@ func tempZipFiles(path string) (string, error) {
|
||||
return tempfile.Name(), nil
|
||||
}
|
||||
|
||||
var ErrBlobExists = errors.New("blob exists")
|
||||
|
||||
func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, error) {
|
||||
bin, err := os.Open(path)
|
||||
if err != nil {
|
||||
@ -311,13 +313,13 @@ func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, er
|
||||
} */
|
||||
if client.IsLocal() {
|
||||
config, err := getLocalPath(cmd.Context(), digest)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
if errors.Is(err, ErrBlobExists) {
|
||||
return digest, nil
|
||||
}
|
||||
|
||||
if config == nil {
|
||||
fmt.Println("config is nil")
|
||||
return digest, nil
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
fmt.Println("HI")
|
||||
@ -333,7 +335,7 @@ func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, er
|
||||
}
|
||||
|
||||
fmt.Println("DEFAULT")
|
||||
if err = client.CreateBlob(cmd.Context(), digest, false, bin); err != nil {
|
||||
if err = client.CreateBlob(cmd.Context(), digest, bin); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return digest, nil
|
||||
@ -383,11 +385,13 @@ func getLocalPath(ctx context.Context, digest string) (*api.ServerConfig, error)
|
||||
fmt.Println("error unmarshalling response data")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &respData, nil
|
||||
}
|
||||
|
||||
fmt.Println("!!!!!!!!!!")
|
||||
fmt.Println(respData)
|
||||
return &respData, nil
|
||||
return nil, ErrBlobExists
|
||||
}
|
||||
|
||||
func createBlobLocal(path string, dest string) error {
|
||||
|
@ -782,20 +782,10 @@ func (s *Server) CreateBlobHandler(c *gin.Context) {
|
||||
c.Status(http.StatusOK)
|
||||
return
|
||||
}
|
||||
fmt.Println("HEIAHOEIHFOAHAEFHAO")
|
||||
fmt.Println(c.GetHeader("X-Redirect-Create"))
|
||||
if c.GetHeader("X-Redirect-Create") == "1" {
|
||||
response := api.ServerConfig{ModelDir: path}
|
||||
fmt.Println("Hit redirect")
|
||||
resp, err := json.Marshal(response)
|
||||
fmt.Println("marshalled response")
|
||||
if err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("loc", string(resp))
|
||||
fmt.Println("!!!!!!!!!", string(resp))
|
||||
if c.GetHeader("X-Redirect-Create") == "1" {
|
||||
c.Header("Location", path)
|
||||
fmt.Println("!!!!!!!!!", string(path))
|
||||
c.Status(http.StatusTemporaryRedirect)
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user