store api key in .env
This commit is contained in:
parent
0ba5c6c377
commit
3a3d6ee400
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ dist
|
||||
node_modules
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
.env
|
||||
|
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,6 +9,7 @@
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"axios": "^1.3.6",
|
||||
"dotenv": "^16.0.3",
|
||||
"node-fetch": "^3.3.1",
|
||||
"nonce": "^1.0.4",
|
||||
"openai": "^3.2.1",
|
||||
@ -1212,6 +1213,14 @@
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.4.368",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.368.tgz",
|
||||
@ -4500,6 +4509,11 @@
|
||||
"esutils": "^2.0.2"
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
|
||||
},
|
||||
"electron-to-chromium": {
|
||||
"version": "1.4.368",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.368.tgz",
|
||||
|
@ -56,6 +56,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.3.6",
|
||||
"dotenv": "^16.0.3",
|
||||
"node-fetch": "^3.3.1",
|
||||
"nonce": "^1.0.4",
|
||||
"openai": "^3.2.1",
|
||||
|
@ -28,7 +28,7 @@ export default class ChatPanel {
|
||||
);
|
||||
|
||||
// Set the webview's initial HTML content
|
||||
new ChatPanel(panel, extensionUri, uuidv4()));
|
||||
new ChatPanel(panel, extensionUri, uuidv4());
|
||||
}
|
||||
|
||||
private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri, session_id: string) {
|
||||
|
@ -1,8 +1,15 @@
|
||||
|
||||
const { Configuration, OpenAIApi } = require("openai");
|
||||
import * as dotenv from 'dotenv';
|
||||
import * as path from 'path';
|
||||
|
||||
const extensionDir = path.resolve(__dirname, '..');
|
||||
const envFilePath = path.join(extensionDir, '.env');
|
||||
const dotenvOutput = dotenv.config({ path: envFilePath });
|
||||
console.log('dotenv output:', dotenvOutput);
|
||||
|
||||
const configuration = new Configuration({
|
||||
apiKey: "sk-xxxx",
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
|
||||
// Set up proxy settings
|
||||
@ -22,15 +29,7 @@ export async function chatWithGPT(prompt: string, session_id: string, messageLis
|
||||
},
|
||||
];
|
||||
|
||||
const some_array = [
|
||||
{role: 'user', content: 'how are you?'},
|
||||
{role: 'assistant', content: "As an AI language model, I don't have feelin… you for asking. How can I assist you today?"},
|
||||
{role: 'user', content: 'what is my question?'}
|
||||
]
|
||||
|
||||
try {
|
||||
console.log(fullConversation)
|
||||
console.log(some_array)
|
||||
let completion = await openai.createChatCompletion({
|
||||
model: "gpt-3.5-turbo",
|
||||
messages: fullConversation,
|
||||
|
Loading…
x
Reference in New Issue
Block a user