|
1 | 1 | import json
|
2 | 2 | import sublime
|
3 | 3 | import sublime_plugin
|
| 4 | +import threading |
4 | 5 |
|
5 | 6 | import urllib.request as request
|
6 | 7 |
|
@@ -59,15 +60,28 @@ def show_input_done(self, input_string):
|
59 | 60 |
|
60 | 61 | self.view.settings().set('show_input_last', input_string)
|
61 | 62 |
|
62 |
| - contents = self.request(input_string).replace('\\', '\\\\').replace('$', '\\$') |
| 63 | + Request(self.view, self.settings, input_string).start() |
63 | 64 |
|
64 |
| - self.debug('show_input_done[contents]', contents) |
| 65 | + def debug(self, key, value): |
| 66 | + if (self.settings['debug']): |
| 67 | + print(key, value) |
| 68 | + |
| 69 | +class Request(threading.Thread): |
| 70 | + def __init__(self, view, settings, prompt): |
| 71 | + self.view = view |
| 72 | + self.settings = settings |
| 73 | + self.prompt = prompt |
| 74 | + |
| 75 | + super(Request, self).__init__() |
| 76 | + |
| 77 | + def run(self): |
| 78 | + contents = self.request().replace('\\', '\\\\').replace('$', '\\$') |
65 | 79 |
|
66 | 80 | self.view.run_command('insert_snippet', {'contents': contents})
|
67 | 81 |
|
68 |
| - def request(self, input_string): |
| 82 | + def request(self): |
69 | 83 | response = self.request_response()
|
70 |
| - data = self.request_data(input_string) |
| 84 | + data = self.request_data() |
71 | 85 | timeout = self.settings['timeout']
|
72 | 86 |
|
73 | 87 | self.debug('request[data]', data)
|
@@ -101,9 +115,9 @@ def request_headers(self):
|
101 | 115 | 'Content-Type': 'application/json'
|
102 | 116 | }
|
103 | 117 |
|
104 |
| - def request_data(self, input_string): |
| 118 | + def request_data(self): |
105 | 119 | return json.dumps({
|
106 |
| - 'prompt': input_string, |
| 120 | + 'prompt': self.prompt, |
107 | 121 | 'model': self.settings['model'],
|
108 | 122 | 'temperature': self.settings['temperature'],
|
109 | 123 | 'max_tokens': self.settings['max_tokens']
|
|
0 commit comments