Skip to content

Commit

Permalink
Use Continue/version as the user-agent in customFetch
Browse files Browse the repository at this point in the history
When continue is frontent by a proxy (such as codegate), the proxy
benefits from knowing who it is that is talking to it instead of a
generic JS user-agent.

This patch enhances the requestOptions with a custom header set to
Continue+version.
  • Loading branch information
jhrozek committed Feb 3, 2025
1 parent da9ec0c commit 2cabcef
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/llm/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as fs from "fs";
import * as path from "path";

import { fetchwithRequestOptions } from "@continuedev/fetch";
import { findLlmInfo } from "@continuedev/llm-info";
import {
Expand Down Expand Up @@ -57,6 +60,9 @@ import {
toFimBody,
} from "./openaiTypeConverters.js";

const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
const VERSION = packageJson.version;

export abstract class BaseLLM implements ILLM {
static providerName: string;
static defaultOptions: Partial<LLMOptions> | undefined = undefined;
Expand Down Expand Up @@ -351,10 +357,18 @@ export abstract class BaseLLM implements ILLM {
// Custom Node.js fetch
const customFetch = async (input: URL | RequestInfo, init: any) => {
try {
const requestOptions = {
...(this.requestOptions ?? {}),
headers: {
...(this.requestOptions?.headers ?? {}),
"User-Agent": `Continue-test/${VERSION}`,
},
};

const resp = await fetchwithRequestOptions(
new URL(input as any),
{ ...init },
{ ...this.requestOptions },
requestOptions,
);

// Error mapping to be more helpful
Expand Down

0 comments on commit 2cabcef

Please sign in to comment.