Skip to content

Commit

Permalink
ChatGPT-3 and prompt for ai complete
Browse files Browse the repository at this point in the history
  • Loading branch information
saif-ellafi committed Dec 20, 2022
1 parent ca1030b commit 7793d24
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The installer will identify this location automatically, so normally you don't h

1. Make sure your Espanso installation is valid and espanso starts correctly
2. Download the Zip packages for Linux (either base or base with AI)
3. If using default paths, this should just work: `unzip ~/Downloads/PlayBTW_v1_19_base_with_ai.zip -d ~/.config/espanso/`
3. If using default paths, this should just work: `unzip ~/Downloads/PlayBTW_v1_20_base_with_ai.zip -d ~/.config/espanso/`

### AI Complete errors

Expand Down
58 changes: 57 additions & 1 deletion match/playbtw_ai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,68 @@

matches:
# OpenAI Completion
- regex: ":aicomplete"
- triggers: [":aic", ":gpt"]
replace: "{{output}}"
vars:
- name: form_ai
type: form
params:
layout: |
Text prompt:
[[prompt]]
Model (ada cheapest, davinci best):
[[model]]
Temperature (randomness vs certainty):
[[temperature]]
Tokens (result length):
[[tokens]]
fields:
prompt:
type: text
multiline: true
model:
type: list
values:
- 'text-davinci-003'
- 'text-curie-001'
- 'text-babbage-001'
- 'text-ada-001'
default:
'text-davinci-003'
temperature:
type: list
values:
- '1.0'
- '0.9'
- '0.75'
- '0.5'
- '0.25'
- '0.1'
- '0'
default: '0.9'
tokens:
type: list
values:
- '16'
- '32'
- '64'
- '128'
- '256'
- '512'
- '1024'
default:
'64'
- name: output
type: script
params:
args:
- "%CONFIG%/scripts/playbtw_ai"
- ai_complete
- --prompt
- "{{form_ai.prompt}}"
- --model
- "{{form_ai.model}}"
- --temperature
- "{{form_ai.temperature}}"
- --tokens
- "{{form_ai.tokens}}"
2 changes: 1 addition & 1 deletion playbtw_ai.spec
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ shutil.move('README.pdf', '{0}/../README.pdf'.format(DISTPATH))
shutil.copy('match/playbtw_ai.yml', '{0}/../match/'.format(DISTPATH))
shutil.copy('config/openai.txt', '{0}/../config/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_ai', 'zip', 'dist_ai')
shutil.make_archive('PlayBTW_v1_20_ai', 'zip', 'dist_ai')
2 changes: 1 addition & 1 deletion playbtw_all.spec
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ else:
for f in glob.glob('tables/*'):
shutil.copy2(f, '{0}/../tables/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_base', 'zip', 'dist_all')
shutil.make_archive('PlayBTW_v1_20_base', 'zip', 'dist_all')
2 changes: 1 addition & 1 deletion playbtw_all_ai.spec
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ else:
for f in glob.glob('tables/*'):
shutil.copy2(f, '{0}/../tables/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_base_with_ai', 'zip', 'dist_all_ai')
shutil.make_archive('PlayBTW_v1_20_base_with_ai', 'zip', 'dist_all_ai')
2 changes: 1 addition & 1 deletion playbtw_core.spec
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ md2pdf('README.pdf', md_file_path='README.md', css_file_path='pdf.css', base_url
shutil.copy('README.pdf', '{0}/../README.pdf'.format(DISTPATH))
shutil.copy('match/playbtw_core.yml', '{0}/../match/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_core', 'zip', 'dist_core')
shutil.make_archive('PlayBTW_v1_20_core', 'zip', 'dist_core')
2 changes: 1 addition & 1 deletion playbtw_example.spec
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ shutil.copy('match/playbtw_example.yml', '{0}/../match/'.format(DISTPATH))
for f in glob.glob('tables/example*'):
shutil.copy2(f, '{0}/../tables/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_example', 'zip', 'dist_example')
shutil.make_archive('PlayBTW_v1_20_example', 'zip', 'dist_example')
2 changes: 1 addition & 1 deletion playbtw_mythic.spec
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ shutil.copy('match/playbtw_mythic.yml', '{0}/../match/'.format(DISTPATH))
for f in glob.glob('tables/mythic*'):
shutil.copy2(f, '{0}/../tables/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_mythic', 'zip', 'dist_mythic')
shutil.make_archive('PlayBTW_v1_20_mythic', 'zip', 'dist_mythic')
2 changes: 1 addition & 1 deletion playbtw_opse.spec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ shutil.copy('match/playbtw_opse.yml', '{0}/../match/'.format(DISTPATH))
for f in glob.glob('tables/opse*'):
shutil.copy2(f, '{0}/../tables/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_opse', 'zip', 'dist_opse')
shutil.make_archive('PlayBTW_v1_20_opse', 'zip', 'dist_opse')
2 changes: 1 addition & 1 deletion playbtw_pum.spec
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ shutil.copy('match/playbtw_pum.yml', '{0}/../match/'.format(DISTPATH))
for f in glob.glob('tables/pum*'):
shutil.copy2(f, '{0}/../tables/'.format(DISTPATH))

shutil.make_archive('PlayBTW_v1_19_pum', 'zip', 'dist_pum')
shutil.make_archive('PlayBTW_v1_20_pum', 'zip', 'dist_pum')
22 changes: 15 additions & 7 deletions scripts/playbtw_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

import argparse
import openai
import pyperclip

from playbtw_common import *


parser = argparse.ArgumentParser(description='Play by the Writing - for Espanso - AI Mode')
parser.add_argument('action', type=str, help='ai_complete')
parser.add_argument('--prompt', type=str, default=0, help='Text to prompt the AI')
parser.add_argument('--model', type=str, default=None, help='Model to use in OpenAI')
parser.add_argument('--temperature', type=float, help='Determines randomness levels, where 1 is full risk and 0 certain')
parser.add_argument('--tokens', type=int, help='Max tokens in the response')


args = vars(parser.parse_args())
Expand All @@ -22,11 +25,16 @@


if action == 'ai_complete':
context = pyperclip.paste()
if not context.strip():
print("ERROR: Nothing found in clipboard. Copy some text for context")
else:
response = openai.Completion().create(model='text-davinci-002', prompt=context, max_tokens=64, top_p=1, n=1)
print(response['choices'][0]['text'].strip())
prompt = args['prompt']
model = args['model']
temperature = args['temperature']
tokens = args['tokens']
response = openai.Completion().create(
prompt=prompt,
model=model,
temperature=temperature,
max_tokens=tokens
)
print(response['choices'][0]['text'].strip())
else:
raise Exception("Wrong Function argument!")

0 comments on commit 7793d24

Please sign in to comment.