Skip to content

Commit

Permalink
v0.9.7 在日志中添加 [WARNING] 信息
Browse files Browse the repository at this point in the history
  • Loading branch information
x5iu committed Aug 22, 2024
1 parent 3f80c7a commit 35e85c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func logRequest(
latency time.Duration,
tokenFinishLatency time.Duration,
err error,
warnings []error,
) {
if query != "" {
path += "?" + query
Expand Down Expand Up @@ -135,6 +136,11 @@ func logRequest(
}
}
}
if len(warnings) > 0 {
for _, warning := range warnings {
logger.Printf(" %s %s\n", boldYellow("[WARNING]"), boldYellow(warning.Error()))
}
}
}

func _boolToInt(b bool) int {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {
var (
MoonPalace = &cobra.Command{
Use: "moonpalace",
Version: "v0.9.6",
Version: "v0.9.7",
Short: "MoonPalace is a command-line tool for debugging the Moonshot AI HTTP API",
SilenceErrors: true,
SilenceUsage: true,
Expand Down
6 changes: 4 additions & 2 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func buildProxy(
return func(w http.ResponseWriter, r *http.Request) {
var (
err error
warnings []error
encoder = json.NewEncoder(w)
newRequest *http.Request
newResponse *http.Response
Expand Down Expand Up @@ -214,6 +215,7 @@ func buildProxy(
latency,
tokenFinishLatency,
err,
warnings,
)
var lastInsertID int64
lastInsertID, err = persistence.Persistence(
Expand Down Expand Up @@ -388,7 +390,7 @@ func buildProxy(
}
}
if choice.FinishReason != nil && *choice.FinishReason == "length" {
err = errors.New("it seems that your max_tokens value is too small, please set a larger value")
warnings = append(warnings, errors.New("it seems that your max_tokens value is too small, please set a larger value"))
}
if detectRepeat {
var detector *RepeatDetector
Expand All @@ -403,7 +405,7 @@ func buildProxy(
}
detector.Automaton.AddString(choice.Delta.Content)
if detector.Automaton.Length() > repeatMinLength && detector.Automaton.GetRepeatness() < repeatThreshold {
err = errors.New("it appears that there is an issue with content repeating in the current response")
warnings = append(warnings, errors.New("it appears that there is an issue with content repeating in the current response"))
for index, snapshot := range detectors {
if snapshot.FinishReason == "" {
finishChunk := []byte(fmt.Sprintf(
Expand Down

0 comments on commit 35e85c3

Please sign in to comment.