diff --git a/plugin-copilot/src/main/java/appland/copilotChat/NavieCopilotChatRequestHandler.java b/plugin-copilot/src/main/java/appland/copilotChat/NavieCopilotChatRequestHandler.java index 3b0381db..2467091e 100644 --- a/plugin-copilot/src/main/java/appland/copilotChat/NavieCopilotChatRequestHandler.java +++ b/plugin-copilot/src/main/java/appland/copilotChat/NavieCopilotChatRequestHandler.java @@ -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())); } }; @@ -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, diff --git a/plugin-copilot/src/main/java/appland/copilotChat/copilot/CopilotChatSession.java b/plugin-copilot/src/main/java/appland/copilotChat/copilot/CopilotChatSession.java index 7fde5bff..94b4fbd1 100644 --- a/plugin-copilot/src/main/java/appland/copilotChat/copilot/CopilotChatSession.java +++ b/plugin-copilot/src/main/java/appland/copilotChat/copilot/CopilotChatSession.java @@ -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)); diff --git a/plugin-copilot/src/main/java/appland/copilotChat/copilot/GitHubCopilot.java b/plugin-copilot/src/main/java/appland/copilotChat/copilot/GitHubCopilot.java index c6207feb..90effa21 100644 --- a/plugin-copilot/src/main/java/appland/copilotChat/copilot/GitHubCopilot.java +++ b/plugin-copilot/src/main/java/appland/copilotChat/copilot/GitHubCopilot.java @@ -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() { } }