Skip to content

Base64 to be deprecated while image upload - #44

Open
VishnuKrishnathu wants to merge 13 commits into
ELEVATE-Project:release-2.3.0from
darshilbabel:fix/base64_dep
Open

Base64 to be deprecated while image upload#44
VishnuKrishnathu wants to merge 13 commits into
ELEVATE-Project:release-2.3.0from
darshilbabel:fix/base64_dep

Conversation

@VishnuKrishnathu

@VishnuKrishnathu VishnuKrishnathu commented Aug 3, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features

    • Added support for selecting custom AI models configured for a chatbot.
    • Added support for GPT-5.2, GPT-5.2 Pro, GPT-5 Mini, Claude Haiku 4.5, and Claude Sonnet 4.5.
  • Bug Fixes

    • Improved model-specific token and sampling-limit handling.
    • Improved story media saving and file processing, including HEIC/HEIF conversion.
  • Chores

    • Removed obsolete debug output and unused code without changing user-facing behavior.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

LLM model routing

Layer / File(s) Summary
Model choices
chatbot/models/enums.py
Adds Claude Haiku 4.5 and Claude Sonnet 4.5 Bedrock model choices.
Custom model resolution
chatbot/llm_models/llm_script.py
Adds get_custom_model and applies the resolved model to OpenAI chat completions, Bedrock Converse, OpenAI Responses, token limits, and top_p checks.

Story media cleanup

Layer / File(s) Summary
Story media save processing
chatbot/models/story_models.py
Removes file URL downloads and base64 generation. Processes uploaded files directly and saves when no file exists.
Story flow and module cleanup
chatbot/views/story_views.py, chatbot/utils/shikshalokam_story_utils.py, shikshalokam_mohini/settings.py
Removes debug output, unused imports, and formatting-only artifacts while retaining story creation and PDF update behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CompanyBot
  participant LLMHandlers
  participant ModelProvider
  CompanyBot->>LLMHandlers: provide custom_model
  LLMHandlers->>LLMHandlers: resolve model_to_use or model_id
  LLMHandlers->>ModelProvider: send request with resolved model
Loading

Possibly related PRs

Suggested reviewers: irfan-ansari-au28

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the removal of base64 processing during image upload, which is a real change in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@VishnuKrishnathu VishnuKrishnathu changed the title Fix/base64 dep Base64 to be deprecated while image upload Aug 3, 2026
@VishnuKrishnathu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Action performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@chatbot/llm_models/llm_script.py`:
- Around line 29-38: Update get_custom_model to safely handle malformed or
non-object other_params: catch JSON decoding failures, validate that parsed
values are mappings before calling .get(), and return None (or the established
controlled configuration error) for invalid optional settings so callers remain
on their normal error path.
- Around line 261-264: Update get_pricing_from_company_bot and its pricing data
so supported Bedrock Claude model IDs, including the newly listed Haiku and
Sonnet IDs, have exact pricing entries; when pricing_data.get(model_id) misses,
return None instead of falling back to the llama3-3-70b entry. Preserve existing
exact-match pricing behavior for all other models.
- Around line 116-119: Validate the custom model selected in the
model-resolution flow before assigning it to provider-specific handlers. In the
logic around get_custom_model, handle_openai_model, handle_openai_response_api,
and handle_bedrock_model, check other_params['custom_model'] and
company_bot.llm_model so only a model compatible with the selected provider is
passed as model or modelId; otherwise continue using the provider-appropriate
configured model.

In `@chatbot/utils/shikshalokam_story_utils.py`:
- Around line 435-437: Remove the three debug print calls for profile, story
title, and story.formatted_content from the PDF update flow. Do not emit user or
story data to stdout; retain existing behavior and use only redacted structured
logging if diagnostics are required elsewhere.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 536aaf28-ecf8-4c91-84e2-d325a7cddec4

📥 Commits

Reviewing files that changed from the base of the PR and between aa10d4b and 809973c.

📒 Files selected for processing (6)
  • chatbot/llm_models/llm_script.py
  • chatbot/models/enums.py
  • chatbot/models/story_models.py
  • chatbot/utils/shikshalokam_story_utils.py
  • chatbot/views/story_views.py
  • shikshalokam_mohini/settings.py

Comment on lines +29 to +38
def get_custom_model(company_bot):
"""Return company_bot.other_params['custom_model'] if set, else None."""
if not company_bot:
return None
other_params = company_bot.get('other_params') if isinstance(company_bot, dict) else getattr(
company_bot, 'other_params', None
)
if isinstance(other_params, str):
other_params = json.loads(other_params)
return other_params.get('custom_model') if other_params else None

@coderabbitai coderabbitai Bot Aug 3, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle malformed other_params before parsing it.

json.loads at Line 37 can raise json.JSONDecodeError. A valid JSON list, string, or number can then reach Line 38 without a .get() method. The Bedrock and Responses API handlers call this helper before their try blocks. A malformed optional setting can therefore abort the request instead of using the normal error path.

Catch parse errors, require an object, and return None or a controlled configuration error.

Proposed fix
 def get_custom_model(company_bot):
     """Return company_bot.other_params['custom_model'] if set, else None."""
     if not company_bot:
         return None
     other_params = company_bot.get('other_params') if isinstance(company_bot, dict) else getattr(
         company_bot, 'other_params', None
     )
     if isinstance(other_params, str):
-        other_params = json.loads(other_params)
-    return other_params.get('custom_model') if other_params else None
+        try:
+            other_params = json.loads(other_params)
+        except json.JSONDecodeError:
+            return None
+    if not isinstance(other_params, dict):
+        return None
+    custom_model = other_params.get('custom_model')
+    if not isinstance(custom_model, str):
+        return None
+    return custom_model.strip() or None
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def get_custom_model(company_bot):
"""Return company_bot.other_params['custom_model'] if set, else None."""
if not company_bot:
return None
other_params = company_bot.get('other_params') if isinstance(company_bot, dict) else getattr(
company_bot, 'other_params', None
)
if isinstance(other_params, str):
other_params = json.loads(other_params)
return other_params.get('custom_model') if other_params else None
def get_custom_model(company_bot):
"""Return company_bot.other_params['custom_model'] if set, else None."""
if not company_bot:
return None
other_params = company_bot.get('other_params') if isinstance(company_bot, dict) else getattr(
company_bot, 'other_params', None
)
if isinstance(other_params, str):
try:
other_params = json.loads(other_params)
except json.JSONDecodeError:
return None
if not isinstance(other_params, dict):
return None
custom_model = other_params.get('custom_model')
if not isinstance(custom_model, str):
return None
return custom_model.strip() or None
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@chatbot/llm_models/llm_script.py` around lines 29 - 38, Update
get_custom_model to safely handle malformed or non-object other_params: catch
JSON decoding failures, validate that parsed values are mappings before calling
.get(), and return None (or the established controlled configuration error) for
invalid optional settings so callers remain on their normal error path.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay. Don't want to touch old code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VishnuKrishnathu, acknowledged. I will leave this change out of PR #44.

