Files
supermarket/internal/web/templates/ai.html
T
davidandClaude Opus 5.5 81a7d0596c Let Supermarket use Hermes' Anthropic key and model
Hermes is already set up with an Anthropic key, so AI needn't be set up
twice. `supermarket hermes` asks once, then it and update.sh copy just
the key and model to hermes-ai.json in the data folder (0600). The app
uses them when it has no key of its own, re-reading the file on each use.

Generation still calls the model directly rather than through Hermes'
API: post writing feeds it text from the web, which must not reach an
agent with a terminal, a browser and write access to the CRM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 14:58:06 -07:00

69 lines
3.8 KiB
HTML

{{define "content"}}{{with .Data}}{{$cfg := .Cfg}}
<nav class="tabs">
<a href="/settings/ai" aria-current="page">AI provider</a>
<a href="/settings/credentials">Credentials</a>
</nav>
<h1>AI provider</h1>
<form method="post" action="/settings/ai" id="ai-form">
<section class="card">
<fieldset class="choice">
<legend>Provider</legend>
<label class="check"><input type="radio" name="provider" value="anthropic" {{if ne $cfg.Provider "openai"}}checked{{end}} data-toggle="provider">
Anthropic (Claude)
{{if .HasAnthropicKey}}<span class="help">— with the key saved under <a href="/settings/credentials">Credentials</a></span>
{{else if .Shared}}<span class="help">— with Hermes' key, shared by <code>supermarket hermes</code> (Hermes uses {{.Shared.Model}}). A key saved under <a href="/settings/credentials">Credentials</a> would take its place.</span>
{{else}}<span class="help">— add the API key under <a href="/settings/credentials">Credentials</a>, or share Hermes' by running <code>supermarket hermes</code></span>{{end}}</label>
<label class="check"><input type="radio" name="provider" value="openai" {{if eq $cfg.Provider "openai"}}checked{{end}} data-toggle="provider">
A server on your network (Ollama, LM Studio, llama.cpp, vLLM) or another OpenAI-compatible service</label>
</fieldset>
<div data-show-for="openai">
<label>Server address <input name="base_url" id="base_url" value="{{$cfg.BaseURL}}" placeholder="http://192.168.1.20:11434" list="servers">
<span class="help">Supermarket runs in Docker: for a server on this computer use <code>http://host.docker.internal:11434</code>, and use an IP address rather than a <code>.local</code> name.</span></label>
<datalist id="servers">{{range .Servers}}<option value="{{.BaseURL}}">{{.Name}}</option>{{end}}</datalist>
{{if .Servers}}<p class="help">Found by CoreDesktop's <code>configure ai-servers</code>: {{range $i, $s := .Servers}}{{if $i}}, {{end}}{{$s.Name}} ({{$s.BaseURL}}){{end}}.</p>{{end}}
<button type="button" class="secondary" hx-get="/settings/ai/models" hx-include="#base_url" hx-target="#model-list">List its models</button>
<div id="model-list"></div>
</div>
<label>Model <input name="model" value="{{$cfg.Model}}" list="anthropic-models" required></label>
<datalist id="anthropic-models">{{range .AnthropicModels}}<option value="{{.}}">{{end}}</datalist>
<label data-show-for="anthropic">Effort
<select name="effort">
{{range .Efforts}}<option value="{{.}}" {{if eq $cfg.Effort .}}selected{{end}}>{{.}}</option>{{end}}
</select>
<span class="help">How hard the model thinks. Medium suits drafting; higher costs more and takes longer.</span>
</label>
</section>
<section class="card">
<h2>Model per task</h2>
<p class="help">Leave empty to use the model above. Same provider.</p>
{{range .Tasks}}
<label>{{.Label}} <input name="task_{{.ID}}" value="{{index $cfg.TaskModels .ID}}" list="anthropic-models"></label>
{{end}}
</section>
<div class="actions">
<button type="submit">Save</button>
<button type="button" class="secondary" hx-post="/settings/ai/test" hx-include="#ai-form" hx-target="#test-result" hx-indicator="#testing">Test</button>
<span id="testing" class="htmx-indicator">Asking the model…</span>
</div>
<div id="test-result"></div>
</form>
{{end}}{{end}}
{{define "test-result"}}
{{if .Error}}<p class="error">{{.Error}}</p>
{{else}}<p class="flash">The model answered in {{.Took}}: “{{.Reply}}”</p>{{end}}
{{end}}
{{define "model-list"}}
{{if .Error}}<p class="error">{{.Error}}</p>
{{else if .Models}}<p class="help">Models on this server (click one to use it):</p>
<ul class="pills">{{range .Models}}<li><button type="button" class="pill" data-fill="model" data-value="{{.}}">{{.}}</button></li>{{end}}</ul>
{{else}}<p class="help">The server has no models.</p>{{end}}
{{end}}