summaryrefslogtreecommitdiff
path: root/py/chat.py
diff options
context:
space:
mode:
authorMartin Bielik <mx.bielik@gmail.com>2023-03-27 22:49:07 +0200
committerMartin Bielik <mx.bielik@gmail.com>2023-03-27 22:49:07 +0200
commitc1868ed4dcbb8acaf637b129f8a0f717a41cf5f2 (patch)
tree3b28d61905b9aa640ae99183508073ffd982b556 /py/chat.py
parent8af2250ee04a228e064a750f341812c02134081d (diff)
downloadvim-ai-c1868ed4dcbb8acaf637b129f8a0f717a41cf5f2.tar.gz
chat initial prompt poc
Diffstat (limited to 'py/chat.py')
-rw-r--r--py/chat.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/py/chat.py b/py/chat.py
index 0104014..6b7c2e5 100644
--- a/py/chat.py
+++ b/py/chat.py
@@ -5,13 +5,20 @@ plugin_root = vim.eval("s:plugin_root")
vim.command(f"py3file {plugin_root}/py/utils.py")
options = make_options()
-file_content = vim.eval('trim(join(getline(1, "$"), "\n"))')
+request_options = make_request_options()
openai.api_key = load_api_key()
-lines = file_content.splitlines()
+file_content = vim.eval('trim(join(getline(1, "$"), "\n"))')
+initial_prompt = '\n'.join(options['initial_prompt'])
+prompt = f"{initial_prompt}\n{file_content}"
+
+lines = prompt.splitlines()
messages = []
+with open('/tmp/prompt.aichat', 'w') as f:
+ f.write(prompt)
+
for line in lines:
if line.startswith(">>> system"):
messages.append({"role": "system", "content": ""})
@@ -38,7 +45,7 @@ try:
print('Answering...')
vim.command("redraw")
- response = openai.ChatCompletion.create(messages=messages, stream=True, **options)
+ response = openai.ChatCompletion.create(messages=messages, stream=True, **request_options)
generating_text = False
for resp in response: