still works

This commit is contained in:
Josh Yan 2024-07-03 16:43:40 -07:00
parent 03df02883d
commit d14d38e940
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 // CreateBlob creates a blob from a file on the server. digest is the
// expected SHA256 digest of the file, and r represents the file. // 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 { func (c *Client) CreateBlob(ctx context.Context, digest string, r io.Reader) error {
headers := make(http.Header)
if local {
headers.Set("X-Redirect-Create", "1")
}
return c.do(ctx, http.MethodPost, fmt.Sprintf("/api/blobs/%s", digest), r, nil) 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 return tempfile.Name(), nil
} }
var ErrBlobExists = errors.New("blob exists")
func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, error) { func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, error) {
bin, err := os.Open(path) bin, err := os.Open(path)
if err != nil { if err != nil {
@ -308,13 +310,13 @@ func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, er
} */ } */
if client.IsLocal() { if client.IsLocal() {
config, err := getLocalPath(cmd.Context(), digest) config, err := getLocalPath(cmd.Context(), digest)
if err != nil {
return "", err if errors.Is(err, ErrBlobExists) {
return digest, nil
} }
if config == nil { if err != nil {
fmt.Println("config is nil") return "", err
return digest, nil
} }
fmt.Println("HI") fmt.Println("HI")
@ -330,7 +332,7 @@ func createBlob(cmd *cobra.Command, client *api.Client, path string) (string, er
} }
fmt.Println("DEFAULT") 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 "", err
} }
return digest, nil return digest, nil
@ -380,11 +382,13 @@ func getLocalPath(ctx context.Context, digest string) (*api.ServerConfig, error)
fmt.Println("error unmarshalling response data") fmt.Println("error unmarshalling response data")
return nil, err return nil, err
} }
return &respData, nil
} }
fmt.Println("!!!!!!!!!!") fmt.Println("!!!!!!!!!!")
fmt.Println(respData) fmt.Println(respData)
return &respData, nil return nil, ErrBlobExists
} }
func createBlobLocal(path string, dest string) error { func createBlobLocal(path string, dest string) error {

View File

@ -940,20 +940,10 @@ func (s *Server) CreateBlobHandler(c *gin.Context) {
c.Status(http.StatusOK) c.Status(http.StatusOK)
return 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)) if c.GetHeader("X-Redirect-Create") == "1" {
fmt.Println("!!!!!!!!!", string(resp)) c.Header("Location", path)
fmt.Println("!!!!!!!!!", string(path))
c.Status(http.StatusTemporaryRedirect) c.Status(http.StatusTemporaryRedirect)
return return
} }