still works

This commit is contained in:
Josh Yan 2024-07-03 16:43:40 -07:00
parent ad36d4ff1b
commit cbd98a2e37
3 changed files with 15 additions and 25 deletions

View File

@ -367,11 +367,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)
}

View File

@ -262,6 +262,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 {
@ -308,13 +310,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")
@ -330,7 +332,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
@ -380,11 +382,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 {

View File

@ -940,20 +940,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
}