Swap Anthropic SDK for Ollama (local qwen2.5:7b) #14
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Lineage
Replaces Anthropic API dependency. Lucas has no Anthropic tokens — must use local Ollama instance with qwen2.5:7b in the cluster.
Repo
forgejo_admin/westside-ai-assistantUser Story
As Marcus (admin)
I want the AI assistant to use the local Ollama model instead of Anthropic
So that the service runs at zero cost using our cluster GPU
Context
The AI engine was built with the Anthropic Python SDK (
anthropic). We're swapping to the OpenAI Python SDK (openai) pointing at the cluster-internal Ollama endpoint, which exposes an OpenAI-compatible/v1/chat/completionsAPI with tool_use support. Model:qwen2.5:7brunning on the GTX 1070 in the Ollama pod. The tool definitions stay the same shape (OpenAI tool format), the system prompt stays the same, conversation history stays the same. The main changes are the SDK swap and response parsing.Ollama cluster-internal URL:
http://ollama.ollama.svc.cluster.local:11434/v1File Targets
Files the agent should modify:
app/ai.py— swapanthropicSDK →openaiSDK. Change client init to point at Ollama URL. Change tool definitions from Anthropic format to OpenAI format. Change response parsing fromcontent_block.type == "tool_use"tochoice.message.tool_calls. Change tool result submission to OpenAI format. Keep system prompt, conversation history, confirmation signals, and GroupMe posting unchanged.app/config.py— replaceanthropic_api_keyandanthropic_modelwithollama_url(default:http://ollama.ollama.svc.cluster.local:11434/v1) andollama_model(default:qwen2.5:7b). Keepanthropic_api_keyas optional fallback.requirements.txt— addopenai>=1.0(keepanthropicfor now as optional)tests/test_ai.py— update mocks from Anthropic response format to OpenAI response formatFiles the agent should NOT touch:
app/basketball.py— unchanged, same interfaceapp/confirmation.py— unchanged, same interfaceapp/groupme.py— unchanged, same interfaceAcceptance Criteria
app/ai.pyusesopenai.OpenAI(base_url=settings.ollama_url, api_key="ollama")client{"type": "function", "function": {"name": ..., "parameters": ...}}message.tool_calls(OpenAI format){"role": "tool", "tool_call_id": ..., "content": ...}qwen2.5:7bviaOLLAMA_MODELenv varTest Expectations
pytest tests/ -vConstraints
openaiPython SDK, NOT raw HTTP — cleaner tool_use handlinghttp://ollama.ollama.svc.cluster.local:11434/v1"ollama")ANTHROPIC_API_KEYis set andOLLAMA_URLis not, use AnthropicChecklist
Related
project-westside-ai-assistant— parent projectstory-westside-ai-assistant-read-ops— must still work with local model