summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-09 17:33:12 +0000
committerJordan Bracco <href@random.sh>2022-12-11 02:03:36 +0000
commit6e35caf80d43ec3f42504d580f3341353d6a776e (patch)
tree493d8cc44d2f2e6477114a256a2e5e493af0230b
parentgpt improvements (diff)
gpt web wip
-rw-r--r--lib/lsg_web/controllers/gpt_controller.ex33
-rw-r--r--lib/lsg_web/router.ex4
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/lsg_web/controllers/gpt_controller.ex b/lib/lsg_web/controllers/gpt_controller.ex
new file mode 100644
index 0000000..acf9b27
--- /dev/null
+++ b/lib/lsg_web/controllers/gpt_controller.ex
@@ -0,0 +1,33 @@
+defmodule LSGWeb.GptController do
+ use LSGWeb, :controller
+ require Logger
+
+ plug LSGWeb.ContextPlug
+
+ def result(conn, params = %{"id" => result_id}) do
+ case LSG.IRC.GptPlugin.get_result(result_id) do
+ {:ok, result} ->
+ network = Map.get(params, "network")
+ channel = if c = Map.get(params, "chan"), do: LSGWeb.reformat_chan(c)
+ render(conn, "result.html", network: network, channel: channel, result: result)
+ {:error, :not_found} ->
+ conn
+ |> put_status(404)
+ |> text("Page not found")
+ end
+ end
+
+ def prompt(conn, params = %{"id" => prompt_id}) do
+ case LSG.IRC.GptPlugin.get_prompt(prompt_id) do
+ {:ok, prompt} ->
+ network = Map.get(params, "network")
+ channel = if c = Map.get(params, "chan"), do: LSGWeb.reformat_chan(c)
+ render(conn, "prompt.html", network: network, channel: channel, prompt: prompt)
+ {:error, :not_found} ->
+ conn
+ |> put_status(404)
+ |> text("Page not found")
+ end
+ end
+
+end
diff --git a/lib/lsg_web/router.ex b/lib/lsg_web/router.ex
index eba71dc..5cc0d4a 100644
--- a/lib/lsg_web/router.ex
+++ b/lib/lsg_web/router.ex
@@ -40,6 +40,8 @@ defmodule LSGWeb.Router do
get "/-", IrcController, :index
get "/-/txt", IrcController, :txt
get "/-/txt/:name", IrcController, :txt
+ get "/-/gpt/prompt/:id", GptController, :task
+ get "/-/gpt/result/:id", GptController, :result
get "/-/alcoolog", AlcoologController, :index
get "/-/alcoolog/~/:account_name", AlcoologController, :index
@@ -52,6 +54,8 @@ defmodule LSGWeb.Router do
get "/:network/~:nick/alcoolog/stats.json", AlcoologController, :nick_stats_json
get "/:network/:chan/alcoolog", AlcoologController, :index
get "/:network/:chan/alcoolog/gls.json", AlcoologController, :index_gls_json
+ get "/:network/:chan/gpt/prompt/:id", GptController, :task
+ get "/:network/:chan/gpt/result/:id", GptController, :result
put "/api/alcoolog/minisync/:user_id/meta/:key", AlcoologController, :minisync_put_meta
get "/:network/:chan", IrcController, :index