Reference
main.py
Entry point that ensures necessary config and scripts are setup before handing off to app.py
main()
Create directories and embed scripts if needed, otw run options.read() and app.launch()
Source code in src/__main__.py
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 |
|
app.py
Gradio UI leveraging eponymous function in response
launch()
Launch app's Gradio UI
Source code in src/app.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
opt(option_name)
Syntactic sugar for retrieving options
Source code in src/app.py
10 11 12 |
|
chain.py
Setup language models and multi-query retriever, define the moderation and rag chains
create()
Set ChromaDB vectorstore (w/ opt('collection_name')) as a retriever and create rag_chain
Source code in src/chain.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
create_moderation()
Set Moderation LLM to local Ollama model, construct and return chain
Source code in src/chain.py
120 121 122 123 124 125 126 127 128 |
|
opt(option_name)
Syntactic sugar for retrieving options
Source code in src/chain.py
21 22 23 |
|
prepare_models()
Set num_gpu depending on whether opt('embeddings_gpu') is True or False
Source code in src/chain.py
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 |
|
prepare_prompts()
Define the contextualization prompt for summarizing chat history
Source code in src/chain.py
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 |
|
embeddings.py
Refreshes/generates embeddings in based on scripts
create_batches(all_splits, batch_size)
Breaks all_splits into batches of size <= batch_size
Source code in src/embeddings.py
36 37 38 39 |
|
generate()
Embed and store text documents
Source code in src/embeddings.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
load()
Loads documents in SCRIPTS_DIR
Source code in src/embeddings.py
24 25 26 27 28 29 30 31 32 33 |
|
opt(option_name)
Syntactic sugar for retrieving options
Source code in src/embeddings.py
19 20 21 |
|
prepare_model()
Set and return Ollama embeddings model
Source code in src/embeddings.py
53 54 55 56 57 58 59 60 |
|
split(docs)
Split documents, then divide into batches to avoid ChromaDB/SQLite batch size limitations
Source code in src/embeddings.py
42 43 44 45 46 47 48 49 50 |
|
multi-retriever.py
Define and return the rag-fusion retirever and output parser
prepare(num_queries)
Define output parser and MultiQueryRetriever
Source code in src/multi_retriever.py
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 |
|
options.py
Creates and reads options at ~/.config/chat-script/chat-script.ini
create()
Create options file at ~/.config/chat-script/chat-script.ini with defaults
Source code in src/options.py
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 |
|
read()
Read options from ~/.config/chat-script/chat-script.ini and save in global dict: options
Source code in src/options.py
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
response.py
Returns response w/ citations from RAG-enabled LLM based on user question passed from app ui
check_question(question, request)
Determines whether a response may be generated based on config and user input
Source code in src/response.py
34 35 36 37 38 39 40 41 42 43 |
|
convert_session_history(history)
Workaround for converting Gradio history to Langchain-compatible chat_history.
Source code in src/response.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
format_context(context)
Formats and yields context passed to LLM in human-readable format
Source code in src/response.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
generate(question, history, request)
Creates RAG + history chain w/ local LLM and streams chain's text response
Source code in src/response.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
get_session_history()
Manage chat history
Source code in src/response.py
65 66 67 |
|
inspect(state)
Print state between runnables and pass it on (includes: input, chat_history)
Source code in src/response.py
70 71 72 73 74 |
|
opt(option_name)
Syntactic sugar for retrieving options
Source code in src/response.py
29 30 31 |
|
prepare_rag_history()
Define retrieval chain w/ history
Source code in src/response.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
reject(question, request)
Display log, alert based on config
Source code in src/response.py
116 117 118 119 120 121 122 123 124 |
|
rejection_message()
Yield unsafe response info to user
Source code in src/response.py
127 128 129 130 131 132 133 134 |
|