This commit is contained in:
@@ -1,21 +1,30 @@
|
|||||||
// See the Tailwind configuration guide for advanced usage
|
// See the Tailwind configuration guide for advanced usage
|
||||||
// https://tailwindcss.com/docs/configuration
|
// https://tailwindcss.com/docs/configuration
|
||||||
|
|
||||||
const plugin = require("tailwindcss/plugin")
|
const plugin = require("tailwindcss/plugin");
|
||||||
const fs = require("fs")
|
const fs = require("fs");
|
||||||
const path = require("path")
|
const path = require("path");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: [
|
content: [
|
||||||
"./js/**/*.js",
|
"./js/**/*.js",
|
||||||
"../lib/elixir_ai_web.ex",
|
"../lib/elixir_ai_web.ex",
|
||||||
"../lib/elixir_ai_web/**/*.*ex"
|
"../lib/elixir_ai_web/**/*.*ex",
|
||||||
|
],
|
||||||
|
safelist: [
|
||||||
|
"bg-cyan-950/30",
|
||||||
|
"bg-red-950/30",
|
||||||
|
"bg-green-950/30",
|
||||||
|
"bg-blue-950/30",
|
||||||
|
"bg-yellow-950/30",
|
||||||
|
"bg-purple-950/30",
|
||||||
|
"bg-pink-950/30",
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {
|
extend: {
|
||||||
colors: {
|
colors: {
|
||||||
brand: "#FD4F00",
|
brand: "#FD4F00",
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
@@ -25,50 +34,71 @@ module.exports = {
|
|||||||
//
|
//
|
||||||
// <div class="phx-click-loading:animate-ping">
|
// <div class="phx-click-loading:animate-ping">
|
||||||
//
|
//
|
||||||
plugin(({addVariant}) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])),
|
plugin(({ addVariant }) =>
|
||||||
plugin(({addVariant}) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])),
|
addVariant("phx-click-loading", [
|
||||||
plugin(({addVariant}) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])),
|
".phx-click-loading&",
|
||||||
|
".phx-click-loading &",
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
plugin(({ addVariant }) =>
|
||||||
|
addVariant("phx-submit-loading", [
|
||||||
|
".phx-submit-loading&",
|
||||||
|
".phx-submit-loading &",
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
plugin(({ addVariant }) =>
|
||||||
|
addVariant("phx-change-loading", [
|
||||||
|
".phx-change-loading&",
|
||||||
|
".phx-change-loading &",
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
|
||||||
// Embeds Heroicons (https://heroicons.com) into your app.css bundle
|
// Embeds Heroicons (https://heroicons.com) into your app.css bundle
|
||||||
// See your `CoreComponents.icon/1` for more information.
|
// See your `CoreComponents.icon/1` for more information.
|
||||||
//
|
//
|
||||||
plugin(function({matchComponents, theme}) {
|
plugin(function ({ matchComponents, theme }) {
|
||||||
let iconsDir = path.join(__dirname, "../deps/heroicons/optimized")
|
let iconsDir = path.join(__dirname, "../deps/heroicons/optimized");
|
||||||
let values = {}
|
let values = {};
|
||||||
let icons = [
|
let icons = [
|
||||||
["", "/24/outline"],
|
["", "/24/outline"],
|
||||||
["-solid", "/24/solid"],
|
["-solid", "/24/solid"],
|
||||||
["-mini", "/20/solid"],
|
["-mini", "/20/solid"],
|
||||||
["-micro", "/16/solid"]
|
["-micro", "/16/solid"],
|
||||||
]
|
];
|
||||||
icons.forEach(([suffix, dir]) => {
|
icons.forEach(([suffix, dir]) => {
|
||||||
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
|
fs.readdirSync(path.join(iconsDir, dir)).forEach((file) => {
|
||||||
let name = path.basename(file, ".svg") + suffix
|
let name = path.basename(file, ".svg") + suffix;
|
||||||
values[name] = {name, fullPath: path.join(iconsDir, dir, file)}
|
values[name] = { name, fullPath: path.join(iconsDir, dir, file) };
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
matchComponents({
|
matchComponents(
|
||||||
"hero": ({name, fullPath}) => {
|
{
|
||||||
let content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, "")
|
hero: ({ name, fullPath }) => {
|
||||||
let size = theme("spacing.6")
|
let content = fs
|
||||||
if (name.endsWith("-mini")) {
|
.readFileSync(fullPath)
|
||||||
size = theme("spacing.5")
|
.toString()
|
||||||
} else if (name.endsWith("-micro")) {
|
.replace(/\r?\n|\r/g, "");
|
||||||
size = theme("spacing.4")
|
let size = theme("spacing.6");
|
||||||
}
|
if (name.endsWith("-mini")) {
|
||||||
return {
|
size = theme("spacing.5");
|
||||||
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
|
} else if (name.endsWith("-micro")) {
|
||||||
"-webkit-mask": `var(--hero-${name})`,
|
size = theme("spacing.4");
|
||||||
"mask": `var(--hero-${name})`,
|
}
|
||||||
"mask-repeat": "no-repeat",
|
return {
|
||||||
"background-color": "currentColor",
|
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
|
||||||
"vertical-align": "middle",
|
"-webkit-mask": `var(--hero-${name})`,
|
||||||
"display": "inline-block",
|
mask: `var(--hero-${name})`,
|
||||||
"width": size,
|
"mask-repeat": "no-repeat",
|
||||||
"height": size
|
"background-color": "currentColor",
|
||||||
}
|
"vertical-align": "middle",
|
||||||
}
|
display: "inline-block",
|
||||||
}, {values})
|
width: size,
|
||||||
})
|
height: size,
|
||||||
]
|
};
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
{ values },
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ defmodule ElixirAi.ConversationManager do
|
|||||||
{:reply, Map.get(conversations, name, []), state}
|
{:reply, Map.get(conversations, name, []), state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_info({:db_error, reason}, state) do
|
||||||
|
Logger.error("ConversationManager received db_error: #{inspect(reason)}")
|
||||||
|
{:noreply, state}
|
||||||
|
end
|
||||||
|
|
||||||
def handle_info({:store_message, name, message}, %{conversations: conversations} = state) do
|
def handle_info({:store_message, name, message}, %{conversations: conversations} = state) do
|
||||||
case Conversation.find_id(name) do
|
case Conversation.find_id(name) do
|
||||||
{:ok, conv_id} ->
|
{:ok, conv_id} ->
|
||||||
|
|||||||
@@ -7,19 +7,23 @@ defmodule ElixirAi.Data.DbHelpers do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run_sql(sql, params, topic) do
|
def run_sql(sql, params, topic) do
|
||||||
|
original_sql = sql
|
||||||
|
original_params = params
|
||||||
{sql, params} = named_params_to_positional_params(sql, params)
|
{sql, params} = named_params_to_positional_params(sql, params)
|
||||||
|
|
||||||
try do
|
try do
|
||||||
result = Ecto.Adapters.SQL.query!(ElixirAi.Repo, sql, params)
|
result = Ecto.Adapters.SQL.query!(ElixirAi.Repo, sql, params)
|
||||||
|
|
||||||
# Transform rows to maps with column names as keys
|
# Transform rows to maps with column names as keys
|
||||||
Enum.map(result.rows, fn row ->
|
Enum.map(result.rows || [], fn row ->
|
||||||
Enum.zip(result.columns, row)
|
Enum.zip(result.columns, row)
|
||||||
|> Enum.into(%{})
|
|> Enum.into(%{})
|
||||||
end)
|
end)
|
||||||
rescue
|
rescue
|
||||||
exception ->
|
exception ->
|
||||||
Logger.error("Database error: #{Exception.message(exception)}")
|
Logger.error("Database error: #{Exception.message(exception)}")
|
||||||
|
Logger.error("Failed SQL: #{original_sql}")
|
||||||
|
Logger.error("SQL params: #{inspect(original_params, pretty: true)}")
|
||||||
|
|
||||||
Phoenix.PubSub.broadcast(
|
Phoenix.PubSub.broadcast(
|
||||||
ElixirAi.PubSub,
|
ElixirAi.PubSub,
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ defmodule ElixirAi.Message do
|
|||||||
$(role),
|
$(role),
|
||||||
$(content),
|
$(content),
|
||||||
$(reasoning_content),
|
$(reasoning_content),
|
||||||
$(tool_calls),
|
$(tool_calls)::jsonb,
|
||||||
$(tool_call_id),
|
$(tool_call_id),
|
||||||
$(inserted_at)
|
$(inserted_at)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,53 +24,62 @@ defmodule ElixirAiWeb.HomeLive do
|
|||||||
<div>
|
<div>
|
||||||
<h1 class="text-lg font-semibold text-cyan-300 mb-8">Conversations</h1>
|
<h1 class="text-lg font-semibold text-cyan-300 mb-8">Conversations</h1>
|
||||||
|
|
||||||
<ul class="mb-8 space-y-2">
|
<.conversation_list conversations={@conversations} />
|
||||||
<%= if @conversations == [] do %>
|
|
||||||
<li class="text-sm text-cyan-700">No conversations yet.</li>
|
|
||||||
<% end %>
|
|
||||||
<%= for name <- @conversations do %>
|
|
||||||
<li>
|
|
||||||
<.link
|
|
||||||
navigate={~p"/chat/#{name}"}
|
|
||||||
class="block px-4 py-2 rounded-lg border border-cyan-900/40 bg-cyan-950/20 text-cyan-300 hover:border-cyan-700 hover:bg-cyan-950/40 transition-colors text-sm"
|
|
||||||
>
|
|
||||||
{name}
|
|
||||||
</.link>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<form phx-submit="create" class="space-y-2">
|
<.create_conversation_form new_name={@new_name} ai_providers={@ai_providers} />
|
||||||
<.input type="text" name="name" value={@new_name} label="Conversation Name" />
|
|
||||||
<select
|
|
||||||
name="ai_provider_id"
|
|
||||||
class="w-full rounded px-3 py-2 text-sm bg-cyan-950/20 border border-cyan-900/40 text-cyan-100 focus:outline-none focus:ring-1 focus:ring-cyan-700"
|
|
||||||
>
|
|
||||||
<option value="">Select AI Provider</option>
|
|
||||||
<%= for provider <- @ai_providers do %>
|
|
||||||
<option value={provider.id}>{provider.name} - {provider.model_name}</option>
|
|
||||||
<% end %>
|
|
||||||
</select>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="w-full px-4 py-2 rounded text-sm border border-cyan-900/40 bg-cyan-950/20 text-cyan-300 hover:border-cyan-700 hover:bg-cyan-950/40 transition-colors"
|
|
||||||
>
|
|
||||||
Create
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<%= if @error do %>
|
<%= if @error do %>
|
||||||
<p class="mt-2 text-sm text-red-400">{@error}</p>
|
<p class="mt-2 text-sm text-red-400">{@error}</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%!-- <div>
|
|
||||||
<.live_component module={ElixirAiWeb.AiProvidersLive} id="ai-providers" />
|
|
||||||
</div> --%>
|
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp conversation_list(assigns) do
|
||||||
|
~H"""
|
||||||
|
<ul class="mb-8 space-y-2">
|
||||||
|
<%= if @conversations == [] do %>
|
||||||
|
<li class="text-sm text-cyan-700">No conversations yet.</li>
|
||||||
|
<% end %>
|
||||||
|
<%= for name <- @conversations do %>
|
||||||
|
<li>
|
||||||
|
<.link
|
||||||
|
navigate={~p"/chat/#{name}"}
|
||||||
|
class="block px-4 py-2 rounded-lg border border-cyan-900/40 bg-cyan-950/20 text-cyan-300 hover:border-cyan-700 hover:bg-cyan-950/40 transition-colors text-sm"
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</.link>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
defp create_conversation_form(assigns) do
|
||||||
|
~H"""
|
||||||
|
<form phx-submit="create" class="space-y-2">
|
||||||
|
<.input type="text" name="name" value={@new_name} label="Conversation Name" />
|
||||||
|
<select
|
||||||
|
name="ai_provider_id"
|
||||||
|
class="w-full rounded px-3 py-2 text-sm bg-cyan-950/20 border border-cyan-900/40 text-cyan-100 focus:outline-none focus:ring-1 focus:ring-cyan-700"
|
||||||
|
>
|
||||||
|
<%= for {provider, index} <- Enum.with_index(@ai_providers) do %>
|
||||||
|
<option value={provider.id} selected={index == 0}>
|
||||||
|
{provider.name} - {provider.model_name}
|
||||||
|
</option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="w-full px-4 py-2 rounded text-sm border border-cyan-900/40 bg-cyan-950/20 text-cyan-300 hover:border-cyan-700 hover:bg-cyan-950/40 transition-colors"
|
||||||
|
>
|
||||||
|
Create
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
def handle_event("create", %{"name" => name, "ai_provider_id" => provider_id}, socket) do
|
def handle_event("create", %{"name" => name, "ai_provider_id" => provider_id}, socket) do
|
||||||
name = String.trim(name)
|
name = String.trim(name)
|
||||||
|
|
||||||
|
|||||||
2
mix.exs
2
mix.exs
@@ -32,7 +32,7 @@ defmodule ElixirAi.MixProject do
|
|||||||
# Type `mix help deps` for examples and options.
|
# Type `mix help deps` for examples and options.
|
||||||
defp deps do
|
defp deps do
|
||||||
[
|
[
|
||||||
{:phoenix, "~> 1.7.18"},
|
{:phoenix, "~> 1.7.21"},
|
||||||
{:phoenix_html, "~> 4.1"},
|
{:phoenix_html, "~> 4.1"},
|
||||||
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
||||||
{:phoenix_live_view, "~> 1.0.0"},
|
{:phoenix_live_view, "~> 1.0.0"},
|
||||||
|
|||||||
Reference in New Issue
Block a user