-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
71 lines (61 loc) · 3.45 KB
/
config.ts
File metadata and controls
71 lines (61 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { env } from '$env/dynamic/private'
import { open } from 'sqlite'
import sqlite3 from 'sqlite3'
import os from 'node:os'
import path from 'node:path'
export interface Setting {
key: string
value: string
description: string
}
const DB_PATH = path.join(os.homedir(), '.wellsaid_settings.db')
const db = await open({ filename: DB_PATH, driver: sqlite3.Database })
await db.exec(`CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT,
description TEXT
)`)
const defaultSettings: Record<string, { value?: string; description: string }> = {
PARTNER_PHONE: { value: env.PARTNER_PHONE, description: "Your partner's phone number in the Messages app" },
HISTORY_LOOKBACK_HOURS: { value: env.HISTORY_LOOKBACK_HOURS, description: 'How many hours of prior conversation history to search for extra context' },
CUSTOM_CONTEXT: { value: env.CUSTOM_CONTEXT, description: 'To guide the AI\'s personality and behavior (Example: "Act as my therapist suggesting replies to my partner" or "You are a helpful assistant")' },
OPENAI_API_KEY: { value: env.OPENAI_API_KEY, description: 'Your OpenAI API key' },
OPENAI_MODEL: { value: env.OPENAI_MODEL, description: 'gpt-4 or any other OpenAI model' },
OPENAI_TEMPERATURE: { value: env.OPENAI_TEMPERATURE, description: 'Controls the randomness of the responses' },
OPENAI_TOP_P: { value: env.OPENAI_TOP_P, description: 'Lets the responses be a little more adventurous' },
OPENAI_FREQUENCY_PENALTY: { value: env.OPENAI_FREQUENCY_PENALTY, description: 'Keeps the suggestions from repeating themselves' },
OPENAI_PRESENCE_PENALTY: { value: env.OPENAI_PRESENCE_PENALTY, description: 'Nudges the AI to bring up fresh ideas' },
ANTHROPIC_API_KEY: { value: env.ANTHROPIC_API_KEY, description: 'Your Anthropic API key' },
ANTHROPIC_MODEL: { value: env.ANTHROPIC_MODEL, description: 'claude-3-opus-20240229 or another Anthropic model' },
ANTHROPIC_TEMPERATURE: { value: env.ANTHROPIC_TEMPERATURE, description: "Controls the randomness of Claude's responses" },
GROK_API_KEY: { value: env.GROK_API_KEY, description: 'Your Grok API key' },
GROK_MODEL: { value: env.GROK_MODEL, description: 'grok-1 or another Grok model' },
GROK_TEMPERATURE: { value: env.GROK_TEMPERATURE, description: 'Controls the randomness of Grok\'s responses' },
KHOJ_API_URL: { value: env.KHOJ_API_URL, description: 'Your Khoj server API URL if you have one, otherwise leave this out or leave it blank' },
KHOJ_AGENT: { value: env.KHOJ_AGENT, description: 'optional specific agent to use' },
}
for (const [key, { value = '', description }] of Object.entries(defaultSettings)) {
await db.run(
'INSERT OR IGNORE INTO settings (key, value, description) VALUES (?, ?, ?)',
key,
value,
description
)
}
const rows = await db.all<Setting[]>('SELECT key, value, description FROM settings')
export const settings: Record<string, string> = {}
for (const row of rows) {
settings[row.key] = row.value
}
export async function updateSetting(key: string, value: string): Promise<void> {
await db.run(
'INSERT INTO settings (key, value, description) VALUES (?, ?, (SELECT description FROM settings WHERE key = ?)) ON CONFLICT(key) DO UPDATE SET value=excluded.value',
key,
value,
key
)
settings[key] = value
}
export async function getAllSettings(): Promise<Setting[]> {
return db.all<Setting[]>('SELECT key, value, description FROM settings')
}