-
Notifications
You must be signed in to change notification settings - Fork 12
Base64 to be deprecated while image upload #44
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
base: release-2.3.0
Are you sure you want to change the base?
Changes from all commits
db5c849
9605672
be2e2a0
75f2e83
842b9fc
c5b82bd
94c078b
5284587
4a8e21c
6395634
7b4d9cc
9a779e5
809973c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,18 @@ | |
| llm_retry_number = int(os.getenv('LLM_RETRY_NUMBER')) | ||
|
|
||
|
|
||
| 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 handle_llama_model( | ||
| messages, max_token, model_name=None, is_json_format=True, temperature=None, top_p=None, seed=None, n=None, | ||
| stream=False, url_to_use=None | ||
|
|
@@ -101,7 +113,10 @@ def handle_openai_model( | |
| else: | ||
| client = OpenAI(api_key=client_api_key) | ||
|
|
||
| if model_name: | ||
| custom_model = get_custom_model(company_bot) | ||
| if custom_model: | ||
| model_to_use = custom_model | ||
| elif model_name: | ||
|
Comment on lines
+116
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.pyRepository: 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,
})
PYRepository: ELEVATE-Project/mitra-service Length of output: 2080 Validate the resolved model against the selected provider.
🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's okay. Don't want to touch old code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐇︵︵ You are interacting with an AI system. |
||
| model_to_use = model_name | ||
| elif company_bot: | ||
| model_to_use = company_bot.llm_model | ||
|
|
@@ -121,7 +136,7 @@ def handle_openai_model( | |
| LLMModel.GPT5_2, | ||
| } | ||
| if max_token: | ||
| if company_bot.llm_model in token_limit_models: | ||
| if model_to_use in token_limit_models: | ||
| request_data["max_completion_tokens"] = max_token | ||
| else: | ||
| request_data["max_tokens"]= max_token | ||
|
|
@@ -135,7 +150,7 @@ def handle_openai_model( | |
| request_data["tools"]= tools | ||
| if tool_choice: | ||
| request_data["tool_choice"]= tool_choice | ||
| if top_p is not None and company_bot.llm_model not in token_limit_models: | ||
| if top_p is not None and model_to_use not in token_limit_models: | ||
| request_data['top_p'] = top_p | ||
| print("request_data: ", request_data) | ||
| response = client.chat.completions.create(**request_data) | ||
|
|
@@ -243,7 +258,10 @@ def handle_bedrock_model( | |
| config=boto_config | ||
| ) | ||
| print("aws_key used: ", aws_key if aws_key else AWS_KEY) | ||
| if model_name: | ||
| custom_model = get_custom_model(company_bot) | ||
| if custom_model: | ||
| model_id = custom_model | ||
| elif model_name: | ||
|
Comment on lines
+261
to
+264
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 -200Repository: 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 -250Repository: ELEVATE-Project/mitra-service Length of output: 32109 Do not fall back to Llama pricing for unmatched Bedrock models.
Add exact pricing keys for each supported model, or return 🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's okay. Don't want to touch old code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐇 You are interacting with an AI system. |
||
| model_id = model_name | ||
| else: | ||
| model_id = 'meta.llama3-1-8b-instruct-v1:0' | ||
|
|
@@ -621,7 +639,10 @@ def handle_openai_response_api( | |
|
|
||
| client = OpenAI(api_key=client_api_key) | ||
|
|
||
| if model_name: | ||
| custom_model = get_custom_model(company_bot) | ||
| if custom_model: | ||
| model_to_use = custom_model | ||
| elif model_name: | ||
| model_to_use = model_name | ||
| elif company_bot: | ||
| model_to_use = company_bot.llm_model | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -414,7 +414,6 @@ def get_html_from_template(story, profile, flow, auth=False, language=None): | |||||||
| return html_content | ||||||||
|
|
||||||||
| def update_story_pdf(access_token, session, flow, is_edit_story=False): | ||||||||
|
|
||||||||
| try: | ||||||||
| chatsession = ChatSession.objects.values("language").get(session=session) | ||||||||
|
|
||||||||
|
|
@@ -431,13 +430,15 @@ def update_story_pdf(access_token, session, flow, is_edit_story=False): | |||||||
|
|
||||||||
| if story and story.content and story.formatted_content: | ||||||||
| update_story_content(story) | ||||||||
|
|
||||||||
| profile = story.author | ||||||||
| print("profile: ", profile) | ||||||||
| print("story: ", story.title) | ||||||||
| print("story format: ", story.formatted_content) | ||||||||
|
Comment on lines
435
to
437
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Proposed fix- print("profile: ", profile)
- print("story: ", story.title)
- print("story format: ", story.formatted_content)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's okay. Don't want to touch old code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐇︵︵ You are interacting with an AI system. |
||||||||
| language = chatsession.get("language", StoryLanguageChoices.ENGLISH) | ||||||||
| flow_obj = Flow.objects.filter(flow_route=flow).first() | ||||||||
| has_pdf_template = flow_obj and PDFTemplates.objects.filter(flow=flow_obj).exists() | ||||||||
|
|
||||||||
| if has_pdf_template: | ||||||||
| html_content = get_html_from_template( | ||||||||
| story=story, profile=profile, flow=flow, | ||||||||
|
|
@@ -447,7 +448,7 @@ def update_story_pdf(access_token, session, flow, is_edit_story=False): | |||||||
| html_content = get_story_html(story=story, profile=profile, flow=flow) | ||||||||
|
|
||||||||
| pdf_generated = generate_pdf_with_gotenberg(html_content) | ||||||||
| # print("pdf_generated: ", pdf_generated) | ||||||||
|
|
||||||||
| pdf_file_name = story.title | ||||||||
| if not pdf_file_name or pdf_file_name == '': | ||||||||
| pdf_file_name = 'Improvement_story' | ||||||||
|
|
@@ -514,7 +515,6 @@ def update_story_pdf(access_token, session, flow, is_edit_story=False): | |||||||
| conversation = get_stored_conversation(company_chats=company_chats) | ||||||||
| chat_history = get_stored_chathistory(company_chats=company_chats) | ||||||||
|
|
||||||||
|
|
||||||||
| tasks_payload = [] | ||||||||
|
|
||||||||
| task_id_from_session = None | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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_paramsbefore parsing it.json.loadsat Line 37 can raisejson.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 theirtryblocks. A malformed optional setting can therefore abort the request instead of using the normal error path.Catch parse errors, require an object, and return
Noneor 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
🤖 Prompt for AI Agents
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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_paramscase 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.