Skip to content

Commit bd12f61

Browse files
authored
feat: add support for customized AI model (word-hunter#116)
word-hunter#105
1 parent 0961c77 commit bd12f61

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/background/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ onMessage(Messages.fetch_html, async ({ data }) => {
244244

245245
onMessage(Messages.ai_explain, async ({ data }) => {
246246
const { word, text } = data
247-
const explain = await explainWord(word, text, settings().openai.model)
247+
const model = settings().openai.model === "custom" ? settings().openai.customModel : settings().openai.model
248+
const explain = await explainWord(word, text, model)
248249
return explain
249250
})
250251

src/lib/settings.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export const DEFAULT_SETTINGS = {
4545
apiKey: '',
4646
apiProxy: 'https://api.openai.com/v1/chat/completions',
4747
model: 'gpt-3.5-turbo',
48-
prompt: 'explain the word ${word} in the sentence "${context}" with grade 2 English words'
48+
prompt: 'explain the word ${word} in the sentence "${context}" with grade 2 English words',
49+
customModel: ''
4950
},
5051
githubToken: '',
5152
githubGistId: ''

src/options/openai.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export const OpenAISetting = () => {
2626
setSetting('openai', { ...openai, model: target.value })
2727
}
2828

29+
const onCustomModelChange = (e: Event) => {
30+
const target = e.target as HTMLInputElement
31+
const openai = settings().openai
32+
setSetting('openai', { ...openai, customModel: target.value })
33+
}
34+
2935
return (
3036
<Show when={settings().dictTabs.openai}>
3137
<section class="section">
@@ -43,8 +49,18 @@ export const OpenAISetting = () => {
4349
<option value="gpt-4">gpt-4</option>
4450
<option value="gpt-4o">gpt-4o</option>
4551
<option value="gpt-4o-mini">gpt-4o-mini</option>
52+
<option value="custom">custom model</option>
4653
</select>
4754
</div>
55+
{settings().openai.model === 'custom' && (
56+
<input
57+
type="text"
58+
placeholder="input custom model"
59+
class="input input-bordered input-sm w-full max-w-xs text-xs"
60+
value={settings().openai.customModel}
61+
oninput={onCustomModelChange}
62+
/>
63+
)}
4864
<textarea
4965
placeholder="input your openai apikey"
5066
class="textarea textarea-bordered textarea-lg w-full h-24 max-w-xs text-xs leading-5"

0 commit comments

Comments
 (0)