The malformed other_params case remains a follow-up risk in the existing code. If you later want to address it, I can help create a separate issue.

🐇︵‍💫

You are interacting with an AI system.

Comment on lines +116 to +119
custom_model = get_custom_model(company_bot)
if custom_model:
model_to_use = custom_model
elif model_name:

@coderabbitai coderabbitai Bot Aug 3, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 5 \
  'custom_model|LLMProvider|company_bot\.llm_model|handle_openai_model|handle_bedrock_model|handle_openai_response_api' \
  --glob '*.py' .

Repository: ELEVATE-Project/mitra-service

Length of output: 50388


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== llm_script outline =="
ast-grep outline chatbot/llm_models/llm_script.py --view expanded | sed -n '1,220p'

echo
echo "== llm_script relevant lines =="
sed -n '1,180p' chatbot/llm_models/llm_script.py | cat -n
sed -n '240,280p' chatbot/llm_models/llm_script.py | cat -n
sed -n '620,660p' chatbot/llm_models/llm_script.py | cat -n

echo
echo "== focused provider/model usages in llm_script.py =="
rg -n -C 3 'def get_custom_model|get_custom_model|LLMProvider|model_to_use|model_name|provider|model_id|modelId|invoke_model|chat completions|OpenAI' chatbot/llm_models/llm_script.py

Repository: ELEVATE-Project/mitra-service

Length of output: 24350


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== LLMModel enum and references =="
rg -n "class LLMModel|LLMModel\." chatbot/models chatbot --glob '*.py' | sed -n '1,240p'

echo
echo "== get_custom_model read-only semantic probe =="
python3 - <<'PY'
class CompanyBotLike:
    def __init__(self, other_params=None):
        self.other_params = other_params

def get_custom_model(company_bot):
    other_params = company_bot.get('other_params') if isinstance(company_bot, dict) else getattr(
        company_bot, 'other_params', None
    )
    if isinstance(other_params, str):
        import json
        other_params = json.loads(other_params)
    return other_params.get('custom_model') if other_params else None

samples = [
    {'other_params': {'custom_model': 'anthropic.claude-sonnet-4-20250514-v1:0'}},
    {'other_params': '{"custom_model":"anthropic.claude-sonnet-4-20250514-v1:0"}'},
    type('Obj', (), {'other_params': {'custom_model': 'gpt-4.1-mini'}}),
]
for company_bot in samples:
    model_name = 'gsm8k-template'
    company_bot_llm_model = 'llama3-1-8b'
    custom_model = get_custom_model(company_bot)
    open_ai_model_to_use = custom_model or model_name or company_bot_llm_model
    bedrock_model_id = custom_model or model_name or None
    print({
        'input_type': type(company_bot).__name__,
        'provider_agnostic_model_value': custom_model,
        'fallback_to_caller_model_name': model_name,
        'open_ai_openai_model': open_ai_model_to_use,
        'bedrock_model_id': bedrock_model_id,
    })
