Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
tombyrn committed Mar 16, 2023
1 parent 7bcdc19 commit 65f02ac
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
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.
```
36 changes: 36 additions & 0 deletions chat-gpt.js
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();
26 changes: 26 additions & 0 deletions package.json
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"
}
}

0 comments on commit 65f02ac

Please sign in to comment.