Skip to main content

dispatch_to_qa.py

Source: sunholo/agents/dispatch_to_qa.py

Functions

send_to_qa(user_input, vector_name, chat_history, stream=False, **kwargs)

Sends a query to the QA system synchronously.

Args: user_input (str): The user's input query. vector_name (str): The name of the vector. chat_history (list): The history of previous chat messages. stream (bool): Whether to stream the response. **kwargs: Additional key-value pairs for request data.

Returns: Union[dict, generator]: The response from the QA system, either as a JSON object or as a generator for streaming.

Example:

response = send_to_qa("What is AI?", "my_vector", [])
print(response)
# Output: {'answer': 'The definition of AI is ...'}

send_to_qa_async(user_input, vector_name, chat_history, stream=False, **kwargs)

Sends a query to the QA system asynchronously.

Args: user_input (str): The user's input query. vector_name (str): The name of the vector. chat_history (list): The history of previous chat messages. stream (bool): Whether to stream the response. **kwargs: Additional key-value pairs for request data.

Returns: generator: A generator that yields chunks of the streamed response or the entire response.

Example:

async def example_async_query():
async for response_chunk in send_to_qa_async("What is AI?", "my_vector", []):
print(response_chunk)

add_header_ids(header, **kwargs)

Adds user and session IDs to the request header if they are provided.

Args: header (dict): The original request header. **kwargs: Additional key-value pairs for header data.

Returns: dict: The updated header.

Example:

header = {"Authorization": "Bearer some_token"}
updated_header = add_header_ids(header, user_id="user_123", session_id="session_456")
print(updated_header)
# Output: {'Authorization': 'Bearer some_token', 'X-User-ID': 'user_123', 'X-Session-ID': 'session_456'}

prep_request_payload(user_input, chat_history, vector_name, stream, **kwargs)

Prepares the request payload for sending a query to the QA system.

Args: user_input (str): The user's input query. chat_history (list): The history of previous chat messages. vector_name (str): The name of the vector. stream (bool): Whether the request will be streamed. **kwargs: Additional key-value pairs for request data.

Returns: tuple: The endpoint URL and the prepared data payload.

Example:

user_input = "What is AI?"
chat_history = []
vector_name = "my_vector"
stream = False
endpoint, payload = prep_request_payload(user_input, chat_history, vector_name, stream)
print(endpoint, payload)
# Output: 'http://example.com/invoke' {'user_input': 'What is AI?', 'chat_history': []}
Sunholo Multivac

Get in touch to see if we can help with your GenAI project.

Contact us

Other Links

Sunholo Multivac - GenAIOps

Copyright ©

Holosun ApS 2024