From 7793d24e42a6dba3bcd4b0318ef526921dd2baa8 Mon Sep 17 00:00:00 2001 From: Saif Addin Date: Tue, 20 Dec 2022 01:30:33 +0100 Subject: [PATCH] ChatGPT-3 and prompt for ai complete --- README.md | 2 +- match/playbtw_ai.yml | 58 ++++++++++++++++++++++++++++++++++++++++++- playbtw_ai.spec | 2 +- playbtw_all.spec | 2 +- playbtw_all_ai.spec | 2 +- playbtw_core.spec | 2 +- playbtw_example.spec | 2 +- playbtw_mythic.spec | 2 +- playbtw_opse.spec | 2 +- playbtw_pum.spec | 2 +- scripts/playbtw_ai.py | 22 ++++++++++------ 11 files changed, 81 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index a512da1..79ee0f0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/match/playbtw_ai.yml b/match/playbtw_ai.yml index 79c6bef..671df65 100644 --- a/match/playbtw_ai.yml +++ b/match/playbtw_ai.yml @@ -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}}" diff --git a/playbtw_ai.spec b/playbtw_ai.spec index 88ef886..b92fd27 100644 --- a/playbtw_ai.spec +++ b/playbtw_ai.spec @@ -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') \ No newline at end of file +shutil.make_archive('PlayBTW_v1_20_ai', 'zip', 'dist_ai') \ No newline at end of file diff --git a/playbtw_all.spec b/playbtw_all.spec index a46e7a7..5300ee9 100644 --- a/playbtw_all.spec +++ b/playbtw_all.spec @@ -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') diff --git a/playbtw_all_ai.spec b/playbtw_all_ai.spec index 9b4a691..6bdff91 100644 --- a/playbtw_all_ai.spec +++ b/playbtw_all_ai.spec @@ -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') diff --git a/playbtw_core.spec b/playbtw_core.spec index c8b37a9..e315a8a 100644 --- a/playbtw_core.spec +++ b/playbtw_core.spec @@ -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') diff --git a/playbtw_example.spec b/playbtw_example.spec index 75081c2..e22a61f 100644 --- a/playbtw_example.spec +++ b/playbtw_example.spec @@ -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') \ No newline at end of file +shutil.make_archive('PlayBTW_v1_20_example', 'zip', 'dist_example') \ No newline at end of file diff --git a/playbtw_mythic.spec b/playbtw_mythic.spec index 6757290..18a853f 100644 --- a/playbtw_mythic.spec +++ b/playbtw_mythic.spec @@ -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') diff --git a/playbtw_opse.spec b/playbtw_opse.spec index bd3ceb8..94b977c 100644 --- a/playbtw_opse.spec +++ b/playbtw_opse.spec @@ -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') diff --git a/playbtw_pum.spec b/playbtw_pum.spec index 7b435b8..5d13a35 100644 --- a/playbtw_pum.spec +++ b/playbtw_pum.spec @@ -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') diff --git a/scripts/playbtw_ai.py b/scripts/playbtw_ai.py index 16127db..5477ff5 100644 --- a/scripts/playbtw_ai.py +++ b/scripts/playbtw_ai.py @@ -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()) @@ -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!")