Skip to content

Commit

Permalink
Merge pull request #7 from necarlson97/windows
Browse files Browse the repository at this point in the history
Windows
  • Loading branch information
necarlson97 authored Feb 20, 2023
2 parents c0429b8 + 7560064 commit 297237b
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
// Request a prompt based on the highlighted text from codex
{ "keys": ["ctrl+shift+insert"], "command": "completion_codex" },
// Instruct a type of edit on the highlighted text
{ "keys": ["ctrl+shift+end"], "command": "edit_codex" },
]
2 changes: 1 addition & 1 deletion codex-ai.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"open_ai_key": "<put your key here from https://beta.openai.com/account/api-keys>",
"open_ai_key": "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",
"max_seconds": 60,
"completions": {
"model": "text-davinci-003",
14 changes: 7 additions & 7 deletions codex_ai.py
Original file line number Diff line number Diff line change
@@ -36,6 +36,12 @@ def handle_thread(self, thread, seconds=0):
settings = sublime.load_settings('codex-ai.sublime-settings')
max_seconds = settings.get('max_seconds', 60)

# If we ran out of time, let user know, stop checking on the thread
if seconds > max_seconds:
msg = "Codex ran out of time! {}s".format(max_seconds)
sublime.status_message(msg)
return

# While the thread is running, show them some feedback,
# and keep checking on the thread
if thread.running:
@@ -47,12 +53,6 @@ def handle_thread(self, thread, seconds=0):
self.handle_thread(thread, seconds + 1), 1000)
return

# If we ran out of time, let user know, stop checking on the thread
if seconds > max_seconds:
msg = "Codex ran out of time! {}s".format(max_seconds)
sublime.status_message(msg)
return

# If we finished with no result, something is wrong
if not thread.result:
sublime.status_message("Something is wrong with Codex - aborting")
@@ -185,7 +185,7 @@ def get_codex_response(self):
respone_dict = json.loads(response.read().decode())

if respone_dict.get('error', None):
raise ValueError(respone_dict['Error'])
raise ValueError(respone_dict['error'])
else:
choice = respone_dict.get('choices', [{}])[0]
ai_text = choice['text']

0 comments on commit 297237b

Please sign in to comment.