forked from phoenix/litellm-mirror
refactor: add black formatting
This commit is contained in:
parent
b87d630b0a
commit
4905929de3
156 changed files with 19723 additions and 10869 deletions
40
ui/admin.py
40
ui/admin.py
|
@ -2,6 +2,7 @@
|
|||
Admin sets proxy url + allowed email subdomain
|
||||
"""
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
import streamlit as st
|
||||
import base64, os
|
||||
|
@ -9,34 +10,47 @@ import base64, os
|
|||
# Replace your_base_url with the actual URL where the proxy auth app is hosted
|
||||
your_base_url = os.getenv("BASE_URL") # Example base URL
|
||||
|
||||
|
||||
# Function to encode the configuration
|
||||
def encode_config(proxy_url, allowed_email_subdomain):
|
||||
combined_string = f"proxy_url={proxy_url}&accepted_email_subdomain={allowed_email_subdomain}"
|
||||
return base64.b64encode(combined_string.encode('utf-8')).decode('utf-8')
|
||||
combined_string = (
|
||||
f"proxy_url={proxy_url}&accepted_email_subdomain={allowed_email_subdomain}"
|
||||
)
|
||||
return base64.b64encode(combined_string.encode("utf-8")).decode("utf-8")
|
||||
|
||||
|
||||
# Simple function to update config values
|
||||
def update_config(proxy_url, allowed_email_subdomain):
|
||||
st.session_state['proxy_url'] = proxy_url
|
||||
st.session_state['allowed_email_subdomain'] = allowed_email_subdomain
|
||||
st.session_state['user_auth_url'] = f"{your_base_url}/?page={encode_config(proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain)}"
|
||||
st.session_state["proxy_url"] = proxy_url
|
||||
st.session_state["allowed_email_subdomain"] = allowed_email_subdomain
|
||||
st.session_state[
|
||||
"user_auth_url"
|
||||
] = f"{your_base_url}/?page={encode_config(proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain)}"
|
||||
|
||||
|
||||
def admin_page():
|
||||
# Display the form for the admin to set the proxy URL and allowed email subdomain
|
||||
st.header("Admin Configuration")
|
||||
# Create a configuration placeholder
|
||||
st.session_state.setdefault('proxy_url', 'http://example.com')
|
||||
st.session_state.setdefault('allowed_email_subdomain', 'example.com')
|
||||
st.session_state.setdefault('user_auth_url', 'NOT_GIVEN')
|
||||
st.session_state.setdefault("proxy_url", "http://example.com")
|
||||
st.session_state.setdefault("allowed_email_subdomain", "example.com")
|
||||
st.session_state.setdefault("user_auth_url", "NOT_GIVEN")
|
||||
|
||||
with st.form("config_form", clear_on_submit=False):
|
||||
proxy_url = st.text_input("Set Proxy URL", st.session_state['proxy_url'])
|
||||
allowed_email_subdomain = st.text_input("Set Allowed Email Subdomain", st.session_state['allowed_email_subdomain'])
|
||||
proxy_url = st.text_input("Set Proxy URL", st.session_state["proxy_url"])
|
||||
allowed_email_subdomain = st.text_input(
|
||||
"Set Allowed Email Subdomain", st.session_state["allowed_email_subdomain"]
|
||||
)
|
||||
submitted = st.form_submit_button("Save")
|
||||
|
||||
if submitted:
|
||||
update_config(proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain)
|
||||
update_config(
|
||||
proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain
|
||||
)
|
||||
|
||||
# Display the current configuration
|
||||
st.write(f"Current Proxy URL: {st.session_state['proxy_url']}")
|
||||
st.write(f"Current Allowed Email Subdomain: {st.session_state['allowed_email_subdomain']}")
|
||||
st.write(f"Current User Auth URL: {st.session_state['user_auth_url']}")
|
||||
st.write(
|
||||
f"Current Allowed Email Subdomain: {st.session_state['allowed_email_subdomain']}"
|
||||
)
|
||||
st.write(f"Current User Auth URL: {st.session_state['user_auth_url']}")
|
||||
|
|
14
ui/app.py
14
ui/app.py
|
@ -2,6 +2,7 @@
|
|||
Routes between admin, auth, keys pages
|
||||
"""
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
import streamlit as st
|
||||
import base64, binascii, os
|
||||
|
@ -9,18 +10,20 @@ from admin import admin_page
|
|||
from auth import auth_page
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
|
||||
|
||||
# Parse the query params in the URL
|
||||
def get_query_params():
|
||||
# Get the query params from Streamlit's `server.request` function
|
||||
# This functionality is not officially documented and could change in the future versions of Streamlit
|
||||
query_params = st.experimental_get_query_params()
|
||||
return query_params
|
||||
query_params = st.experimental_get_query_params()
|
||||
return query_params
|
||||
|
||||
|
||||
def is_base64(sb):
|
||||
try:
|
||||
if isinstance(sb, str):
|
||||
# Try to encode it to bytes if it's a unicode string
|
||||
sb_bytes = sb.encode('ascii')
|
||||
sb_bytes = sb.encode("ascii")
|
||||
elif isinstance(sb, bytes):
|
||||
sb_bytes = sb
|
||||
else:
|
||||
|
@ -36,10 +39,11 @@ def is_base64(sb):
|
|||
except (binascii.Error, ValueError):
|
||||
# If an error occurs, return False, as the input is not base64
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# Check the URL path and route to the correct page based on the path
|
||||
query_params = get_query_params()
|
||||
page_param = query_params.get('page', [None])[0]
|
||||
page_param = query_params.get("page", [None])[0]
|
||||
|
||||
# Route to the appropriate page based on the URL query param
|
||||
if page_param:
|
||||
|
|
11
ui/auth.py
11
ui/auth.py
|
@ -6,9 +6,11 @@ Uses supabase passwordless auth: https://supabase.com/docs/reference/python/auth
|
|||
Remember to set your redirect url to 8501 (streamlit default).
|
||||
"""
|
||||
import logging
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
import streamlit as st
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
import os
|
||||
from supabase import create_client, Client
|
||||
|
@ -20,14 +22,13 @@ supabase: Client = create_client(url, key)
|
|||
|
||||
|
||||
def sign_in_with_otp(email: str, redirect_url: str):
|
||||
data = supabase.auth.sign_in_with_otp({"email": email,
|
||||
"options": {
|
||||
"email_redirect_to": redirect_url
|
||||
}})
|
||||
data = supabase.auth.sign_in_with_otp(
|
||||
{"email": email, "options": {"email_redirect_to": redirect_url}}
|
||||
)
|
||||
print(f"data: {data}")
|
||||
# Redirect to Supabase UI with the return data
|
||||
st.write(f"Please check your email for a login link!")
|
||||
|
||||
|
||||
|
||||
# Create the Streamlit app
|
||||
def auth_page(redirect_url: str):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue