mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
Demo warning in /chat UI (#466)
* Add demo warning to /chat * Missed two files! * Function calling works now, update message
This commit is contained in:
@@ -9,6 +9,8 @@ class ApplicationController < ActionController::Base
|
||||
before_action :set_default_chat
|
||||
before_action :set_active_storage_url_options
|
||||
|
||||
helper_method :demo_config, :demo_host_match?, :show_demo_warning?
|
||||
|
||||
private
|
||||
def detect_os
|
||||
user_agent = request.user_agent
|
||||
@@ -35,4 +37,20 @@ class ApplicationController < ActionController::Base
|
||||
port: request.optional_port
|
||||
}
|
||||
end
|
||||
|
||||
def demo_config
|
||||
Rails.application.config_for(:demo)
|
||||
rescue RuntimeError, Errno::ENOENT, Psych::SyntaxError
|
||||
nil
|
||||
end
|
||||
|
||||
def demo_host_match?(demo = demo_config)
|
||||
return false unless demo.is_a?(Hash) && demo["hosts"].present?
|
||||
|
||||
demo["hosts"].include?(request.host)
|
||||
end
|
||||
|
||||
def show_demo_warning?
|
||||
demo_host_match?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,19 +5,13 @@ class SessionsController < ApplicationController
|
||||
layout "auth"
|
||||
|
||||
def new
|
||||
begin
|
||||
demo = Rails.application.config_for(:demo)
|
||||
@prefill_demo_credentials = demo_host_match?(demo)
|
||||
if @prefill_demo_credentials
|
||||
@email = params[:email].presence || demo["email"]
|
||||
@password = params[:password].presence || demo["password"]
|
||||
else
|
||||
@email = params[:email]
|
||||
@password = params[:password]
|
||||
end
|
||||
rescue RuntimeError, Errno::ENOENT, Psych::SyntaxError
|
||||
# Demo config file missing or malformed - disable demo credential prefilling
|
||||
@prefill_demo_credentials = false
|
||||
demo = demo_config
|
||||
@prefill_demo_credentials = demo_host_match?(demo)
|
||||
|
||||
if @prefill_demo_credentials
|
||||
@email = params[:email].presence || demo["email"]
|
||||
@password = params[:password].presence || demo["password"]
|
||||
else
|
||||
@email = params[:email]
|
||||
@password = params[:password]
|
||||
end
|
||||
@@ -91,10 +85,4 @@ class SessionsController < ApplicationController
|
||||
def set_session
|
||||
@session = Current.user.sessions.find(params[:id])
|
||||
end
|
||||
|
||||
def demo_host_match?(demo)
|
||||
return false unless demo.present? && demo["hosts"].present?
|
||||
|
||||
demo["hosts"].include?(request.host)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<div data-controller="chat hotkey">
|
||||
<%= turbo_frame_tag chat_frame do %>
|
||||
<div class="flex flex-col h-full md:p-4">
|
||||
<% if show_demo_warning? %>
|
||||
<%= render "shared/demo_warning",
|
||||
title: t("chats.demo_banner_title"),
|
||||
message: t("chats.demo_banner_message") %>
|
||||
<% end %>
|
||||
|
||||
<% if @chats.any? %>
|
||||
<div class="grow flex flex-col">
|
||||
<div class="flex items-center justify-between my-6">
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
<div class="flex flex-col h-full md:p-4">
|
||||
<%= render "chats/chat_nav", chat: @chat %>
|
||||
|
||||
<% if show_demo_warning? %>
|
||||
<%= render "shared/demo_warning",
|
||||
title: t("chats.demo_banner_title"),
|
||||
message: t("chats.demo_banner_message") %>
|
||||
<% end %>
|
||||
|
||||
<div class="mt-auto py-8">
|
||||
<%= render "chats/ai_greeting" %>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
<div class="flex flex-col h-full">
|
||||
<div class="md:p-4">
|
||||
<%= render "chats/chat_nav", chat: @chat %>
|
||||
|
||||
<% if show_demo_warning? %>
|
||||
<%= render "shared/demo_warning",
|
||||
title: t("chats.demo_banner_title"),
|
||||
message: t("chats.demo_banner_message") %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="messages" class="grow overflow-y-auto p-4 space-y-6 pb-24 lg:pb-4" data-chat-target="messages">
|
||||
|
||||
13
app/views/shared/_demo_warning.html.erb
Normal file
13
app/views/shared/_demo_warning.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<%# locals: title:, message: %>
|
||||
<div class="mb-4 rounded-lg border bg-blue-50 text-blue-700 border-blue-200 theme-dark:bg-blue-900/20 theme-dark:text-blue-400 theme-dark:border-blue-800 p-4" role="status" aria-live="polite">
|
||||
<div class="flex items-start gap-3">
|
||||
<div class="shrink-0">
|
||||
<%= icon "info", size: "sm", color: "blue-600" %>
|
||||
</div>
|
||||
<div class="flex-1 text-sm">
|
||||
<h3 class="font-semibold mb-1"><%= title %></h3>
|
||||
<p><%= message %></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
6
config/locales/views/chats/en.yml
Normal file
6
config/locales/views/chats/en.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
en:
|
||||
chats:
|
||||
demo_banner_title: "Demo Mode Active"
|
||||
demo_banner_message: "You are using an open-weights Qwen3 LLM with credits provided by Cloudflare Workers AI. Result may vary since the codebase was mostly tested on `gpt-4.1` but your tokens don't go anywhere else to be trained with! 🤖"
|
||||
|
||||
Reference in New Issue
Block a user