🩹 don't automatically append /v1 to apiBase
This commit is contained in:
parent
1d2eee5c00
commit
de8ccb0ac8
4 changed files with 11 additions and 16 deletions
|
|
@ -16,13 +16,10 @@ class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider {
|
|||
if (apiBase?.endsWith("/")) {
|
||||
apiBase = apiBase.slice(0, -1);
|
||||
}
|
||||
if (apiBase?.endsWith("/v1")) {
|
||||
apiBase = apiBase.slice(0, -3);
|
||||
}
|
||||
|
||||
return await Promise.all(
|
||||
chunks.map(async (chunk) => {
|
||||
const resp = await fetch(`${apiBase}/v1/embeddings`, {
|
||||
const resp = await fetch(`${apiBase}/embeddings`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
input: chunk,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ const NON_CHAT_MODELS = [
|
|||
class OpenAI extends BaseLLM {
|
||||
static providerName: ModelProvider = "openai";
|
||||
static defaultOptions: Partial<LLMOptions> = {
|
||||
apiBase: "https://api.openai.com",
|
||||
apiBase: "https://api.openai.com/v1",
|
||||
};
|
||||
|
||||
protected _convertMessage(message: ChatMessage) {
|
||||
|
|
@ -87,9 +87,7 @@ class OpenAI extends BaseLLM {
|
|||
if (url.endsWith("/")) {
|
||||
url = url.slice(0, -1);
|
||||
}
|
||||
if (!url.endsWith("/v1") && !url.includes("api.perplexity.ai")) {
|
||||
url += "/v1";
|
||||
}
|
||||
|
||||
return url + "/completions";
|
||||
}
|
||||
}
|
||||
|
|
@ -148,10 +146,6 @@ class OpenAI extends BaseLLM {
|
|||
url = url.slice(0, -1);
|
||||
}
|
||||
|
||||
if (!url.includes("/v1") && !url.includes("api.perplexity.ai")) {
|
||||
// includes instead of endsWith becuase DeepInfra uses /v1/openai/chat/completions
|
||||
url += "/v1";
|
||||
}
|
||||
return url + "/chat/completions";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
docs/static/schemas/config.json
vendored
3
docs/static/schemas/config.json
vendored
|
|
@ -172,7 +172,8 @@
|
|||
"deepseek",
|
||||
"openchat",
|
||||
"xwin-coder",
|
||||
"neural-chat"
|
||||
"neural-chat",
|
||||
"codellama-70b"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -105,10 +105,13 @@ export async function llmFromTitle(title?: string): Promise<ILLM> {
|
|||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
let text = await resp.text();
|
||||
if (resp.status === 404 && !resp.url.includes("/v1")) {
|
||||
text =
|
||||
"This may mean that you forgot to add '/v1' to the end of your 'apiBase' in config.json.";
|
||||
}
|
||||
throw new Error(
|
||||
`HTTP ${resp.status} ${resp.statusText} from ${
|
||||
resp.url
|
||||
}\n\n${await resp.text()}`
|
||||
`HTTP ${resp.status} ${resp.statusText} from ${resp.url}\n\n${text}`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue