common package
common.constants
import json, os
from django_core.config import Config
- class common.constants.Constants[source]
Bases:
object- ASR_DEFAULT_CONFIDENCE_SCORE = 0.7
- AZURE_SPEECH_SYNTHESIS_MODEL = 'AZURE_SPEECH_SYNTHESIS_MODEL'
- CHAT_HISTORY_WINDOW = 4
- COULD_NOT_UNDERSTAND_MESSAGE = 'could_not_understand_message'
- EMBEDDING_MODEL = 'text-embedding-3-small'
- GOOGLE_SPEECH_SYNTHESIS_MODEL = 'GOOGLE_SPEECH_SYNTHESIS_MODEL'
- HERE_ARE_FOLLOW_UP_QUESTIONS_TO_ASK_TEXT = '\n\nHere are the follow-up questions you can ask:\n'
- LANGUAGE_SHORT_CODE_ENG = 'en'
- MESSAGE_INPUT_TYPE_TEXT = 'text'
- MESSAGE_INPUT_TYPE_VOICE = 'voice'
- MP3 = 'mp3'
- MULTILINGUAL_ENG_TEXTS = {'could_not_understand_message': 'Apologize! I could not understand. Please try again.', 'unable_to_transcribe_the_voice_input_query': 'Unfortunately unable to transcribe the above voice input query.'}
- OGG = 'ogg'
- SPLIT_STRING_LIST_FOR_FOLLOW_UP_QUESTIONS = ['Example Questions:\n', 'Here are a few questions that may help:', 'Here are a few follow-up questions that may help:', '**Example Questions:**', 'As follow-up questions, users can ask:', 'As follow-up questions, you can ask:', 'As follow-up questions, here are some examples based on the context provided:']
- UNABLE_TO_TRANSCRIBE_THE_VOICE_INPUT_QUERY = 'Unfortunately unable to transcribe the above voice input query.'
- UNANSWERED_PHRASES = ['out of my context', 'out of context', 'not mentioned in the given context', ' rephrase ', ' reframe ', 'topic was not in my last update', "topic wasn't in my last update", 'I do not have information', "I don't have information", "I don't have real-time information", 'thought of stumping an AI']
common.utils
import logging, json, certifi, re, uuid, base64, regex, binascii from peewee import DoesNotExist from requests import Request, Session from requests.adapters import HTTPAdapter from urllib3.util import Retry
from common.constants import Constants from database.db_operations import create_record, get_record_by_field, update_record from database.database_config import db_conn from database.models import Conversation, Messages, User, FollowUpQuestion, Language, MultilingualText from django_core.config import Config from django_core import celery from language_service.translation import * from language_service.utils import get_language_by_code
logger = logging.getLogger(__name__)
- common.utils.get_or_create_latest_conversation(conversation_data)[source]
Fetch the latest conversation instance if available or create a new conversation. def get_or_create_latest_conversation(conversation_data: dict) -> Conversation:
- common.utils.get_user_chat_history(user_id)[source]
Fetch user chat history by querying the previous messages associated with the user. def get_user_chat_history(user_id, window=Config.CHAT_HISTORY_WINDOW):
- common.utils.send_request(url, headers={})[source]
Generic helper function to send requests to a specified URL with the relevant HTTP method, query params, request body, content negotiation and number of retries.
org defn: def send_request( url, headers={}, data=None, content_type=”form-data”, request_type=”GET”, total_retry=10, params=None
):