from omegaconf import OmegaConf from query import VectaraQuery import os import gradio as gr def isTrue(x) -> bool: if isinstance(x, bool): return x return x.strip().lower() == 'true' corpus_keys = str(os.environ['corpus_keys']).split(',') cfg = OmegaConf.create({ 'corpus_keys': corpus_keys, 'api_key': str(os.environ['api_key']), 'title': os.environ['title'], 'description': os.environ['description'], 'source_data_desc': os.environ['source_data_desc'], 'streaming': isTrue(os.environ.get('streaming', False)), 'prompt_name': os.environ.get('prompt_name', None), 'examples': os.environ.get('examples', None) }) vq = VectaraQuery(cfg.api_key, cfg.corpus_keys, cfg.prompt_name) def respond(message, history): if cfg.streaming: # Call stream response and stream output stream = vq.submit_query_streaming(message) outputs = "" for output in stream: outputs += output yield outputs else: # Call non-stream response and return message output response = vq.submit_query(message) yield response cfg.description = f'''
{cfg.title} |
This demo uses Retrieval Augmented Generation from Vectara to ask questions about {cfg.source_data_desc}. |