Skip to content

Commit 9b08d3e

Browse files
committed
Fix regression: completion broken after rewrite feature API changes.
1 parent c0ed5c8 commit 9b08d3e

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix regression: completion broken after rewrite feature API changes.
6+
57
## 0.78.0
68

79
- Prefix tool name with server to LLM: <server>__<toolname>. #196

src/eca/features/completion.clj

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,23 @@
6060
{:keys [line character]} position
6161
input-code (insert-completion-tag doc-text position)
6262
instructions (f.prompt/inline-completion-prompt config)
63-
{:keys [error result]} (deref (future
64-
(llm-api/sync-prompt!
65-
{:provider provider
66-
:model model
67-
:config config
68-
:prompt input-code
69-
:instructions instructions
70-
:provider-auth provider-auth
71-
:model-capabilities (assoc model-capabilities
72-
:reason? false
73-
:tools false
74-
:web-search false)}))
75-
30000 ;; TODO move to config
76-
{:error {:message "Timeout waiting for completion"}})]
63+
{:keys [error output-text]} (deref (future
64+
(try
65+
(llm-api/sync-prompt!
66+
{:provider provider
67+
:model model
68+
:config config
69+
:prompt input-code
70+
:instructions instructions
71+
:provider-auth provider-auth
72+
:model-capabilities (assoc model-capabilities
73+
:reason? false
74+
:tools false
75+
:web-search false)})
76+
(catch Exception e
77+
{:error {:exception e}})))
78+
30000 ;; TODO move to config
79+
{:error {:message "Timeout waiting for completion"}})]
7780
(cond
7881
(:message error)
7982
{:error {:type :warning
@@ -85,12 +88,12 @@
8588
{:error {:type :warning
8689
:message (:message (.getMessage ^Exception (:exception error)))}})
8790

88-
(not result)
91+
(not output-text)
8992
{:error {:type :info
9093
:message "No suggestions found"}}
9194

9295
:else
93-
{:items [{:text (normalize-code-result result)
96+
{:items [{:text (normalize-code-result output-text)
9497
:doc-version doc-version
9598
:range {:start {:line line :character character}
9699
:end {:line line :character character}}}]})))

src/eca/llm_providers/openai.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@
2626
json/parse-string)]
2727
(get-in payload ["https://api.openai.com/auth" "chatgpt_account_id"])))
2828

29+
(defn ^:private response-body->result [body]
30+
{:output-text (reduce
31+
#(str %1 (:text %2))
32+
""
33+
(:content (last (:output body))))})
34+
2935
(defn ^:private base-responses-request! [{:keys [rid body api-url auth-type url-relative-path api-key on-error on-stream]}]
3036
(let [oauth? (= :auth/oauth auth-type)
3137
url (if oauth?
3238
codex-url
3339
(str api-url (or url-relative-path responses-path)))
34-
response* (atom nil)
3540
on-error (if on-stream
3641
on-error
3742
(fn [error-data]
3843
(llm-util/log-response logger-tag rid "response-error" body)
39-
(reset! response* {:error error-data})))]
44+
{:error error-data}))]
4045
(llm-util/log-request logger-tag rid url body)
4146
@(http/post
4247
url
@@ -64,16 +69,11 @@
6469
(on-stream event data)))
6570
(do
6671
(llm-util/log-response logger-tag rid "response" body)
67-
(reset! response*
68-
{:output-text (reduce
69-
#(str %1 (:text %2))
70-
""
71-
(:content (last (:output body))))}))))
72+
(response-body->result body))))
7273
(catch Exception e
7374
(on-error {:exception e}))))
7475
(fn [e]
75-
(on-error {:exception e})))
76-
@response*))
76+
(on-error {:exception e})))))
7777

7878
(defn ^:private normalize-messages [messages supports-image?]
7979
(keep (fn [{:keys [role content] :as msg}]

0 commit comments

Comments
 (0)