fix: captain json parsing (#13708)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
Aakash Bakhle
2026-03-05 15:43:21 +05:30
committed by GitHub
parent 3ea5f258a4
commit fd69b4c8f2
8 changed files with 60 additions and 6 deletions

View File

@@ -20,6 +20,14 @@ class Llm::BaseAiService
private
# Strips markdown code fences (```json ... ``` or ``` ... ```) that some
# LLM providers/gateways wrap around JSON responses despite response_format hints.
def sanitize_json_response(response)
return response if response.nil?
response.strip.sub(/\A```(?:\w*)\s*\n?/, '').sub(/\n?\s*```\s*\z/, '').strip
end
def setup_model
config_value = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_MODEL')&.value
@model = (config_value.presence || DEFAULT_MODEL)

View File

@@ -24,6 +24,14 @@ class Llm::LegacyBaseOpenAiService
private
# Strips markdown code fences (```json ... ``` or ``` ... ```) that some
# LLM providers/gateways wrap around JSON responses despite response_format hints.
def sanitize_json_response(response)
return response if response.nil?
response.strip.sub(/\A```(?:\w*)\s*\n?/, '').sub(/\n?\s*```\s*\z/, '').strip
end
def uri_base
endpoint = InstallationConfig.find_by(name: 'CAPTAIN_OPEN_AI_ENDPOINT')&.value
endpoint.presence || 'https://api.openai.com/'