Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"telegramify-markdown": "^1.3.0",
"tmp": "^0.2.3",
"tsx": "^4.20.3",
"undici": "^7.11.0",
"zod": "^3.25.76"
},
"devDependencies": {
Expand Down
14 changes: 7 additions & 7 deletions src/helpers/useApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import OpenAI, { ClientOptions } from "openai";
import { HttpsProxyAgent } from "https-proxy-agent";
import OpenAI from "openai";
import { ProxyAgent } from "undici";
import { useConfig } from "../config";

const apiCache: Record<string, OpenAI> = {};
Expand All @@ -8,8 +8,8 @@ export function useApi(localModel?: string): OpenAI {
const cacheKey = localModel || "default";
if (!apiCache[cacheKey]) {
const config = useConfig();
const httpAgent = config.auth.proxy_url
? new HttpsProxyAgent(`${config.auth.proxy_url}`)
const proxyAgent = config.auth.proxy_url
? new ProxyAgent(config.auth.proxy_url)
: undefined;

if (localModel) {
Expand All @@ -18,13 +18,13 @@ export function useApi(localModel?: string): OpenAI {
apiCache[cacheKey] = new OpenAI({
baseURL: `${model.url}/v1`,
apiKey: config.auth.chatgpt_api_key,
// httpAgent,
...(proxyAgent ? { fetchOptions: { dispatcher: proxyAgent } } : {}),
});
} else {
apiCache[cacheKey] = new OpenAI({
apiKey: config.auth.chatgpt_api_key,
httpAgent,
} as unknown as ClientOptions & { httpAgent: unknown });
...(proxyAgent ? { fetchOptions: { dispatcher: proxyAgent } } : {}),
});
}
}
return apiCache[cacheKey];
Expand Down