-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/nbonamy/witsy/issues/33
- Loading branch information
Showing
8 changed files
with
144 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
<template> | ||
<div> | ||
<div class="group"> | ||
<label>API key</label> | ||
<div class="subgroup"> | ||
<InputObfuscated v-model="apiKey" @blur="onKeyChange" /> | ||
<a href="https://openrouter.ai/settings/keys" target="_blank">Get your API key</a> | ||
</div> | ||
</div> | ||
<div class="group"> | ||
<label>Chat model</label> | ||
<div class="subgroup"> | ||
<select v-model="chat_model" :disabled="chat_models.length == 0" @change="save"> | ||
<option v-for="model in chat_models" :key="model.id" :value="model.id"> | ||
{{ model.name }} | ||
</option> | ||
</select> | ||
<a href="https://openrouter.ai/models" target="_blank">More about OpenRouter models</a> | ||
</div> | ||
<button @click.prevent="onRefresh">{{ refreshLabel }}</button> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
import { store } from '../services/store' | ||
import LlmFactory from '../llms/llm' | ||
import InputObfuscated from '../components/InputObfuscated.vue' | ||
const apiKey = ref(null) | ||
const refreshLabel = ref('Refresh') | ||
const chat_model = ref(null) | ||
const chat_models = ref([]) | ||
const load = () => { | ||
apiKey.value = store.config.engines.openrouter?.apiKey || '' | ||
chat_models.value = store.config.engines.openrouter?.models?.chat || [] | ||
chat_model.value = store.config.engines.openrouter?.model?.chat || '' | ||
} | ||
const onRefresh = async () => { | ||
refreshLabel.value = 'Refreshing…' | ||
setTimeout(() => getModels(), 500) | ||
} | ||
const setEphemeralRefreshLabel = (text: string) => { | ||
refreshLabel.value = text | ||
setTimeout(() => refreshLabel.value = 'Refresh', 2000) | ||
} | ||
const getModels = async () => { | ||
// load | ||
const llmFactory = new LlmFactory(store.config) | ||
let success = await llmFactory.loadModels('openrouter') | ||
if (!success) { | ||
chat_models.value = [] | ||
setEphemeralRefreshLabel('Error!') | ||
return | ||
} | ||
// reload | ||
load() | ||
// done | ||
setEphemeralRefreshLabel('Done!') | ||
} | ||
const onKeyChange = () => { | ||
if (chat_models.value.length === 0 && apiKey.value.length > 0) { | ||
store.config.engines.openrouter.apiKey = apiKey.value | ||
getModels() | ||
} | ||
save() | ||
} | ||
const save = () => { | ||
store.config.engines.openrouter.apiKey = apiKey.value | ||
store.config.engines.openrouter.model.chat = chat_model.value | ||
store.saveSettings() | ||
} | ||
defineExpose({ load }) | ||
</script> | ||
|
||
<style scoped> | ||
@import '../../css/dialog.css'; | ||
@import '../../css/tabs.css'; | ||
@import '../../css/form.css'; | ||
@import '../../css/panel.css'; | ||
</style> |