Unify naming convension ('openai'/'Openai', no 'openAi'/'openAI')

This commit is contained in:
Jinglei Ren 2023-05-28 08:32:12 +08:00
parent fdc65c998c
commit 50b8ae8185
4 changed files with 15 additions and 15 deletions

View File

@ -34,7 +34,7 @@ export function checkDevChatDependency(): boolean {
} }
} }
export async function checkOpenAiAPIKey() { export async function checkOpenaiApiKey() {
const secretStorage: vscode.SecretStorage = ExtensionContextHolder.context!.secrets; const secretStorage: vscode.SecretStorage = ExtensionContextHolder.context!.secrets;
let openaiApiKey = await secretStorage.get("devchat_OPENAI_API_KEY"); let openaiApiKey = await secretStorage.get("devchat_OPENAI_API_KEY");
if (!openaiApiKey) { if (!openaiApiKey) {
@ -49,7 +49,7 @@ export async function checkOpenAiAPIKey() {
return true; return true;
} }
function checkOpenAIKey() { function checkOpenaiKey() {
let openaiApiKey = vscode.workspace.getConfiguration('DevChat').get('OpenAI.apiKey'); let openaiApiKey = vscode.workspace.getConfiguration('DevChat').get('OpenAI.apiKey');
if (!openaiApiKey) { if (!openaiApiKey) {
openaiApiKey = process.env.OPENAI_API_KEY; openaiApiKey = process.env.OPENAI_API_KEY;
@ -57,7 +57,7 @@ function checkOpenAIKey() {
if (!openaiApiKey) { if (!openaiApiKey) {
// OpenAI key not set // OpenAI key not set
vscode.window.showInputBox({ vscode.window.showInputBox({
placeHolder: 'Please input your openAI API Key' placeHolder: 'Please input your OpenAI API key (or DevChat access key)'
}).then((value) => { }).then((value) => {
if (value) { if (value) {
// Set API Key // Set API Key
@ -86,7 +86,7 @@ function checkDependencyPackage() {
}); });
} }
if (!checkOpenAIKey()) { if (!checkOpenaiKey()) {
return; return;
} }
} }

View File

@ -2,7 +2,7 @@ import * as vscode from 'vscode';
import * as fs from 'fs'; import * as fs from 'fs';
import { import {
checkOpenAiAPIKey, checkOpenaiApiKey,
checkDevChatDependency, checkDevChatDependency,
checkDependencyPackage, checkDependencyPackage,
registerOpenChatPanelCommand, registerOpenChatPanelCommand,
@ -224,7 +224,7 @@ function activate(context: vscode.ExtensionContext) {
// check api key // check api key
if (apiKeyStatus === '' || apiKeyStatus === 'please set api key') { if (apiKeyStatus === '' || apiKeyStatus === 'please set api key') {
const bOk = await checkOpenAiAPIKey(); const bOk = await checkOpenaiApiKey();
if (bOk) { if (bOk) {
apiKeyStatus = 'ready'; apiKeyStatus = 'ready';
} else { } else {

View File

@ -3,7 +3,7 @@ import DevChat, { LogOptions, LogEntry } from '../toolwrapper/devchat';
import { MessageHandler } from './messageHandler'; import { MessageHandler } from './messageHandler';
import messageHistory from '../util/messageHistory'; import messageHistory from '../util/messageHistory';
import { regInMessage, regOutMessage } from '../util/reg_messages'; import { regInMessage, regOutMessage } from '../util/reg_messages';
import { checkOpenAiAPIKey } from '../contributes/commands'; import { checkOpenaiApiKey } from '../contributes/commands';
import ExtensionContextHolder from '../util/extensionContext'; import ExtensionContextHolder from '../util/extensionContext';
import { TopicManager } from '../topic/topicManager'; import { TopicManager } from '../topic/topicManager';
@ -86,7 +86,7 @@ export async function historyMessages(message: any, panel: vscode.WebviewPanel|v
messageHistory.add(entryNew); messageHistory.add(entryNew);
} }
const isApiKeyReady = await checkOpenAiAPIKey(); const isApiKeyReady = await checkOpenaiApiKey();
isApiSet = true; isApiSet = true;
if (!isApiKeyReady) { if (!isApiKeyReady) {
const startMessage = [ apiKeyMissedMessage() ]; const startMessage = [ apiKeyMissedMessage() ];
@ -119,7 +119,7 @@ export function isValidApiKey(apiKey: string) {
export async function isWaitForApiKey() { export async function isWaitForApiKey() {
if (isApiSet === undefined) { if (isApiSet === undefined) {
isApiSet = await checkOpenAiAPIKey(); isApiSet = await checkOpenaiApiKey();
} }
return !isApiSet; return !isApiSet;
} }

View File

@ -84,7 +84,7 @@ class DevChat {
return args; return args;
} }
async getOpenAiApiKey(): Promise<string | undefined> { async getOpenaiApiKey(): Promise<string | undefined> {
const secretStorage: vscode.SecretStorage = ExtensionContextHolder.context!.secrets; const secretStorage: vscode.SecretStorage = ExtensionContextHolder.context!.secrets;
let openaiApiKey = await secretStorage.get("devchat_OPENAI_API_KEY"); let openaiApiKey = await secretStorage.get("devchat_OPENAI_API_KEY");
if (!openaiApiKey) { if (!openaiApiKey) {
@ -151,15 +151,15 @@ class DevChat {
args.push(content); args.push(content);
const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath; const workspaceDir = vscode.workspace.workspaceFolders?.[0].uri.fsPath;
let openaiApiKey = await this.getOpenAiApiKey(); let openaiApiKey = await this.getOpenaiApiKey();
if (!openaiApiKey) { if (!openaiApiKey) {
logger.channel()?.error('openAI key is invalid!'); logger.channel()?.error('OpenAI key is invalid!');
logger.channel()?.show(); logger.channel()?.show();
} }
const openAiApiBase = vscode.workspace.getConfiguration('DevChat').get('OpenAI.EndPoint'); const openaiApiBase = vscode.workspace.getConfiguration('DevChat').get('OpenAI.EndPoint');
const openAiApiBaseObject = openAiApiBase ? { OPENAI_API_BASE: openAiApiBase } : {}; const openaiApiBaseObject = openaiApiBase ? { OPENAI_API_BASE: openaiApiBase } : {};
const openaiModel = vscode.workspace.getConfiguration('DevChat').get('OpenAI.model'); const openaiModel = vscode.workspace.getConfiguration('DevChat').get('OpenAI.model');
const openaiTemperature = vscode.workspace.getConfiguration('DevChat').get('OpenAI.temperature'); const openaiTemperature = vscode.workspace.getConfiguration('DevChat').get('OpenAI.temperature');
@ -203,7 +203,7 @@ class DevChat {
env: { env: {
...process.env, ...process.env,
OPENAI_API_KEY: openaiApiKey, OPENAI_API_KEY: openaiApiKey,
...openAiApiBaseObject ...openaiApiBaseObject
}, },
}, onStdoutPartial, undefined, undefined, undefined); }, onStdoutPartial, undefined, undefined, undefined);