Fix review blockers in record chat

- Add Task.Supervisor to app supervision tree
- Use tagged tuples instead of rescue for error handling
- Pass embedding_text from parent LiveView as prop
- Remove dead Completion struct fields
- Extract socket assigns before Task closure
- Log errors server-side, show generic user message
- Make build_system_prompt private, remove thin wrapper
- Extract do_send_message for retry reuse

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Claudio Ortolina
2026-02-22 10:20:58 +00:00
parent 6e6e419801
commit 8d38512712
10 changed files with 99 additions and 91 deletions
+23 -14
View File
@@ -75,20 +75,29 @@ defmodule OpenAI.API do
end
end
Req.post!("https://api.openai.com/v1/chat/completions",
receive_timeout: 30_000,
connect_options: [
timeout: 5_000
],
json: %{
model: model,
messages: messages,
stream: true,
temperature: temperature
},
auth: {:bearer, api_key},
finch_request: fun
)
case Req.post("https://api.openai.com/v1/chat/completions",
receive_timeout: 30_000,
connect_options: [
timeout: 5_000
],
json: %{
model: model,
messages: messages,
stream: true,
temperature: temperature
},
auth: {:bearer, api_key},
finch_request: fun
) do
{:ok, %{status: status}} when status in 200..299 ->
:ok
{:ok, %{body: body}} ->
{:error, "OpenAI API error: #{inspect(body)}"}
{:error, exception} ->
{:error, "Connection error: #{Exception.message(exception)}"}
end
end
def get_embeddings(text, api_key) do