66
77from autollm .auto .llm import AutoLiteLLM
88from autollm .auto .query_engine import AutoQueryEngine
9- from autollm .serve .prompts import LLM_BUILDER_SYSTEM_PROMPT
9+ from autollm .serve .llm_utils import create_custom_llm
1010from autollm .utils .document_reading import read_files_as_documents
1111
1212llama_index .set_global_handler ("simple" )
1313
14- llm_builder = AutoLiteLLM .from_defaults (system_prompt = LLM_BUILDER_SYSTEM_PROMPT )
1514
16-
17- def configure_app (
18- openai_api_key , palm_api_key , uploaded_files , webpage_input , what_to_make_area , config_file , emoji ,
19- name , description , instruction ):
15+ def create_app (openai_api_key , palm_api_key , what_to_make_area , uploaded_files , webpage_input , config_file ):
2016 global query_engine
2117 progress = gr .Progress ()
2218
@@ -26,6 +22,10 @@ def configure_app(
2622 progress (0.2 , desc = "Reading files..." )
2723 file_documents = read_files_as_documents (input_files = uploaded_files )
2824
25+ progress (0.4 , desc = "Updating LLM..." )
26+ custom_llm = create_custom_llm (user_prompt = what_to_make_area , config = config_file )
27+ emoji , name , description , instruction = update_configurations (custom_llm )
28+
2929 progress (0.8 , desc = "Configuring app.." )
3030 query_engine = AutoQueryEngine .from_defaults (
3131 documents = file_documents ,
@@ -36,8 +36,22 @@ def configure_app(
3636
3737 # Complete progress
3838 progress (1.0 , desc = "Completed" ) # Complete progress bar
39+ create_preview_output = gr .Textbox ("App preview created on the right screen." )
40+
41+ return create_preview_output , emoji , name , description , instruction
42+
43+
44+ def update_configurations (custom_llm ):
45+ emoji = custom_llm .emoji
46+ name = custom_llm .name
47+ description = custom_llm .description
48+ instruction = custom_llm .instructions
49+
50+ return gr .Textbox (emoji ), gr .Textbox (name ), gr .Textbox (description ), gr .Textbox (instruction )
51+
3952
40- return gr .Textbox ("App preview created on the right screen." )
53+ def update_app ():
54+ pass
4155
4256
4357def predict (message , history ):
@@ -89,15 +103,15 @@ def predict(message, history):
89103 with gr .Accordion (label = "Load config file" , open = False ):
90104 config_file_upload = gr .File (
91105 label = "Configurations of LLM, Vector Store.." , file_count = "single" )
92- emoji_input = gr .Textbox (label = "Emoji" )
93- name_input = gr .Textbox (label = "Name" )
94- description_input = gr .Textbox (label = "Description" )
95- instruction_input = gr .TextArea (label = "Instructions" )
106+ emoji = gr .Textbox (label = "Emoji" )
107+ name = gr .Textbox (label = "Name" )
108+ description = gr .Textbox (label = "Description" )
109+ instruction = gr .TextArea (label = "Instructions" )
96110 with gr .Row ():
97111 with gr .Column (scale = 1 , min_width = 10 ):
98112 placeholder = gr .Button (visible = False , interactive = False )
99113 with gr .Column (scale = 1 , min_width = 100 ):
100- create_preview_button_2 = gr .Button ("Create Preview" , variant = "primary" )
114+ update_preview_button = gr .Button ("Update Preview" , variant = "primary" )
101115 configure_output = gr .Textbox (label = "👆 Click `Create Preview` to see preview of the LLM app" )
102116 with gr .Tab ("Export" ):
103117 # Controls for 'Export' tab
@@ -121,18 +135,18 @@ def predict(message, history):
121135 chat_interface = gr .ChatInterface (predict , chatbot = chatbot )
122136
123137 create_preview_button .click (
124- configure_app ,
138+ create_app ,
125139 inputs = [
126- openai_api_key_input , palm_api_key_input , uploaded_files , webpage_input , what_to_make_area ,
127- config_file_upload , emoji_input , name_input , description_input , instruction_input
140+ openai_api_key_input , palm_api_key_input , what_to_make_area , uploaded_files , webpage_input ,
141+ config_file_upload
128142 ],
129- outputs = [create_preview_output ])
143+ outputs = [create_preview_output , emoji , name , description , instruction ])
130144
131- create_preview_button_2 .click (
132- configure_app ,
145+ update_preview_button .click (
146+ update_app ,
133147 inputs = [
134- openai_api_key_input , palm_api_key_input , uploaded_files , webpage_input , what_to_make_area ,
135- config_file_upload , emoji_input , name_input , description_input , instruction_input
148+ openai_api_key_input , palm_api_key_input , what_to_make_area , uploaded_files , webpage_input ,
149+ config_file_upload , emoji , name , description , instruction
136150 ],
137151 outputs = [configure_output ],
138152 scroll_to_output = True )
0 commit comments