Spaces:
Runtime error
Runtime error
Ganesh Chintalapati commited on
Commit ·
a64da77
1
Parent(s): fac7191
Fix syntax
Browse files45 unmodified lines46474849505152124 unmodified lines17717817918018118218318418518618718818919045 unmodified linesasync with httpx.AsyncClient() as client:async with client.stream("POST", "https://api.openai.com/v1/chat/completions", headers=headers, json=payload) as response:response.raise_for_status()async for chunk in response.intro_text():if chunk:# Parse the streaming chunk (JSON lines)lines = chunk.splitlines()124 unmodified linesasync def submit_query(query: str, provider: str, history: List[Dict[str, str]]) -> AsyncGenerator[Tuple[str, List[Dict[str, str]], List[Dict[str, str]]], None]:if not query.strip():yield "", history, historyreturnresponse = ""async for response_chunk, updated_history in query_model(query, provider, history):response += response_chunkyield "", updated_history, updated_history # Yield intermediate updates for streamingyield "", updated_history, updated_history # Final yield with cleared query# Gradio interfacedef clear_history():45 unmodified lines46474849505152124 unmodified lines17717817918018118218318418518618718818919019119219319419519619719819920020120220320420545 unmodified linesasync with httpx.AsyncClient() as client:async with client.stream("POST", "https://api.openai.com/v1/chat/completions", headers=headers, json=payload) as response:response.raise_for_status()async for chunk in response.aiter_text():if chunk:# Parse the streaming chunk (JSON lines)lines = chunk.splitlines()124 unmodified linesasync def submit_query(query: str, provider: str, history: List[Dict[str, str]]) -> AsyncGenerator[Tuple[str, List[Dict[str, str]], List[Dict[str, str]]], None]:if not query.strip():yield "", [{"role": "assistant", "content": "Please enter a query."}], historyreturnresponse = ""async for response_chunk, updated_history in query_model(query, provider, history):response += response_chunk# Convert history to chatbot messages formatchatbot_messages = []for msg in updated_history:chatbot_messages.append({"role": "user", "content": msg["user"]})if msg["bot"]:chatbot_messages.append({"role": "assistant", "content": msg["bot"]})if response and provider == "openai":# For streaming, show partial responsechatbot_messages[-1] = {"role": "assistant", "content": response}yield "", chatbot_messages, updated_history # Yield intermediate updates# Final yield with complete responsechatbot_messages = []for msg in updated_history:chatbot_messages.append({"role": "user", "content": msg["user"]})if msg["bot"]:chatbot_messages.append({"role": "assistant", "content": msg["bot"]})yield "", chatbot_messages, updated_history# Gradio interfacedef clear_history():
app.py+19-4