working on voice control
Some checks failed
CI/CD Pipeline / build (push) Failing after 4s

This commit is contained in:
2026-03-24 15:06:53 -06:00
parent f514012396
commit 86ff82a015
16 changed files with 704 additions and 173 deletions

View File

@@ -135,6 +135,11 @@ defmodule ElixirAi.AiUtils.StreamLineUtils do
:ok
end
def handle_stream_line(server, "proxy error" <> _ = error) when is_binary(error) do
Logger.error("Proxy error in AI stream: #{error}")
send(server, {:stream, {:ai_request_error, error}})
end
def handle_stream_line(server, json) when is_binary(json) do
case Jason.decode(json) do
{:ok, body} ->

View File

@@ -1,7 +1,7 @@
defmodule ElixirAi.ChatRunner do
require Logger
use GenServer
alias ElixirAi.{AiTools, Conversation, Message}
alias ElixirAi.{AiTools, Conversation, Message, SystemPrompts}
import ElixirAi.PubsubTopics
import ElixirAi.ChatRunner.OutboundHelpers
@@ -94,6 +94,12 @@ defmodule ElixirAi.ChatRunner do
_ -> "auto"
end
system_prompt =
case Conversation.find_category(name) do
{:ok, category} -> SystemPrompts.for_category(category)
_ -> nil
end
server_tools = AiTools.build_server_tools(self(), allowed_tools)
liveview_tools = AiTools.build_liveview_tools(self(), allowed_tools)
@@ -106,7 +112,7 @@ defmodule ElixirAi.ChatRunner do
ElixirAi.ChatUtils.request_ai_response(
self(),
messages,
messages_with_system_prompt(messages, system_prompt),
server_tools ++ liveview_tools,
provider,
tool_choice
@@ -117,6 +123,7 @@ defmodule ElixirAi.ChatRunner do
%{
name: name,
messages: messages,
system_prompt: system_prompt,
streaming_response: nil,
pending_tool_calls: [],
allowed_tools: allowed_tools,

View File

@@ -10,7 +10,7 @@ defmodule ElixirAi.ChatRunner.ConversationCalls do
ElixirAi.ChatUtils.request_ai_response(
self(),
new_state.messages,
messages_with_system_prompt(new_state.messages, state.system_prompt),
state.server_tools ++ state.liveview_tools,
state.provider,
effective_tool_choice

View File

@@ -18,4 +18,7 @@ defmodule ElixirAi.ChatRunner.OutboundHelpers do
message
end
def messages_with_system_prompt(messages, nil), do: messages
def messages_with_system_prompt(messages, prompt), do: [prompt | messages]
end

View File

@@ -159,7 +159,7 @@ defmodule ElixirAi.ChatRunner.StreamHandler do
ElixirAi.ChatUtils.request_ai_response(
self(),
state.messages ++ [new_message],
messages_with_system_prompt(state.messages ++ [new_message], state.system_prompt),
state.server_tools ++ state.liveview_tools,
state.provider,
state.tool_choice

View File

@@ -101,6 +101,17 @@ defmodule ElixirAi.Conversation do
end
end
def find_category(name) do
sql = "SELECT category FROM conversations WHERE name = $(name) LIMIT 1"
params = %{"name" => name}
case DbHelpers.run_sql(sql, params, "conversations") do
{:error, :db_error} -> {:error, :db_error}
[] -> {:error, :not_found}
[row | _] -> {:ok, row["category"] || "user-web"}
end
end
def find_allowed_tools(name) do
sql = "SELECT allowed_tools FROM conversations WHERE name = $(name) LIMIT 1"
params = %{"name" => name}

View File

@@ -0,0 +1,14 @@
defmodule ElixirAi.SystemPrompts do
@prompts %{
"voice" =>
"You are responding to voice-transcribed input. Keep replies concise and conversational. The user spoke aloud and their message was transcribed, so minor transcription errors may be present.",
"user-web" => nil
}
def for_category(category) do
case Map.get(@prompts, category) do
nil -> nil
prompt -> %{role: :system, content: prompt}
end
end
end