Skip to content

Commit

Permalink
Added proxy support.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavyaroslav committed Apr 6, 2023
1 parent b422b24 commit f2e19ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
14 changes: 11 additions & 3 deletions openAI.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@
// Affects only `chat_completion` command.
"markdown": false,

// Apply custom syntax highlight to OpenAI completion output panel text.
// Apply custom syntax highlight to OpenAI completion output panel text.
// e.g.: "Packages/MarkdownEditing/syntaxes/MultiMarkdown.sublime-syntax"
"syntax_path": "",

// Minimum amount of characters selected to perform completion.
// Minimum amount of characters selected to perform completion.
// Does not affect completion command if the "output_panel" setting is true.
"minimum_selection_length": 20
"minimum_selection_length": 20,

// Proxy setting
"proxy": {
// Proxy address
"address": "",
// Proxy port
"port": 8080
}
}
8 changes: 7 additions & 1 deletion openai_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ def exec_net_request(self, connect: http.client.HTTPSConnection):

def chat_complete(self):
cacher = Cacher()
conn = http.client.HTTPSConnection("api.openai.com")
proxy = self.settings.get('proxy')['address']
port = self.settings.get('proxy')['port']
if len(proxy) > 0:
conn = http.client.HTTPSConnection(host=proxy, port=port)
conn.set_tunnel("api.openai.com")
else:
conn = http.client.HTTPSConnection("api.openai.com")

payload = {
# Todo add uniq name for each output panel (e.g. each window)
Expand Down
4 changes: 2 additions & 2 deletions outputpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def rewrite_output_panel(self, window, markdown: bool, syntax_path: str):

output_panel.set_read_only(True)
num_lines = get_number_of_lines(output_panel)
print(num_lines)
print(f'num_lines: {num_lines}')

## FIXME: To calibrate scroll.
point = output_panel.text_point(num_lines, 0) # +8 is that much from last line of a past answer and the first line of a next one.
Expand All @@ -47,7 +47,7 @@ def on_activated(self, view):
window=window,
markdown=settings.get('markdown'),
syntax_path=settings.get('syntax_path')
)
)

def show_panel(self, window):
window.run_command("show_panel", {"panel": f"output.{self.OUTPUT_PANEL_NAME}"})
Expand Down

0 comments on commit f2e19ab

Please sign in to comment.