-
Notifications
You must be signed in to change notification settings - Fork 4
Release 1.0.0 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kiranharidas187
merged 12 commits into
ELEVATE-Project:release-1.0.0
from
darshilbabel:release-1.0.0
Jun 10, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb89d3c
Feedback update
KUNALTEMPEST 6df84a1
Added profile bot changes
KUNALTEMPEST 51779ef
profile admin fix
KUNALTEMPEST cd588e1
profile save name
KUNALTEMPEST d772ce9
Profile API + TNC patch api
KUNALTEMPEST ab6625a
saathi backend work
KUNALTEMPEST 0b6ad55
PDF translation issue update
KUNALTEMPEST ff0a699
PDF translation issue update
KUNALTEMPEST 7ed7633
Onboarding issue, new logic, now once interacted with bot sets bool t…
KUNALTEMPEST 7019556
fixed issue where elevate profile api replaced the profile booleans
KUNALTEMPEST 1d81d6f
saving sources and download in chats to preserver for chat history
KUNALTEMPEST e307ab5
Updated at ordering feature added
KUNALTEMPEST File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| from celery import shared_task | ||
| from chatbot.models import ChatSession, CompanyChat, Voice, VoiceType | ||
| from chatbot.models.company_models import Flow | ||
| from chatbot.llm_models.llm_gateway import call_llm_gateway, build_gateway_params | ||
| from chatbot.utils.chat_utils import get_guided_chat | ||
| from chatbot.utils.audio_provider_utils import text_translate_provider | ||
| import json_repair | ||
| import logging | ||
|
|
||
| logger = logging.getLogger('django') | ||
|
|
||
|
|
||
| def _track_usage(session_id, response): | ||
| try: | ||
| usage = response.get('usage', {}) or {} | ||
| cost = response.get('cost', {}) or {} | ||
| usage_cost = { | ||
| 'input_tokens': usage.get('input_tokens', 0) or 0, | ||
| 'output_tokens': usage.get('output_tokens', 0) or 0, | ||
| 'total_tokens': usage.get('total_tokens', 0) or 0, | ||
| 'cost_usd': cost.get('computed_usd', 0) or 0, | ||
| } | ||
| if not any(usage_cost.values()): | ||
| return | ||
| session = ChatSession.objects.get(session=session_id) | ||
| other_params = session.other_params or {} | ||
| totals = other_params.get('usage', {}) | ||
| logger.info("[usage] title call session %s before update: %s | this call: %s", session_id, totals, usage_cost) | ||
| totals['total_input_tokens'] = totals.get('total_input_tokens', 0) + usage_cost['input_tokens'] | ||
| totals['total_output_tokens'] = totals.get('total_output_tokens', 0) + usage_cost['output_tokens'] | ||
| totals['total_tokens'] = totals.get('total_tokens', 0) + usage_cost['total_tokens'] | ||
| totals['total_cost_usd'] = round(totals.get('total_cost_usd', 0) + usage_cost['cost_usd'], 6) | ||
| other_params['usage'] = totals | ||
| session.other_params = other_params | ||
| session.save(update_fields=['other_params']) | ||
| logger.info("[usage] title call session %s after update: %s", session_id, totals) | ||
| except Exception as e: | ||
| logger.error("[usage] failed to track title usage for session %s: %s", session_id, e) | ||
|
|
||
|
|
||
| @shared_task | ||
| def generate_session_title(session_id, language='en'): | ||
| session = ChatSession.objects.filter(session=session_id).first() | ||
| if not session or session.title: | ||
| return | ||
|
|
||
| flow = Flow.objects.filter(bot=session.company_bot).first() | ||
| if not flow or not flow.title_bot: | ||
| logger.info("No title bot configured for session %s", session_id) | ||
| return | ||
|
|
||
| company_bot = flow.title_bot | ||
| logger.info("Generating title for session %s using bot %s", session_id, company_bot.id) | ||
|
|
||
| company_chats = ( | ||
| CompanyChat.objects | ||
| .select_related('sender', 'receiver') | ||
| .filter(session=session_id) | ||
| .order_by('created_at') | ||
| .values("receiver", "receiver__id", "translated_message", "message", "status", "created_at") | ||
| ) | ||
| messages = get_guided_chat(company_bot=company_bot, company_chats=company_chats) | ||
|
|
||
| tools = company_bot.tool_context | ||
| if tools and isinstance(tools, str): | ||
| tools = json_repair.repair_json(tools, return_objects=True) | ||
|
|
||
| tool_choice = None | ||
| if isinstance(tools, dict): | ||
| tool_choice = tools.get('tool_choice', 'auto') | ||
| tools = tools.get('tools') or tools.get('tool') | ||
| elif isinstance(tools, list): | ||
| tool_choice = 'auto' | ||
|
|
||
| system_msg = {'role': 'system', 'content': company_bot.context} | ||
| response = call_llm_gateway( | ||
| messages=[system_msg] + list(messages), | ||
| provider=company_bot.provider, | ||
| model=company_bot.llm_model, | ||
| params=build_gateway_params(company_bot), | ||
| tools=tools or None, | ||
| tool_choice=tool_choice, | ||
| ) | ||
|
|
||
| if not response: | ||
| logger.error("LLM gateway returned no response for title generation, session %s", session_id) | ||
| return | ||
|
|
||
| _track_usage(session_id, response) | ||
|
|
||
| try: | ||
| import json as _json | ||
| choice = response.get('choices', [{}])[0] | ||
| message = choice.get('message', {}) | ||
| tool_calls = message.get('tool_calls') or [] | ||
| title_tc = next( | ||
| (tc for tc in tool_calls if tc.get('function', {}).get('name') == 'generate_title'), | ||
| None, | ||
| ) | ||
| if not title_tc: | ||
| logger.error("generate_title tool call missing in response for session %s", session_id) | ||
| return | ||
| raw_args = title_tc.get('function', {}).get('arguments', '{}') | ||
| arguments = _json.loads(raw_args) if isinstance(raw_args, str) else raw_args | ||
| output_title = arguments.get('title') | ||
| except Exception as e: | ||
| logger.error("Error extracting title for session %s: %s", session_id, e) | ||
| return | ||
|
|
||
| if not output_title: | ||
| logger.error("No title value in generate_title tool call for session %s", session_id) | ||
| return | ||
|
|
||
| if language != 'en': | ||
| voice_provider = Voice.objects.filter( | ||
| company_bot=company_bot, type=VoiceType.TextToText, language=language | ||
| ).first() | ||
| translated = text_translate_provider( | ||
| voice_provider=voice_provider, message_body=output_title, target_language=language, | ||
| source_language='en' | ||
| ) | ||
| if translated.get('status') == 200: | ||
| output_title = translated.get('content') | ||
|
|
||
| session.save_title(output_title) | ||
| logger.info("Title saved for session %s: %s", session_id, output_title) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
chatbot/migrations/0085_flow_title_bot_historicalflow_title_bot_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Generated by Django 5.2 on 2026-06-03 17:10 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('chatbot', '0084_companybot_enable_web_search_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='flow', | ||
| name='title_bot', | ||
| field=models.ForeignKey(blank=True, help_text='Optional bot for session title generation.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='title_flows', to='chatbot.companybot'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='historicalflow', | ||
| name='title_bot', | ||
| field=models.ForeignKey(blank=True, db_constraint=False, help_text='Optional bot for session title generation.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='chatbot.companybot'), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='mediaimage', | ||
| name='media_type', | ||
| field=models.CharField(blank=True, choices=[('application/pdf', 'PDF'), ('text/plain', 'TXT'), ('text/csv', 'CSV'), ('image/jpeg', 'JPEG'), ('image/png', 'PNG'), ('image/svg+xml', 'SVG'), ('image/webp', 'WEBP'), ('image/heif', 'HEIF'), ('image/heic', 'HEIC'), ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'XLSX'), ('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'DOCX')], max_length=100, null=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='storymedia', | ||
| name='media_type', | ||
| field=models.CharField(blank=True, choices=[('application/pdf', 'PDF'), ('text/plain', 'TXT'), ('text/csv', 'CSV'), ('image/jpeg', 'JPEG'), ('image/png', 'PNG'), ('image/svg+xml', 'SVG'), ('image/webp', 'WEBP'), ('image/heif', 'HEIF'), ('image/heic', 'HEIC'), ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'XLSX'), ('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'DOCX')], max_length=100, null=True), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.