Skip to content

Commit

Permalink
better error messages for model response issues, closes #187 and #188
Browse files Browse the repository at this point in the history
  • Loading branch information
danenania committed Oct 2, 2024
1 parent d345ab4 commit a01ca11
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions app/server/model/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func GenPlanName(

if res == "" {
fmt.Println("no namePlan function call found in response")
return "", err
return "", fmt.Errorf("No namePlan function call found in response. This usually means the model failed to generate a valid response.")
}

bytes := []byte(res)
Expand Down Expand Up @@ -271,7 +271,7 @@ func GenPipedDataName(

if res == "" {
fmt.Println("no namePipedData function call found in response")
return "", err
return "", fmt.Errorf("No namePipedData function call found in response. This usually means the model failed to generate a valid response.")
}

bytes := []byte(res)
Expand Down Expand Up @@ -413,7 +413,7 @@ func GenNoteName(

if res == "" {
fmt.Println("no nameNote function call found in response")
return "", err
return "", fmt.Errorf("No nameNote function call found in response. This usually means the model failed to generate a valid response.")
}

bytes := []byte(res)
Expand Down
4 changes: 2 additions & 2 deletions app/server/model/plan/build_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {

if s == "" {
log.Println("no ListReplacements function call found in response")
fileState.lineNumsRetryOrError(fmt.Errorf("no ListReplacements function call found in response"))
fileState.lineNumsRetryOrError(fmt.Errorf("No ListReplacements function call found in response. This usually means the model failed to generate a valid response."))
return
}

Expand All @@ -428,7 +428,7 @@ func (fileState *activeBuildStreamFileState) buildFileLineNums() {
err = json.Unmarshal(bytes, &res)
if err != nil {
log.Printf("Error unmarshalling build response: %v\n", err)
fileState.lineNumsRetryOrError(fmt.Errorf("error unmarshalling build response: %v", err))
fileState.lineNumsRetryOrError(fmt.Errorf("Error unmarshalling build response: %v | This usually means the model failed to generate valid JSON.", err))
return
}

Expand Down
4 changes: 2 additions & 2 deletions app/server/model/plan/build_fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (fileState *activeBuildStreamFileState) fixFileLineNums() {

if s == "" {
log.Println("no ListReplacements function call found in response")
fileState.fixRetryOrAbort(fmt.Errorf("no ListReplacements function call found in response"))
fileState.fixRetryOrAbort(fmt.Errorf("No ListReplacements function call found in response. This usually means the model failed to generate a valid response."))
return
}

Expand All @@ -181,7 +181,7 @@ func (fileState *activeBuildStreamFileState) fixFileLineNums() {
err = json.Unmarshal(bytes, &res)
if err != nil {
log.Printf("Error unmarshalling fix response: %v\n", err)
fileState.fixRetryOrAbort(fmt.Errorf("error unmarshalling fix response: %v", err))
fileState.fixRetryOrAbort(fmt.Errorf("Error unmarshalling fix response: %v | This usually means the model failed to generate valid JSON.", err))
return
}

Expand Down
10 changes: 5 additions & 5 deletions app/server/model/plan/build_fix_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open
return
}

fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream timeout due to inactivity for file '%s'", filePath))
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream timeout due to inactivity for file '%s' | This usually means the model is not responding.", filePath))
return
default:
response, err := stream.Recv()
Expand Down Expand Up @@ -149,7 +149,7 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open
}

execHookOnStop(true)
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream error: no choices"))
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream error: no choices | This usually means the model failed to generate a valid response."))
return
}

Expand All @@ -170,7 +170,7 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open
if trimmed == "{%invalidjson%}" || trimmed == "``(no output)``````" {
log.Println("listenStreamFixChanges - File", filePath+":", "%invalidjson%} token in streamed chunk")
execHookOnStop(true)
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - invalid JSON in streamed chunk for file '%s'", filePath))
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - invalid JSON in streamed chunk for file '%s' | This usually means the model failed to generate valid JSON.", filePath))
return
}

Expand Down Expand Up @@ -201,7 +201,7 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open
log.Println(fileState.activeBuild.FixBuffer)

execHookOnStop(true)
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream buffer tokens too high for file '%s'", filePath))
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream buffer tokens too high for file '%s' | This usually means the model failed to generate valid JSON.", filePath))
return
}
}
Expand All @@ -228,7 +228,7 @@ func (fileState *activeBuildStreamFileState) listenStreamFixChanges(stream *open
log.Printf("listenStreamFixChanges - File %s: Stream chunk missing function call. Reason: %s\n", filePath, choice.FinishReason)

execHookOnStop(true)
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream chunk missing function call. File: %s", filePath))
fileState.fixRetryOrAbort(fmt.Errorf("listenStreamFixChanges - stream chunk missing function call. File: %s | This usually means the model failed to generate a valid response.", filePath))
return
}
}
Expand Down
10 changes: 5 additions & 5 deletions app/server/model/plan/build_stream_line_nums.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str
return
}

fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream timeout due to inactivity for file '%s'", filePath))
fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream timeout due to inactivity for file '%s' | This usually means the model is not responding.", filePath))
return
default:
response, err := stream.Recv()
Expand Down Expand Up @@ -153,7 +153,7 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str
}

execHookOnStop(true)
fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream error: no choices"))
fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream error: no choices | This usually means the model failed to generate a valid response."))
return
}

Expand All @@ -174,7 +174,7 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str
if trimmed == "{%invalidjson%}" || trimmed == "``(no output)``````" {
log.Println("File", filePath+":", "%invalidjson%} token in streamed chunk")
execHookOnStop(true)
fileState.lineNumsRetryOrError(fmt.Errorf("invalid JSON in streamed chunk for file '%s'", filePath))
fileState.lineNumsRetryOrError(fmt.Errorf("Invalid JSON in streamed chunk for file '%s' | This usually means the model failed to generate valid JSON.", filePath))
return
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str
log.Println(fileState.activeBuild.WithLineNumsBuffer)

execHookOnStop(true)
fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream buffer tokens too high for file '%s'", filePath))
fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream buffer tokens too high for file '%s' | This usually means the model failed to generate valid JSON.", filePath))
return
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ func (fileState *activeBuildStreamFileState) listenStreamChangesWithLineNums(str
// log.Println(fileState.activeBuild.WithLineNumsBuffer)

execHookOnStop(true)
fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream chunk missing function call. Reason: %s, File: %s", choice.FinishReason, filePath))
fileState.lineNumsRetryOrError(fmt.Errorf("listenStream - stream chunk missing function call. Reason: %s, File: %s | This usually means the model failed to generate a valid response.", choice.FinishReason, filePath))
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/server/model/plan/build_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (fileState *activeBuildStreamFileState) verifyFileBuild() {

if s == "" {
log.Println("no VerifyOutput function call found in response")
fileState.verifyRetryOrAbort(fmt.Errorf("no Verify Output function call found in response"))
fileState.verifyRetryOrAbort(fmt.Errorf("No VerifyOutput function call found in response. This usually means the model failed to generate a valid response."))
return
}

Expand Down
4 changes: 2 additions & 2 deletions app/server/model/plan/build_verify_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
return
}

fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream timeout due to inactivity for file '%s'", filePath))
fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream timeout due to inactivity for file '%s' | This usually means the model is not responding.", filePath))
return
default:
response, err := stream.Recv()
Expand Down Expand Up @@ -150,7 +150,7 @@ func (fileState *activeBuildStreamFileState) listenStreamVerifyOutput(stream *op
}

execHookOnStop(true)
fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream error: no choices"))
fileState.verifyRetryOrAbort(fmt.Errorf("listenStreamVerifyOutput - stream error: no choices | This usually means the model failed to generate a valid response."))
return
}

Expand Down
2 changes: 1 addition & 1 deletion app/server/model/plan/commit_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (state *activeTellStreamState) genPlanDescription() (*db.ConvoMessageDescri

if descStrRes == "" {
fmt.Println("no describePlan function call found in response")
return nil, fmt.Errorf("no describePlan function call found in response")
return nil, fmt.Errorf("No describePlan function call found in response. This usually means the model failed to generate a valid response.")
}

descByteRes := []byte(descStrRes)
Expand Down
6 changes: 3 additions & 3 deletions app/server/model/plan/tell_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mainLoop:
execHookOnStop(true)
return
} else {
state.onError(fmt.Errorf("stream timeout due to inactivity"), true, "", "")
state.onError(fmt.Errorf("stream timeout due to inactivity | This usually means the model is not responding."), true, "", "")
continue mainLoop
}

Expand Down Expand Up @@ -166,7 +166,7 @@ mainLoop:
return
}

state.onError(fmt.Errorf("stream finished with no choices"), true, "", "")
state.onError(fmt.Errorf("stream finished with no choices | This usually means the model failed to generate a valid response."), true, "", "")
continue mainLoop
}

Expand All @@ -177,7 +177,7 @@ mainLoop:
}

if len(response.Choices) > 1 {
state.onError(fmt.Errorf("stream finished with more than one choice"), true, "", "")
state.onError(fmt.Errorf("stream finished with more than one choice | This usually means the model failed to generate a valid response."), true, "", "")
continue mainLoop
}

Expand Down
2 changes: 1 addition & 1 deletion app/server/model/summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func PlanSummary(client *openai.Client, config shared.ModelRoleConfig, params Pl
}

if len(resp.Choices) == 0 {
return nil, fmt.Errorf("no response from GPT")
return nil, fmt.Errorf("plan summary - no choices in response. This usually means the model failed to generate a valid response.")
}

content := resp.Choices[0].Message.Content
Expand Down

0 comments on commit a01ca11

Please sign in to comment.