Skip to content

Commit 59094c0

Browse files
Add settings screen with sqlite-backed configuration (#41)
* Add settings screen with SQLite-backed configuration * Embed settings as tab * fix: use updated conventions * fix: fix tab location and integrate settings * refactor: improve tab integration * fix: match widths * refactor: relocate settings db * fix: Remove stale info * fix: use same form dimensions * feat: achieve perfect tab alignment * fix: settings/save * fix: stop form resetting * fix: remove open AI key warning * refactor: simplify settings saving * fix: the issue with the form values being cleared on submissio * refactor: code/ui cleanup * ui: remove tab / form space caused by border-radius * ui: simplify styling * ui: fix input field lengths * ui: adjust api key and model input lengths * ui: adjust numeric field lengths * ui: update styles * feat: add urls to descriptions * refactor: code cleanup * feat: add visual save settings feedback * fix: remove unused code * refactor: enhance/streamline settings form * refactor: make hr styles global * refactor: simplify settings form * refactor: remove unused functions * feat: add knip, fix dependencies * ui: move khoj settings up --------- Co-authored-by: nbp <splinesreticulating@users.noreply.github.com>
1 parent e8be9d1 commit 59094c0

30 files changed

+900
-393
lines changed

.env.example

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
# Partner
2-
PARTNER_PHONE=your-partner-phone (eg. +1234567890)
3-
4-
# Search this many hours of prior messages for extra context
5-
HISTORY_LOOKBACK_HOURS=6
6-
7-
# OpenAI (leave values blank if not using)
8-
OPENAI_API_KEY=your-openai-api-key
9-
OPENAI_MODEL=gpt-4
10-
OPENAI_TEMPERATURE=0.5 # Between 0.0 (robotic or repetitive) and 1.0 (random or flippant)
11-
OPENAI_TOP_P=0.8 # Between 0.0 (most likely) and 1.0 (most diverse)
12-
OPENAI_FREQUENCY_PENALTY=0.2 # Between 0.0 (no penalty) and 1.0 (strong penalty)
13-
OPENAI_PRESENCE_PENALTY=0.2 # Between 0.0 (no penalty) and 1.0 (strong penalty)
14-
15-
# Anthropic (leave values blank if not using)
16-
ANTHROPIC_API_KEY=your-anthropic-api-key
17-
ANTHROPIC_MODEL=claude-3-opus-20240229
18-
ANTHROPIC_TEMPERATURE=0.5
19-
20-
# Grok (leave values blank if not using)
21-
GROK_API_KEY=your-grok-api-key
22-
GROK_MODEL=grok-1
23-
GROK_TEMPERATURE=0.5
24-
25-
# Khoj (leave values blank if not using)
26-
KHOJ_API_URL=http://127.0.0.1:42110/api/chat
27-
KHOJ_AGENT=agent-name
28-
291
# Auth
302
APP_USERNAME=you
313
APP_PASSWORD=yourpassword
@@ -38,6 +10,3 @@ ALLOWED_HOST=your-allowed-host (eg. yourhost.tailscale.ts.net)
3810

3911
# Auth (generated using OpenSSL: `openssl rand -base64 64`)
4012
JWT_SECRET=your-jwt-secret
41-
42-
# Custom Context sent with every message to the AI provider
43-
CUSTOM_CONTEXT='Act as a relationship coach and therapist. You are helping my partner and I improve our relationship.'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ vite.config.ts.timestamp-*
2727

2828
# Coverage
2929
coverage
30+
31+
# Settings database
32+
settings.db

README.md

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,38 +75,6 @@ cp .env.example .env
7575

7676
Update the values in the `.env` file. The following variables are needed:
7777

78-
- **Customization**
79-
80-
- `PARTNER_PHONE`: Your partner's phone number in the Messages app
81-
- `HISTORY_LOOKBACK_HOURS`: How many hours of prior conversation history to search for extra context
82-
- `CUSTOM_CONTEXT`: To guide the AI's personality and behavior (Example: "Act as my therapist suggesting replies to my partner" or "You are a helpful assistant")
83-
84-
- **Open AI**
85-
86-
- `OPENAI_API_KEY`: Your OpenAI API key
87-
- `OPENAI_MODEL`: gpt-4 or any other OpenAI model
88-
- `OPENAI_TEMPERATURE`: Controls the randomness of the responses
89-
- `OPENAI_TOP_P`: Lets the responses be a little more adventurous
90-
- `OPENAI_FREQUENCY_PENALTY`: Keeps the suggestions from repeating themselves
91-
- `OPENAI_PRESENCE_PENALTY`: Nudges the AI to bring up fresh ideas
92-
93-
- **Anthropic**
94-
95-
- `ANTHROPIC_API_KEY`: Your Anthropic API key
96-
- `ANTHROPIC_MODEL`: claude-3-opus-20240229 or another Anthropic model
97-
- `ANTHROPIC_TEMPERATURE`: Controls the randomness of Claude's responses
98-
99-
- **Grok**
100-
101-
- `GROK_API_KEY`: Your Grok API key
102-
- `GROK_MODEL`: grok-1 or another Grok model
103-
- `GROK_TEMPERATURE`: Controls the randomness of Grok's responses
104-
105-
- **Khoj**
106-
107-
- `KHOJ_API_URL`: Your [Khoj](https://khoj.dev/) server API URL if you have one, otherwise leave this out or leave it blank
108-
- `KHOJ_AGENT`: The [Khoj agent](https://docs.khoj.dev/features/agents/) to use if you have one, otherwise leave this out or leave it blank
109-
11078
- **Logging**
11179

11280
- `LOG_LEVEL`: Logging level (info, debug, warn, error)

knip.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema.json",
3+
"entry": [
4+
"src/**/*.svelte",
5+
"src/**/*.ts",
6+
"!**/*.test.ts",
7+
"!**/*.spec.ts",
8+
"!**/*.d.ts",
9+
"!**/__tests__/**",
10+
"!**/tests/**",
11+
"!**/mocks/**"
12+
],
13+
"project": ["src/**/*.ts", "src/**/*.svelte"],
14+
"ignore": [
15+
"**/{.svelte-kit,node_modules,__tests__,tests,test,mocks,__mocks__}/**",
16+
"**/*.{test,spec,d}.{ts,js}",
17+
"vite.config.ts",
18+
"src/hooks.server.ts",
19+
"pino-pretty",
20+
"src/lib/types.ts"
21+
],
22+
"ignoreDependencies": ["pino-pretty"]
23+
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
"format:check": "prettier --check .",
1919
"lint": "eslint .",
2020
"lint:fix": "eslint --fix .",
21+
"prune": "knip --production",
22+
"prune:list": "knip",
2123
"pretest": "svelte-kit sync",
2224
"test": "vitest run",
2325
"test:watch": "vitest",
2426
"test:coverage": "vitest run --coverage"
2527
},
2628
"devDependencies": {
29+
"@eslint/js": "^9.29.0",
2730
"@sveltejs/adapter-auto": "^6.0.0",
2831
"@sveltejs/kit": "^2.16.0",
2932
"@sveltejs/vite-plugin-svelte": "^5.0.0",
3033
"@testing-library/jest-dom": "^6.6.3",
31-
"@testing-library/svelte": "^5.2.8",
32-
"@types/basic-auth": "^1.1.8",
3334
"@types/jsonwebtoken": "^9.0.9",
3435
"@types/node": "^22.15.21",
3536
"@typescript-eslint/eslint-plugin": "^8.34.0",
@@ -40,16 +41,17 @@
4041
"eslint-plugin-svelte": "^3.9.1",
4142
"globals": "^16.0.0",
4243
"jsdom": "^26.1.0",
44+
"knip": "^5.61.2",
4345
"prettier": "^3.5.3",
4446
"prettier-plugin-svelte": "^3.4.0",
4547
"svelte": "^5.0.0",
4648
"svelte-check": "^4.0.0",
49+
"svelte-eslint-parser": "^1.2.0",
4750
"typescript": "^5.0.0",
4851
"vite": "^6.2.6",
4952
"vitest": "^3.1.4"
5053
},
5154
"dependencies": {
52-
"basic-auth": "^2.0.1",
5355
"dotenv": "^16.5.0",
5456
"jsonwebtoken": "^9.0.2",
5557
"pino": "^9.7.0",

src/app.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ label {
5454
font-family: var(--label-font);
5555
}
5656

57+
hr {
58+
border: 0;
59+
height: 1px;
60+
background-image: linear-gradient(
61+
to right,
62+
hsla(var(--primary-hsl, 0, 0%, 20%), 0),
63+
hsl(var(--primary-hsl, 0, 0%, 20%)),
64+
hsla(var(--primary-hsl, 0, 0%, 20%), 0)
65+
);
66+
margin: 1rem 0;
67+
}
68+
5769
@keyframes spin {
5870
to {
5971
transform: rotate(360deg);

src/lib/anthropic.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ANTHROPIC_API_KEY, ANTHROPIC_MODEL, ANTHROPIC_TEMPERATURE } from '$env/static/private'
1+
import { settings } from '$lib/config'
22
import { anthropicPrompt } from '$lib/prompts'
33
import type { Message, ToneType } from '$lib/types'
44
import { extractReplies, parseSummaryToHumanReadable } from '$lib/utils'
@@ -10,9 +10,9 @@ const DEFAULT_MODEL = 'claude-3-opus-20240229'
1010
const DEFAULT_TEMPERATURE = 0.5
1111

1212
const getConfig = () => ({
13-
model: ANTHROPIC_MODEL || DEFAULT_MODEL,
14-
temperature: Number(ANTHROPIC_TEMPERATURE || DEFAULT_TEMPERATURE),
15-
apiKey: ANTHROPIC_API_KEY,
13+
model: settings.ANTHROPIC_MODEL || DEFAULT_MODEL,
14+
temperature: Number(settings.ANTHROPIC_TEMPERATURE || DEFAULT_TEMPERATURE),
15+
apiKey: settings.ANTHROPIC_API_KEY,
1616
})
1717

1818
export const getAnthropicReply = async (

0 commit comments

Comments
 (0)