Repository navigation
Expand file tree
/
Copy pathscaffold.py
More file actions
105 lines (89 loc) · 3.28 KB
/
Copy pathscaffold.py
File metadata and controls
105 lines (89 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""Streamlit entrypoint for the AskLit Project Scaffolder.
The workflow lives in ``asklit.scaffold``, one module per step. This module
routes the selected step to its renderer and applies the access gate that
protects the steps which spend the host's model credits.
"""
import streamlit as st
from asklit.config import get_secret_value
from asklit.scaffold import access
from asklit.scaffold.config import default_scaffold_config, ensure_model_defaults
from asklit.scaffold.step_chat import render_chat_step
from asklit.scaffold.step_evaluate import render_evaluate_step
from asklit.scaffold.step_export import render_export_step
from asklit.scaffold.step_knowledge import render_knowledge_step
from asklit.scaffold.step_prompt import render_prompt_step
from asklit.scaffold.ui import (
BILLED_STEPS,
initialize_scaffold_storage,
render_next_step_button,
render_step_selector,
render_workspace_controls,
)
from asklit.ui import escape_html, safe_url
# Re-exported so existing imports of the pre-split module keep working.
from asklit.scaffold.bundle import ( # noqa: F401
DEFAULT_REPO_NAME,
create_bundle,
generate_deployment_secrets,
zip_directory,
)
from asklit.scaffold.workspace import ( # noqa: F401
export_workspace_yaml,
import_workspace_yaml,
sanitize_export_config,
)
STEP_RENDERERS = {
"knowledge": render_knowledge_step,
"prompt": render_prompt_step,
"chat": render_chat_step,
"evaluate": render_evaluate_step,
"export": render_export_step,
}
BILLED_STEP_LABELS = {"chat": "Chat preview", "evaluate": "Evaluate"}
def render_sidebar_branding():
"""Brand the scaffolder itself from operator-configured secrets."""
logo_url = safe_url(
get_secret_value(
"branding.logo_url",
"https://github.com/SuffolkLITLab/logos/raw/main/current-logo/png/lit-lab-logo-large.png",
)
)
homepage_url = safe_url(
get_secret_value("branding.homepage_url", "https://suffolklitlab.org")
)
if not logo_url:
return
st.sidebar.markdown(
f'<a href="{escape_html(homepage_url)}" target="_blank" rel="noopener noreferrer">'
f'<img src="{escape_html(logo_url)}" width="150"></a>',
unsafe_allow_html=True,
)
st.sidebar.divider()
def render_step(step_key):
"""Dispatch one step, gating the ones that make billed model calls."""
if step_key in BILLED_STEPS and not access.require_access(
BILLED_STEP_LABELS[step_key]
):
return False
STEP_RENDERERS[step_key]()
return True
def main():
render_sidebar_branding()
st.title("🧪 AskLit Project Scaffolder")
st.markdown(
"Add a knowledge base, write a prompt, try the assistant, and measure it "
"against gold-labeled scenarios. Export a deployable app when you are "
"satisfied with the results."
)
if "scaffold_id" not in st.session_state:
initialize_scaffold_storage()
if "app_config" not in st.session_state:
st.session_state.app_config = default_scaffold_config()
ensure_model_defaults(st.session_state.app_config)
render_workspace_controls()
access.render_access_status()
step_key = render_step_selector()
if render_step(step_key):
render_next_step_button(step_key)
if __name__ == "__main__":
main()