Skip to content

Commit

Permalink
Fix in server
Browse files Browse the repository at this point in the history
  • Loading branch information
synw committed Jan 24, 2025
1 parent 1c93cfc commit 421b22e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
17 changes: 16 additions & 1 deletion server/lm/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os/exec"
"strings"

"github.com/labstack/echo/v4"
"github.com/synw/agent-smith/server/state"
Expand Down Expand Up @@ -51,11 +52,13 @@ func RunCmd(
enc := json.NewEncoder(c.Response())
enc.SetEscapeHTML(false)
i := 0
buf := []string{}
for scanner.Scan() {
i++
token := scanner.Text()
buf = append(buf, token)
if state.IsVerbose {
fmt.Print(token)
go fmt.Print(token)
}
StreamMsg(createMsg(token, i), c, enc)
}
Expand All @@ -71,5 +74,17 @@ func RunCmd(
if err := cmd.Wait(); err != nil {
msg := fmt.Errorf("Command finished with error: %v", err)
errCh <- createErrorMsg(msg.Error())
} else {
//fmt.Println("Command finished")
res := make(map[string]interface{})
res["text"] = strings.Join(buf, "")
endmsg := types.StreamedMessage{
Num: 0,
Content: "result",
MsgType: types.SystemMsgType,
Data: res,
}
StreamMsg(endmsg, c, enc)
ch <- endmsg
}
}
7 changes: 5 additions & 2 deletions server/lm/oai.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ func OaiInfer(
ntokens := 0
for {
response, err := stream.Recv()
fmt.Println("SERR", err)
fmt.Println("RESP", response)
if errors.Is(err, io.EOF) {
//fmt.Println("\nStream finished")
fmt.Println("\nStream EOF")
emittingElapsed := time.Since(startEmitting)
if state.IsVerbose {
fmt.Println("\n\nEmitting time:", emittingElapsed)
Expand Down Expand Up @@ -155,7 +157,7 @@ func OaiInfer(
}
StreamMsg(endmsg, c, enc)
ch <- endmsg
return nil
break
}
if err != nil {
fmt.Printf("\nStream error: %v\n", err)
Expand Down Expand Up @@ -203,4 +205,5 @@ func OaiInfer(
}
ntokens++
}
return nil
}

0 comments on commit 421b22e

Please sign in to comment.