|
16 | 16 | from knowledge_gpt.core.chunking import chunk_file |
17 | 17 | from knowledge_gpt.core.embedding import embed_files |
18 | 18 | from knowledge_gpt.core.qa import query_folder |
| 19 | +from knowledge_gpt.core.utils import get_llm |
| 20 | + |
19 | 21 |
|
20 | 22 | EMBEDDING = "openai" |
21 | 23 | VECTOR_STORE = "faiss" |
22 | | -MODEL = "openai" |
| 24 | +MODEL_LIST = ["gpt-3.5-turbo", "gpt-4"] |
23 | 25 |
|
24 | | -# For testing |
25 | | -EMBEDDING, VECTOR_STORE, MODEL = ["debug"] * 3 |
| 26 | +# Uncomment to enable debug mode |
| 27 | +# MODEL_LIST.insert(0, "debug") |
26 | 28 |
|
27 | 29 | st.set_page_config(page_title="KnowledgeGPT", page_icon="📖", layout="wide") |
28 | 30 | st.header("📖KnowledgeGPT") |
|
48 | 50 | help="Scanned documents are not supported yet!", |
49 | 51 | ) |
50 | 52 |
|
| 53 | +model: str = st.selectbox("Model", options=MODEL_LIST) # type: ignore |
| 54 | + |
| 55 | +with st.expander("Advanced Options"): |
| 56 | + return_all_chunks = st.checkbox("Show all chunks retrieved from vector search") |
| 57 | + show_full_doc = st.checkbox("Show parsed contents of the document") |
| 58 | + |
| 59 | + |
51 | 60 | if not uploaded_file: |
52 | 61 | st.stop() |
53 | 62 |
|
|
61 | 70 | if not is_file_valid(file): |
62 | 71 | st.stop() |
63 | 72 |
|
64 | | -if MODEL != "debug" and not is_open_ai_key_valid(openai_api_key): |
| 73 | + |
| 74 | +if not is_open_ai_key_valid(openai_api_key, model): |
65 | 75 | st.stop() |
66 | 76 |
|
67 | 77 |
|
68 | 78 | with st.spinner("Indexing document... This may take a while⏳"): |
69 | 79 | folder_index = embed_files( |
70 | 80 | files=[chunked_file], |
71 | | - embedding=EMBEDDING, |
72 | | - vector_store=VECTOR_STORE, |
| 81 | + embedding=EMBEDDING if model != "debug" else "debug", |
| 82 | + vector_store=VECTOR_STORE if model != "debug" else "debug", |
73 | 83 | openai_api_key=openai_api_key, |
74 | 84 | ) |
75 | 85 |
|
|
78 | 88 | submit = st.form_submit_button("Submit") |
79 | 89 |
|
80 | 90 |
|
81 | | -with st.expander("Advanced Options"): |
82 | | - return_all_chunks = st.checkbox("Show all chunks retrieved from vector search") |
83 | | - show_full_doc = st.checkbox("Show parsed contents of the document") |
84 | | - |
85 | | - |
86 | 91 | if show_full_doc: |
87 | 92 | with st.expander("Document"): |
88 | 93 | # Hack to get around st.markdown rendering LaTeX |
|
96 | 101 | # Output Columns |
97 | 102 | answer_col, sources_col = st.columns(2) |
98 | 103 |
|
| 104 | + llm = get_llm(model=model, openai_api_key=openai_api_key, temperature=0) |
99 | 105 | result = query_folder( |
100 | 106 | folder_index=folder_index, |
101 | 107 | query=query, |
102 | 108 | return_all=return_all_chunks, |
103 | | - model=MODEL, |
104 | | - openai_api_key=openai_api_key, |
105 | | - temperature=0, |
| 109 | + llm=llm, |
106 | 110 | ) |
107 | 111 |
|
108 | 112 | with answer_col: |
|
0 commit comments