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:
@@ -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)
|
||||
|
||||
@@ -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/'
|
||||
|
||||
Reference in New Issue
Block a user