"docs/vscode:/vscode.git/clone" did not exist on "741777b5b5bdfb498173d3911bdf4978b49a12ec"
Unverified Commit 5571ed52 authored by Michael Yang's avatar Michael Yang Committed by GitHub
Browse files

Merge pull request #73 from jmorganca/generate-eof

fix eof error in generate
parents 5028de29 0944b01e
......@@ -59,7 +59,7 @@ func pull(model string) error {
&api.PullRequest{Model: model},
func(progress api.PullProgress) error {
if bar == nil {
if progress.Percent == 100 {
if progress.Percent >= 100 {
// already downloaded
return nil
}
......@@ -73,10 +73,9 @@ func pull(model string) error {
}
func RunGenerate(_ *cobra.Command, args []string) error {
// join all args into a single prompt
prompt := strings.Join(args[1:], " ")
if len(args) > 1 {
return generate(args[0], prompt)
// join all args into a single prompt
return generate(args[0], strings.Join(args[1:], " "))
}
if term.IsTerminal(int(os.Stdin.Fd())) {
......
......@@ -199,10 +199,10 @@ func (llm *llama) generate(tokens []C.llama_token, fn func(string)) error {
token, err := llm.sample(pastTokens, &opts)
switch {
case err != nil:
return err
case errors.Is(err, io.EOF):
return nil
case err != nil:
return err
}
fn(llm.detokenize(token))
......
......@@ -119,25 +119,22 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
}
defer out.Close()
totalSize, _ := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
remaining, _ := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
completed := size
totalBytes := size
totalSize += size
total := remaining + completed
for {
n, err := io.CopyN(out, resp.Body, 8192)
if err != nil && !errors.Is(err, io.EOF) {
return err
fn(total, completed)
if completed >= total {
return os.Rename(model.TempFile(), model.FullName())
}
if n == 0 {
break
n , err := io.CopyN(out, resp.Body, 8192)
if err != nil && !errors.Is(err, io.EOF) {
return err
}
totalBytes += n
fn(totalSize, totalBytes)
completed += n
}
fn(totalSize, totalSize)
return os.Rename(model.TempFile(), model.FullName())
}
......@@ -112,7 +112,7 @@ func pull(c *gin.Context) {
ch <- api.PullProgress{
Total: total,
Completed: completed,
Percent: float64(total) / float64(completed) * 100,
Percent: float64(completed) / float64(total) * 100,
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment