Skip to content

Commit

Permalink
Improve error parsing logic in CLAUDE response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jun 16, 2024
1 parent 36f26e6 commit 193dbb6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/CommitMessageGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,31 @@ std::vector<std::string> CommitMessageGenerator::parse_openai_response(std::stri
} else if (r.match("{choices[{message{content")) {
text = decode_json_string(r.string());
} else if (r.match("{error{type")) {
error_status_ = r.string();
ok1 = false;
} else if (r.match("{error{message")) {
error_message_ = r.string();
return {};
ok1 = false;
}
}
} else if (ai_type == GenerativeAI::CLAUDE) {
while (r.next()) {
fprintf(stderr, "%d\n", r.path().c_str());
fflush(stderr);
if (r.match("{stop_reason")) {
if (r.string() == "end_turn") {
ok1 = true;
}
} else if (r.match("{content[{text")) {
text = decode_json_string(r.string());
// } else if (r.match("{error{type")) {
// error_ = r.string();
// return {};
} else if (r.match("{type")) {
if (r.string() == "error") {
ok1 = false;
}
} else if (r.match("{error{type")) {
error_status_ = r.string();
ok1 = false;
} else if (r.match("{error{message")) {
error_message_ = r.string();
ok1 = false;
}
}
} else if (ai_type == GenerativeAI::GEMINI) {
Expand Down

0 comments on commit 193dbb6

Please sign in to comment.