fix: make the integration work against a Claude proxy
- Treat an empty tool argument string as no parameters instead of raising JSONDecodeError; the proxy sends "" for tools like the timer status (upstream issue #3). - Do not replay earlier web searches in the history. The chat log keeps only their status, and a search without results makes the model disown the answers it based on it and search again (upstream issue #4). - Look up the home location for web search with the subentry's model instead of gpt-4o-mini, and save the options without city/region if the lookup fails (upstream issue #5). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8737e5d4ec
commit
235c536cab
6 files changed
+224
-70
No files matched your search
@@ -702,31 +702,39 @@ class OpenAISubentryFlowHandler(ConfigSubentryFlow):
|
||||
): str,
|
||||
}
|
||||
)
|
||||
response = await client.responses.create(
|
||||
model=RECOMMENDED_CHAT_MODEL,
|
||||
input=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Where are the following coordinates located: "
|
||||
f"({zone_home.attributes[EntityStateAttribute.LATITUDE]},"
|
||||
f" {zone_home.attributes[EntityStateAttribute.LONGITUDE]})?",
|
||||
}
|
||||
],
|
||||
text={
|
||||
"format": {
|
||||
"type": "json_schema",
|
||||
"name": "approximate_location",
|
||||
"description": "Approximate location data of the user "
|
||||
"for refined web search results",
|
||||
"schema": to_openapi(location_schema),
|
||||
"strict": False,
|
||||
}
|
||||
},
|
||||
store=self.options.get(
|
||||
CONF_STORE_RESPONSES, RECOMMENDED_STORE_RESPONSES
|
||||
),
|
||||
)
|
||||
location_data = location_schema(json.loads(response.output_text) or {})
|
||||
# Ask the subentry's own model: the endpoint may not serve
|
||||
# RECOMMENDED_CHAT_MODEL (an OpenAI name). A failed lookup only
|
||||
# costs the city/region hint, so it must not block saving.
|
||||
try:
|
||||
response = await client.responses.create(
|
||||
model=self.options.get(CONF_CHAT_MODEL, RECOMMENDED_CHAT_MODEL),
|
||||
input=[
|
||||
{
|
||||
"role": "system",
|
||||
"content": "Where are the following coordinates located: "
|
||||
f"({zone_home.attributes[EntityStateAttribute.LATITUDE]},"
|
||||
f" {zone_home.attributes[EntityStateAttribute.LONGITUDE]})?",
|
||||
}
|
||||
],
|
||||
text={
|
||||
"format": {
|
||||
"type": "json_schema",
|
||||
"name": "approximate_location",
|
||||
"description": "Approximate location data of the user "
|
||||
"for refined web search results",
|
||||
"schema": to_openapi(location_schema),
|
||||
"strict": False,
|
||||
}
|
||||
},
|
||||
store=self.options.get(
|
||||
CONF_STORE_RESPONSES, RECOMMENDED_STORE_RESPONSES
|
||||
),
|
||||
)
|
||||
location_data = location_schema(json.loads(response.output_text) or {})
|
||||
except (openai.OpenAIError, ValueError, vol.Invalid) as err:
|
||||
_LOGGER.warning(
|
||||
"Could not look up the home location for web search: %s", err
|
||||
)
|
||||
|
||||
if self.hass.config.country:
|
||||
location_data[CONF_WEB_SEARCH_COUNTRY] = self.hass.config.country
|
||||
|
||||
Reference in new issue
Block a user