Skip to content

Instantly share code, notes, and snippets.

@kinfolk0117
Created March 21, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinfolk0117/7177964818f46407d4c457923650c212 to your computer and use it in GitHub Desktop.
Save kinfolk0117/7177964818f46407d4c457923650c212 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import openai
import os
import sys
# get query from command line argument
query = sys.argv[1]
engine_model="gpt-3.5-turbo"
# caputure current tmux buffer,
buffer = os.popen("tmux capture-pane -p -S -").read()
# the buffer will end in multiple empty lines remoe them
buffer = buffer.strip()
# only keep the last 50 lines
buffer = "'\n'".join(buffer.split("\n")[-50:])
# print buffer to buffer.txt
with open("buffer.txt", "w") as f:
f.write(buffer)
prompt="The following is a conversation with an AI assistant. The assistant is an expert software developer and will help the user with it's queries by giving examples and instructions."
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": prompt},
{"role": "user", "content": "BUFFER:\n" + buffer + "\n\nQUERY:\n" + query}
]
)
message = completion.choices[0].message
print(message.role + ": " + message.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment