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:
+23
-14
@@ -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
|
||||
|
||||
@@ -3,7 +3,5 @@ defmodule OpenAI.Completion do
|
||||
defstruct content: "",
|
||||
temperature: 0.2,
|
||||
role: "user",
|
||||
model: "gpt-4o-mini",
|
||||
messages: nil,
|
||||
response_format: nil
|
||||
model: "gpt-4o-mini"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user