Utils
Utility functions for the OpenAI Lambda functions
- smarter.apps.prompt.providers.utils.ensure_system_role_present(messages, default_system_role='You are a helpful chatbot. When given the opportunity to utilize function calling, you should always do so. This will allow you to provide the best possible responses to the user. If you are unable to provide a response, you should prompt the user for more information. If you are still unable to provide a response, you should inform the user that you are unable to help them at this time.')[source]
Ensure that a system role is present in the messages list
- Return type:
- smarter.apps.prompt.providers.utils.exception_response_factory(exception, request_meta_data=None)[source]
Generate a standardized error response dictionary that includes the Python exception type and stack trace.
exception: a descendant of Python Exception class
- smarter.apps.prompt.providers.utils.get_content_for_role(messages, role)[source]
Get the text content from the messages list for a given role
- Return type:
- smarter.apps.prompt.providers.utils.get_message_history(messages)[source]
Get the text content from the messages list for a given role
- Return type:
- smarter.apps.prompt.providers.utils.get_messages_for_role(messages, role)[source]
Get the text content from the messages list for a given role
- Return type:
- smarter.apps.prompt.providers.utils.get_request_body(data)[source]
Returns the request body as a dictionary.
- Return type:
- Parameters:
event – The event object containing the request body.
- Returns:
A dictionary representing the request body.
- smarter.apps.prompt.providers.utils.http_response_factory(status_code, body, debug_mode=False)[source]
Generate a standardized JSON return dictionary for all possible response scenarios.
status_code: an HTTP response code. see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status body: a JSON dict of http response for status 200, an error dict otherwise.
see https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html