Update app.py
Browse files53 unmodified lines545556575758596061626364646566673 unmodified lines7172737474757677787980818182838384858619 unmodified lines10610710810910911011111289 unmodified lines20220320420520620720820920921021121253 unmodified lines description="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):def chatbot_interface(message, system_prompt, history, model, temperature, num_calls, use_embeddings): if not message.strip(): return "", history
history = history + [(message, "")]
try: for response in respond(message, history, model, temperature, num_calls, use_embeddings, system_prompt): for response in respond(message, system_prompt, history, model, temperature, num_calls, use_embeddings): history[-1] = (message, response) yield history except gr.CancelledError:3 unmodified lines history[-1] = (message, f"An unexpected error occurred: {str(e)}") yield history
def retry_last_response(history, model, temperature, num_calls, use_embeddings, system_prompt):def retry_last_response(system_prompt, history, model, temperature, num_calls, use_embeddings): if not history: return history last_user_msg = history[-1][0] history = history[:-1] # Remove the last response return chatbot_interface(last_user_msg, history, model, temperature, num_calls, use_embeddings, system_prompt) return chatbot_interface(last_user_msg, , system_prompt, history, model, temperature, num_calls, use_embeddings)
def respond(message, history, model, temperature, num_calls, use_embeddings, system_prompt):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 lines return 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):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 lines respond, 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), 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.",app.py+7-7