Started to work on interaction views. However, need a quick check in because of a python upgrade systemwide that breaks code.

This commit is contained in:
Josako
2024-06-21 09:52:06 +02:00
parent c5370c8026
commit cc9f6c95aa
19 changed files with 553 additions and 112 deletions

View File

@@ -9,6 +9,7 @@ class ChatSession(db.Model):
session_id = db.Column(db.String(36), nullable=True)
session_start = db.Column(db.DateTime, nullable=False)
session_end = db.Column(db.DateTime, nullable=True)
timezone = db.Column(db.String(30), nullable=True)
# Relations
interactions = db.relationship('Interaction', backref='chat_session', lazy=True)
@@ -25,6 +26,7 @@ class Interaction(db.Model):
answer = db.Column(db.Text, nullable=True)
algorithm_used = db.Column(db.String(20), nullable=True)
language = db.Column(db.String(2), nullable=False)
timezone = db.Column(db.String(30), nullable=True)
appreciation = db.Column(db.Integer, nullable=True)
# Timing information

View File

@@ -21,6 +21,10 @@ class CitedAnswer(BaseModel):
...,
description="The integer IDs of the SPECIFIC sources that were used to generate the answer"
)
insufficient_info: bool = Field(
False, # Default value is set to False
description="A boolean indicating wether given sources were sufficient or not to generate the answer"
)
def set_language_prompt_template(cls, language_prompt):
@@ -112,17 +116,20 @@ def select_model_variables(tenant):
summary_template = current_app.config.get('GPT4_SUMMARY_TEMPLATE')
rag_template = current_app.config.get('GPT4_RAG_TEMPLATE')
history_template = current_app.config.get('GPT4_HISTORY_TEMPLATE')
encyclopedia_template = current_app.config.get('GPT4_ENCYCLOPEDIA_TEMPLATE')
tool_calling_supported = True
case 'gpt-3-5-turbo':
summary_template = current_app.config.get('GPT3_5_SUMMARY_TEMPLATE')
rag_template = current_app.config.get('GPT3_5_RAG_TEMPLATE')
history_template = current_app.config.get('GPT3_5_HISTORY_TEMPLATE')
encyclopedia_template = current_app.config.get('GPT3_5_ENCYCLOPEDIA_TEMPLATE')
case _:
raise Exception(f'Error setting model variables for tenant {tenant.id} '
f'error: Invalid chat model')
model_variables['summary_template'] = summary_template
model_variables['rag_template'] = rag_template
model_variables['history_template'] = history_template
model_variables['encyclopedia_template'] = encyclopedia_template
if tool_calling_supported:
model_variables['cited_answer_cls'] = CitedAnswer
case _:
@@ -143,4 +150,4 @@ def create_language_template(template, language):
def replace_variable_in_template(template, variable, value):
return template.replace(variable, value)
return template.replace(variable, value)

View File

@@ -0,0 +1,37 @@
# common/utils/filters.py
import pytz
from datetime import datetime
def to_local_time(utc_dt, timezone_str):
"""
Converts a UTC datetime to a local datetime based on the provided timezone string.
"""
if not utc_dt:
return "N/A"
local_tz = pytz.timezone(timezone_str)
local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz)
return local_dt.strftime('%Y-%m-%d %H:%M:%S %Z%z')
def time_difference(start_dt, end_dt):
"""
Returns the time difference between two datetimes as a string.
If end_dt is None, returns "Ongoing".
"""
if not start_dt:
return "N/A"
if end_dt:
delta = end_dt - start_dt
# Customize the formatting as needed
return str(delta)
return "Ongoing"
def register_filters(app):
"""
Registers custom filters with the Flask app.
"""
app.jinja_env.filters['to_local_time'] = to_local_time
app.jinja_env.filters['time_difference'] = time_difference