Fix 404: map 'code-memory' model name to real Ollama model
Open WebUI sends the proxy model name to our endpoint; passing it directly to Ollama caused 404. Now stripped before forwarding. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
6
main.py
6
main.py
@@ -127,13 +127,15 @@ async def chat_completions(req: ChatRequest, bg: BackgroundTasks):
|
|||||||
messages = await build_context(req)
|
messages = await build_context(req)
|
||||||
user_content = next((m.content for m in reversed(req.messages)
|
user_content = next((m.content for m in reversed(req.messages)
|
||||||
if m.role == "user"), "")
|
if m.role == "user"), "")
|
||||||
|
# use real Ollama model, not our proxy name
|
||||||
|
ollama_model = None if req.model == "code-memory" else req.model
|
||||||
|
|
||||||
if req.stream:
|
if req.stream:
|
||||||
collected: list[str] = []
|
collected: list[str] = []
|
||||||
|
|
||||||
async def gen() -> AsyncIterator[bytes]:
|
async def gen() -> AsyncIterator[bytes]:
|
||||||
try:
|
try:
|
||||||
async for chunk in oll.chat_stream(messages, model=req.model):
|
async for chunk in oll.chat_stream(messages, model=ollama_model):
|
||||||
collected.append(chunk)
|
collected.append(chunk)
|
||||||
data = json.dumps({"choices": [{"delta": {"content": chunk},
|
data = json.dumps({"choices": [{"delta": {"content": chunk},
|
||||||
"finish_reason": None}]})
|
"finish_reason": None}]})
|
||||||
@@ -153,7 +155,7 @@ async def chat_completions(req: ChatRequest, bg: BackgroundTasks):
|
|||||||
bg.add_task(_save_stream)
|
bg.add_task(_save_stream)
|
||||||
return StreamingResponse(gen(), media_type="text/event-stream")
|
return StreamingResponse(gen(), media_type="text/event-stream")
|
||||||
|
|
||||||
response_text = await oll.chat(messages, model=req.model)
|
response_text = await oll.chat(messages, model=ollama_model)
|
||||||
|
|
||||||
# background: save turns + extract facts
|
# background: save turns + extract facts
|
||||||
async def _save():
|
async def _save():
|
||||||
|
|||||||
Reference in New Issue
Block a user