Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jansorg committed Jan 8, 2025
1 parent 47938bd commit bb11a0e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ public void end() {
channelHandlerContext.channel(),
new ReadOnlyHttpHeaders(true,
HttpHeaderNames.CONTENT_TYPE, "application/json",
"openai-organization", GitHubCopilot.OPEN_AI_ORGANIZATION,
"openai-version", GitHubCopilot.OPEN_AI_VERSION,
"x-request-id", CopilotChatSession.requestId()));
GitHubCopilot.HEADER_OPENAI_ORGANIZATION, GitHubCopilot.OPEN_AI_ORGANIZATION,
GitHubCopilot.HEADER_OPENAI_VERSION, GitHubCopilot.OPEN_AI_VERSION,
GitHubCopilot.HEADER_REQUEST_ID, CopilotChatSession.requestId()));
}
};

Expand Down Expand Up @@ -282,6 +282,10 @@ private static boolean isEqualByHash(@NotNull String expectedValue, @NotNull Str
return MessageDigest.isEqual(expectedValue.getBytes(StandardCharsets.UTF_8), value.getBytes(StandardCharsets.UTF_8));
}

/**
* Handle a server error response from GitHub Copilot.
* If the Copilot API sent a "context token overflow" error, we convert it into a suitable error response for Navie.
*/
private static void handleHttpServerError(@NotNull FullHttpRequest fullHttpRequest,
@NotNull Exception exception,
@NotNull CopilotModelDefinition copilotModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public void ask(@NotNull CopilotChatResponseListener responseListener,
.isReadResponseOnError(true)
.tuner(connection -> {
applyHeaders(connection, baseHeaders);
connection.setRequestProperty("openai-intent", "conversation-panel");
connection.setRequestProperty("openai-organization", "github-copilot");
connection.setRequestProperty("x-request-id", requestId());
connection.setRequestProperty(GitHubCopilot.HEADER_OPENAI_INTENT, "conversation-panel");
connection.setRequestProperty(GitHubCopilot.HEADER_OPENAI_ORGANIZATION, "github-copilot");
connection.setRequestProperty(GitHubCopilot.HEADER_REQUEST_ID, requestId());
})
.connect(httpRequest -> {
httpRequest.write(GsonUtils.GSON.toJson(copilotRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public final class GitHubCopilot {
public static final String CHAT_FALLBACK_MODEL_NAME = "gpt-4o";
public static final double CHAT_DEFAULT_TEMPERATURE = 0.1;

// HTTP header names used by GitHub Copilot
public static final String HEADER_OPENAI_ORGANIZATION = "openai-organization";
public static final String HEADER_OPENAI_VERSION = "openai-version";
public static final String HEADER_REQUEST_ID = "x-request-id";
public static final String HEADER_OPENAI_INTENT = "openai-intent";

private GitHubCopilot() {
}
}

0 comments on commit bb11a0e

Please sign in to comment.