-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,17 @@ | ||
# chat-gpt-shell- | ||
# chat-gpt-cli | ||
Access ChatGPT through the Command Line | ||
|
||
## Setup | ||
Obtain a OpenAI API KEY. Create a ```env.js``` file in the root directory and put the following line in it ```module.exports = 'YOUR_OPEN_AI_KEY'``` | ||
|
||
Use ``` npm link ``` to symlink package folder. | ||
```chat-gpt``` command should be available in your shell. | ||
|
||
## Example | ||
``` | ||
$ chat-gpt how many inches in a mile | ||
===================== Chat-GPT ===================== | ||
There are 63,360 inches in a mile. | ||
``` |
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,36 @@ | ||
#!/usr/bin/env node | ||
let prompt = ""; | ||
for(let i = 2; i < process.argv.length; i++){ | ||
prompt += process.argv[i] + ' ' | ||
} | ||
if(process.argv.length <= 2 || prompt.trim().length == 0){ | ||
console.error('No prompt provided to ChatGPT') | ||
process.exit(1) | ||
} | ||
|
||
const { Configuration, OpenAIApi } = require('openai'); | ||
const configuration = new Configuration({ | ||
apiKey: require('./env'), | ||
}); | ||
const openai = new OpenAIApi(configuration); | ||
|
||
async function generateText() { | ||
const response = await openai.createCompletion({ | ||
model: 'text-davinci-002', | ||
prompt: prompt, | ||
temperature: 0, | ||
max_tokens: 1000, | ||
}); | ||
|
||
if(response.data.choices[0].text){ | ||
console.log('===================== Chat-GPT =====================') | ||
console.log(response.data.choices[0].text) | ||
console.log('\n') | ||
} | ||
else{ | ||
console.error('No response generated') | ||
} | ||
|
||
} | ||
|
||
generateText(); |
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,26 @@ | ||
{ | ||
"dependencies": { | ||
"openai": "^3.2.1" | ||
}, | ||
"name": "chat-gpt-cli", | ||
"description": "Access ChatGPT through the Command Line", | ||
"version": "1.0.0", | ||
"main": "gpt.js", | ||
"devDependencies": {}, | ||
"scripts": { | ||
"test": "node gpt.js How many cups in a gallon" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tombyrn/chat-gpt-shell-.git" | ||
}, | ||
"author": "Thomas Byrnes", | ||
"license": "GPL-3.0", | ||
"bugs": { | ||
"url": "https://github.com/tombyrn/chat-gpt-shell-/issues" | ||
}, | ||
"homepage": "https://github.com/tombyrn/chat-gpt-shell-#readme", | ||
"bin": { | ||
"chat-gpt": "./chat-gpt.js" | ||
} | ||
} |