Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Commit 3215e36

Browse files
Add GPT as utility and modify voice to use GPT for summarization (#92)
* add GPT as utility and modify voice to use GPT for summarization * fix pylint errors * fix priming example json * update voice plugin readme * Update README.md * Update README.md * gpt3 skill update with util Signed-off-by: Tathagata Chakraborti <[email protected]> Co-authored-by: Mayank Agarwal <[email protected]> Co-authored-by: Tathagata Chakraborti <[email protected]>
1 parent a43ae19 commit 3215e36

24 files changed

+349
-113
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ python:
99
# command to install dependencies
1010
install:
1111
- pip install -r requirements.txt
12+
- pip install -r requirements_utilities.txt
1213
- pip install -r requirements_test.txt
1314
- pip install -r requirements_dev.txt
1415
- pip install -r requirements_emulator.txt

clai/server/plugins/dataxplore/manifest.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
name=dataxplore
33
description=This skill summarizes csv file from your natural language command into a Bash command.
44
default=no
5-
exclude=OS/390 Z/OS
5+
exclude=OS/390 Z/OS

clai/server/plugins/gpt3/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openai_api.key

clai/server/plugins/gpt3/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and the [NLC2CMD](http://ibm.biz/nlc2cmd) use case, but uses the recently releas
1010
The skill makes a remote call to the [OpenAI API](https://openai.com/blog/openai-api/), apply
1111
for yours [here](https://forms.office.com/Pages/ResponsePage.aspx?id=VsqMpNrmTkioFJyEllK8s0v5E5gdyQhOuZCXNuMR8i1UQjFWVTVUVEpGNkg3U1FNRDVVRFg3U0w4Vi4u).
1212

13+
The setup uses the GPT-3 utility in CLAI, please refer to the
14+
instructions [here](https://github.com/IBM/clai/tree/master/clai/server/utilities/gpt3) for more details.
15+
1316
### Scoring & Confidence
1417

1518
Currently, the `gpt3` skill returns a default confidence of `0.0`. Use direct invocation to use `gpt3`. If you have ideas to score and explain the responses from the GPT-3 model, open a PR!

clai/server/plugins/gpt3/gpt3.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,36 @@
99
from clai.server.command_message import State, Action, NOOP_COMMAND
1010
from clai.tools.colorize_console import Colorize
1111

12-
import requests
13-
14-
''' globals '''
15-
gpt3_endpoint = 'http://gpt3server.mybluemix.net/gpt3'
12+
from clai.server.utilities.gpt3.gpt3 import GPT, Example
1613

14+
from pathlib import Path
15+
import json
16+
import os
1717

1818
class GPT3(Agent):
1919
def __init__(self):
2020
super(GPT3, self).__init__()
21+
self._gpt3_api = self.__init_gpt3_api__()
22+
23+
def __init_gpt3_api__(self):
24+
25+
current_directory = str(Path(__file__).parent.absolute())
26+
27+
path_to_gpt3_key = os.path.join(current_directory, "openai_api.key")
28+
path_to_gpt3_prompts = os.path.join(current_directory, "prompt.json")
29+
30+
gpt3_key = open(path_to_gpt3_key, 'r').read()
31+
gpt3_prompts = json.load(open(path_to_gpt3_prompts, 'r'))
32+
33+
gpt3_api = GPT(temperature=0)
34+
gpt3_api.set_api_key(gpt3_key)
35+
36+
for prompt in gpt3_prompts:
37+
ip, op = prompt['input'], prompt['output']
38+
example = Example(ip, op)
39+
gpt3_api.add_example(example)
40+
41+
return gpt3_api
2142

2243
def get_next_action(self, state: State) -> Action:
2344

@@ -29,13 +50,13 @@ def get_next_action(self, state: State) -> Action:
2950

3051
try:
3152

32-
response = requests.post(gpt3_endpoint, json={'text': command, 'use_cached_prompt' : True}).json()
33-
response = response['response']
53+
response = self._gpt3_api.get_top_reply(command, strip_output_suffix=True)
54+
response = response.strip()
3455

3556
return Action(
3657
suggested_command=response,
3758
execute=False,
38-
description="Currently GPT-3 does not provide an explanation. Got an idea? Contribute to CLAI!",
59+
description="Currently the GPT-3 skill does not provide an explanation. Got an idea? Contribute to CLAI!",
3960
confidence=0.0)
4061

4162
except Exception as ex:

clai/server/plugins/gpt3/prompt.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"input": "List files",
4+
"output": "ls -l"
5+
},
6+
7+
{
8+
"input": "Count files in a directory",
9+
"output": "ls -l | wc -l"
10+
},
11+
{
12+
"input": "Disk space used by home directory",
13+
"output": "du ~"
14+
},
15+
{
16+
"input": "Replace foo with bar in all .py files",
17+
"output": "sed -i .bak -- 's/foo/bar/g' *.py"
18+
},
19+
{
20+
"input": "Delete the models subdirectory",
21+
"output": "rm -rf ./models"
22+
}
23+
]

clai/server/plugins/gpt3/remote/Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

clai/server/plugins/gpt3/remote/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

clai/server/plugins/gpt3/remote/manifest.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

clai/server/plugins/gpt3/remote/requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)