Update app.py
Browse files53 unmodified lines54555657585960616263646566673 unmodified lines7172737475767778798081828384858619 unmodified lines10610710810911011111289 unmodified lines20220320420520620720820921021121253 unmodified linesdescription="List of sources to cite. Should be an URL of the source.")def chatbot_interface(message, history, model, temperature, num_calls, use_embeddings, system_prompt):if not message.strip():return "", historyhistory = history + [(message, "")]try:for response in respond(message, history, model, temperature, num_calls, use_embeddings, system_prompt):history[-1] = (message, response)yield historyexcept gr.CancelledError:3 unmodified lineshistory[-1] = (message, f"An unexpected error occurred: {str(e)}")yield historydef retry_last_response(history, model, temperature, num_calls, use_embeddings, system_prompt):if not history:return historylast_user_msg = history[-1][0]history = history[:-1] # Remove the last responsereturn chatbot_interface(last_user_msg, history, model, temperature, num_calls, use_embeddings, system_prompt)def respond(message, history, model, temperature, num_calls, use_embeddings, system_prompt):logging.info(f"User Query: {message}")logging.info(f"Model Used: {model}")logging.info(f"Use Embeddings: {use_embeddings}")19 unmodified linesreturn FAISS.from_documents(documents, embed)def get_response_with_search(query, model, num_calls=3, temperature=0.2, use_embeddings=True, system_prompt=DEFAULT_SYSTEM_PROMPT):search_results = duckduckgo_search(query)if use_embeddings:89 unmodified linesrespond,additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),additional_inputs=[gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),gr.Checkbox(label="Use Embeddings", value=False),gr.Textbox(label="System Prompt", lines=5, value=DEFAULT_SYSTEM_PROMPT),],title="AI-powered Web Search Assistant",description="Ask questions and get answers from web search results.",53 unmodified lines54555657585960616263646566673 unmodified lines7172737475767778798081828384858619 unmodified lines10610710810911011111289 unmodified lines20220320420520620720820921021121253 unmodified linesdescription="List of sources to cite. Should be an URL of the source.")def chatbot_interface(message, system_prompt, history, model, temperature, num_calls, use_embeddings):if not message.strip():return "", historyhistory = history + [(message, "")]try:for response in respond(message, system_prompt, history, model, temperature, num_calls, use_embeddings):history[-1] = (message, response)yield historyexcept gr.CancelledError:3 unmodified lineshistory[-1] = (message, f"An unexpected error occurred: {str(e)}")yield historydef retry_last_response(system_prompt, history, model, temperature, num_calls, use_embeddings):if not history:return historylast_user_msg = history[-1][0]history = history[:-1] # Remove the last responsereturn chatbot_interface(last_user_msg, , system_prompt, history, model, temperature, num_calls, use_embeddings)def respond(message, system_prompt, history, model, temperature, num_calls, use_embeddings):logging.info(f"User Query: {message}")logging.info(f"Model Used: {model}")logging.info(f"Use Embeddings: {use_embeddings}")19 unmodified linesreturn FAISS.from_documents(documents, embed)def get_response_with_search(query, system_prompt=DEFAULT_SYSTEM_PROMPT, model, num_calls=3, temperature=0.2, use_embeddings=True):search_results = duckduckgo_search(query)if use_embeddings:89 unmodified linesrespond,additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=True, render=False),additional_inputs=[gr.Textbox(label="System Prompt", lines=5, value=DEFAULT_SYSTEM_PROMPT),gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3]),gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),gr.Checkbox(label="Use Embeddings", value=False),],title="AI-powered Web Search Assistant",description="Ask questions and get answers from web search results.",
app.py+7-7