qna_routes.py
Source: sunholo/agents/flask/qna_routes.py
Functions
register_qna_routes(app, stream_interpreter, vac_interpreter)
Register Q&A routes for a Flask application.
This function sets up multiple routes for handling Q&A operations, including streaming responses and processing static responses.
Args: app (Flask): The Flask application instance. stream_interpreter (function): Function to handle streaming Q&A responses. vac_interpreter (function): Function to handle static Q&A responses.
Returns: None
Example: from flask import Flask app = Flask(name)
def dummy_stream_interpreter(...): ...
def dummy_vac_interpreter(...): ...
register_qna_routes(app, dummy_stream_interpreter, dummy_vac_interpreter)
create_langfuse_trace(request, vector_name)
Create a Langfuse trace for tracking requests.
This function initializes a Langfuse trace object based on the request headers and vector name.
Args: request (Request): The Flask request object. vector_name (str): The name of the vector for the request.
Returns: Langfuse.Trace: The Langfuse trace object.
Example: trace = create_langfuse_trace(request, "example_vector")
handle_file_upload(file, vector_name)
Handle file upload and store the file in Google Cloud Storage.
This function saves the uploaded file locally, uploads it to Google Cloud Storage, and then removes the local copy.
Args: file (FileStorage): The uploaded file. vector_name (str): The name of the vector for the request.
Returns: tuple: A tuple containing the URI of the uploaded file and its MIME type.
Raises: Exception: If the file upload fails.
Example: uri, mime_type = handle_file_upload(file, "example_vector")
make_openai_response(user_message, vector_name, answer)
No docstring available.
prep_vac(request, vector_name)
Prepare the input data for a VAC request.
This function processes the incoming request data, extracts relevant information, and prepares the data for VAC processing.
Args: request (Request): The Flask request object. vector_name (str): The name of the vector for the request.
Returns: dict: A dictionary containing prepared input data and metadata.
Example: prep_data = prep_vac(request, "example_vector")