mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-09 03:07:46 +08:00
fix(ollama): send chat requests to the /api path
The Ollama SDK appends /chat to the base URL, and Ollama serves chat at /api/chat. The model list already added the missing /api, so with "http://localhost:11434" (the address our docs showed) models were listed but every chat request went to /chat and got a 404. An OpenAI-style ".../v1" address went to /v1/chat. ollamaApiUrl() turns the server address, ".../v1" and ".../api" into ".../api". Chat, the model list and the settings dialog's request URL hint all use it. The docs now show http://localhost:11434/api, which also works on released versions.
This commit is contained in:
@@ -622,6 +622,15 @@ export function normalizeBaseUrl(url: string): string {
|
||||
.replace(/\/(?:chat\/completions|completions|messages|responses)$/, "")
|
||||
}
|
||||
|
||||
/**
|
||||
* Ollama's native API root, which the SDK appends /chat to and the model
|
||||
* list /tags. Users often enter the server address ("http://localhost:11434")
|
||||
* or its OpenAI-compatible one (".../v1"); both get /api.
|
||||
*/
|
||||
export function ollamaApiUrl(baseUrl: string): string {
|
||||
return `${normalizeBaseUrl(baseUrl).replace(/\/(?:api|v1)$/, "")}/api`
|
||||
}
|
||||
|
||||
/** Where a chat request goes for a base URL, or null when the SDK decides */
|
||||
export function chatRequestUrl(
|
||||
provider: ProviderName,
|
||||
@@ -630,6 +639,7 @@ export function chatRequestUrl(
|
||||
const url = normalizeBaseUrl(baseUrl)
|
||||
if (!url) return null
|
||||
if (provider === "anthropic") return `${url}/messages`
|
||||
if (provider === "ollama") return `${ollamaApiUrl(url)}/chat`
|
||||
// These SDKs build their own paths (or, for MiniMax, pick the protocol
|
||||
// from the URL)
|
||||
const ownPaths: ProviderName[] = [
|
||||
@@ -637,7 +647,6 @@ export function chatRequestUrl(
|
||||
"vertexai",
|
||||
"azure",
|
||||
"bedrock",
|
||||
"ollama",
|
||||
"gateway",
|
||||
"minimax",
|
||||
"edgeone",
|
||||
|
||||
Reference in New Issue
Block a user