fix: honor registered DeepSeek endpoint

This commit is contained in:
冰朔 2026-08-05 11:14:10 +08:00
commit 380fca2b9f
2 changed files with 24 additions and 3 deletions

View file

@ -1,5 +1,11 @@
const DEFAULT_TIMEOUT_MS = 45_000;
function completionEndpoint(apiUrl) {
const value = String(apiUrl || "").replace(/\/+$/, "");
if (/\/chat\/completions$/i.test(value)) return value;
return `${value}/chat/completions`;
}
function extractJson(text) {
const value = String(text || "").trim();
if (!value) throw new Error("model_response_empty");
@ -36,7 +42,7 @@ export class DeepSeekJsonClient {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
try {
const response = await this.fetchImpl(`${this.apiUrl}/chat/completions`, {
const response = await this.fetchImpl(completionEndpoint(this.apiUrl), {
method: "POST",
headers: {
authorization: `Bearer ${this.apiKey}`,
@ -78,4 +84,4 @@ export class DeepSeekJsonClient {
}
}
export { extractJson };
export { completionEndpoint, extractJson };