PY

Repository: ELEVATE-Project/mitra-service

Length of output: 2080


Validate the resolved model against the selected provider.

get_custom_model can return a Bedrock model ID, but handle_openai_model and handle_openai_response_api pass it directly as model to OpenAI. handle_bedrock_model has the same provider-neutral override behavior. Check other_params['custom_model'] and company_bot.llm_model before these handlers assign model/modelId.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@chatbot/llm_models/llm_script.py` around lines 116 - 119, Validate the custom
model selected in the model-resolution flow before assigning it to
provider-specific handlers. In the logic around get_custom_model,
handle_openai_model, handle_openai_response_api, and handle_bedrock_model, check
other_params['custom_model'] and company_bot.llm_model so only a model
compatible with the selected provider is passed as model or modelId; otherwise
continue using the provider-appropriate configured model.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay. Don't want to touch old code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VishnuKrishnathu, acknowledged. I will leave this provider-validation change out of PR #44.

🐇︵︵

You are interacting with an AI system.

Comment on lines +261 to +264
custom_model = get_custom_model(company_bot)
if custom_model:
model_id = custom_model
elif model_name:

@coderabbitai coderabbitai Bot Aug 3, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n -C 5 \
  'model_pricing|llama3-3-70b|claude-haiku-4-5-20251001-v1:0|claude-sonnet-4-5-20250929-v1:0' \
  --glob '*.py' \
  --glob '*.json' \
  --glob '*.yaml' \
  --glob '*.yml' .

Repository: ELEVATE-Project/mitra-service

Length of output: 34328


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Relevant llm_script sections:"
sed -n '250,350p' chatbot/llm_models/llm_script.py
echo "---"
rg -n "get_pricing_from_company_bot|handle_bedrock_model|model_pricing|LLAMA_3_3_70B_INSTRUCT|CLAUDE" chatbot/observability chatbot --glob '*.py' | head -200

Repository: ELEVATE-Project/mitra-service

Length of output: 26416


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Pricing exact-miss fallback paths:"
sed -n '179,222p' chatbot/llm_models/llm_script.py
echo "--- guest script duplicate"
sed -n '332,370p' chatbot/scripts/guest_discussion/onetime_script.py
echo "--- get_custom_model references"
rg -n "def get_custom_model|get_custom_model\\(" chatbot --glob '*.py'
echo "--- model_pricing keys in tracked data files"
rg -n -C 3 "model_pricing|llama3-3-70b|us\.anthropic\.claude-haiku-4-5|us\.anthropic\.claude-sonnet-4-5|claude-haiku-4-5|claude-sonnet-4-5" \
  --glob '*.py' --glob '*.json' --glob '*.yaml' --glob '*.yml' --glob '*.md' --glob '*.txt' . | head -250

Repository: ELEVATE-Project/mitra-service

Length of output: 32109


Do not fall back to Llama pricing for unmatched Bedrock models.

get_pricing_from_company_bot uses pricing_data.get(model_id) and then looks up pricing_data.get('llama3-3-70b'). New Claude IDs such as us.anthropic.claude-haiku-4-5-20251001-v1:0 and us.anthropic.claude-sonnet-4-5-20250929-v1:0 can therefore log incorrect costs if exact pricing entries are missing.

Add exact pricing keys for each supported model, or return None on exact miss.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@chatbot/llm_models/llm_script.py` around lines 261 - 264, Update
get_pricing_from_company_bot and its pricing data so supported Bedrock Claude
model IDs, including the newly listed Haiku and Sonnet IDs, have exact pricing
entries; when pricing_data.get(model_id) misses, return None instead of falling
back to the llama3-3-70b entry. Preserve existing exact-match pricing behavior
for all other models.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay. Don't want to touch old code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VishnuKrishnathu, acknowledged. I will keep this existing pricing fallback behavior unchanged in this PR.

🐇

You are interacting with an AI system.

Comment on lines 435 to 437
print("profile: ", profile)
print("story: ", story.title)
print("story format: ", story.formatted_content)

@coderabbitai coderabbitai Bot Aug 3, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Remove user data from PDF-flow debug output.

These print calls write profile data and user-generated story content to stdout during every PDF update. This conflicts with the production log cleanup objective and can expose sensitive data. Remove the calls. Use redacted structured logging only when diagnostics are required.

Proposed fix
-        print("profile: ", profile)
-        print("story: ", story.title)
-        print("story format: ", story.formatted_content)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print("profile: ", profile)
print("story: ", story.title)
print("story format: ", story.formatted_content)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@chatbot/utils/shikshalokam_story_utils.py` around lines 435 - 437, Remove the
three debug print calls for profile, story title, and story.formatted_content
from the PDF update flow. Do not emit user or story data to stdout; retain
existing behavior and use only redacted structured logging if diagnostics are
required elsewhere.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay. Don't want to touch old code

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VishnuKrishnathu, acknowledged. I will leave the existing PDF-flow debug output unchanged in this PR.

🐇︵︵

You are interacting with an AI system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants