Fix plugin loading when there is no openai key (#59)

* Fix onload issue when there is no openai key

* Make openai key text field wider
This commit is contained in:
Logan Yang 2023-06-08 12:52:51 -07:00 committed by GitHub
parent 5c137ed23f
commit dadd890af8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

View file

@ -124,6 +124,13 @@ class AIState {
key, model, temperature, maxTokens,
} = this.langChainParams;
if (!key) {
new Notice(
'No OpenAI API key provided. Please set it in Copilot settings, and restart the plugin.'
);
return;
}
AIState.chatOpenAI = new ChatOpenAI({
openAIApiKey: key,
modelName: model,

View file

@ -1,5 +1,6 @@
import AIState from '@/aiState';
import { ChatMessage } from '@/sharedState';
import { Notice } from 'obsidian';
export type Role = 'assistant' | 'user' | 'system';
@ -12,17 +13,25 @@ export const getAIResponse = async (
updateShouldAbort: (abortController: AbortController | null) => void,
debug = false,
) => {
const {
key,
model,
temperature,
maxTokens,
systemMessage,
chatContextTurns,
} = aiState.langChainParams;
if (!key) {
new Notice(
'No OpenAI API key provided. Please set it in Copilot settings, and restart the plugin.'
);
return;
}
const abortController = new AbortController();
updateShouldAbort(abortController);
if (debug) {
const {
model,
temperature,
maxTokens,
systemMessage,
chatContextTurns,
} = aiState.langChainParams;
console.log(`*** DEBUG INFO ***\n`
+ `user message: ${userMessage.message}\n`
+ `model: ${model}\n`

View file

@ -54,7 +54,7 @@ export class CopilotSettingTab extends PluginSettingTab {
)
.addText((text) => {
text.inputEl.type = "password";
text.inputEl.style.width = "80%";
text.inputEl.style.width = "100%";
text
.setPlaceholder("OpenAI API key")
.setValue(this.plugin.settings.openAiApiKey)