fix: CleanOrphanedWebSearchBlocks bidirektional – entfernt auch verwaiste web_search_tool_result ohne server_tool_use
Vorher wurden nur orphaned server_tool_use entfernt (die keinen web_search_tool_result hatten). Jetzt auch umgekehrt: web_search_tool_result Blöcke ohne zugehörigen server_tool_use werden entfernt. Mögliche Ursache für API 400 'web_search_tool_result without corresponding server_tool_use': Parse-Fehler beim Laden des server_tool_use aus der DB oder Reihenfolgeprobleme führten dazu, dass nur der Result-Block in der History landete.
This commit is contained in:
1 parent
3153cb6c6b
commit
8dd962ac49
1 file changed
+23
-9
+23
-9
@@ -601,8 +601,9 @@ Für welche Plattform soll die App entwickelt werden? Web, Mobile oder Desktop?
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Entfernt server_tool_use-Blöcke vom Typ "web_search" aus assistant-Messages,
|
/// Entfernt verwaiste web_search-Blöcke aus assistant-Messages:
|
||||||
/// wenn kein zugehöriger web_search_tool_result-Block in derselben Message existiert.
|
/// - server_tool_use ohne zugehörigen web_search_tool_result (z.B. alte DB-Einträge)
|
||||||
|
/// - web_search_tool_result ohne zugehörigen server_tool_use (z.B. Parse-Fehler)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void CleanOrphanedWebSearchBlocks(List<object> history)
|
private static void CleanOrphanedWebSearchBlocks(List<object> history)
|
||||||
{
|
{
|
||||||
@@ -639,11 +640,14 @@ Für welche Plattform soll die App entwickelt werden? Web, Mobile oder Desktop?
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Orphaned = server_tool_use IDs ohne zugehörige web_search_tool_result
|
// Orphaned server_tool_use = IDs ohne zugehörige web_search_tool_result
|
||||||
var orphanedIds = webSearchToolUseIds.Except(webSearchToolResultIds).ToHashSet();
|
var orphanedUseIds = webSearchToolUseIds.Except(webSearchToolResultIds).ToHashSet();
|
||||||
if (orphanedIds.Count == 0) continue;
|
// Orphaned web_search_tool_result = tool_use_ids ohne zugehörige server_tool_use
|
||||||
|
var orphanedResultIds = webSearchToolResultIds.Except(webSearchToolUseIds).ToHashSet();
|
||||||
|
|
||||||
// Entferne orphaned server_tool_use Blöcke
|
if (orphanedUseIds.Count == 0 && orphanedResultIds.Count == 0) continue;
|
||||||
|
|
||||||
|
// Entferne orphaned server_tool_use und web_search_tool_result Blöcke
|
||||||
contentList.RemoveAll(block =>
|
contentList.RemoveAll(block =>
|
||||||
{
|
{
|
||||||
var json = JsonSerializer.Serialize(block);
|
var json = JsonSerializer.Serialize(block);
|
||||||
@@ -652,10 +656,20 @@ Für welche Plattform soll die App entwickelt werden? Web, Mobile oder Desktop?
|
|||||||
catch { return false; }
|
catch { return false; }
|
||||||
|
|
||||||
var type = el.TryGetProperty("type", out var t) ? t.GetString() : "";
|
var type = el.TryGetProperty("type", out var t) ? t.GetString() : "";
|
||||||
if (type != "server_tool_use") return false;
|
|
||||||
|
|
||||||
var id = el.TryGetProperty("id", out var idProp) ? idProp.GetString() : "";
|
if (type == "server_tool_use")
|
||||||
return orphanedIds.Contains(id);
|
{
|
||||||
|
var id = el.TryGetProperty("id", out var idProp) ? idProp.GetString() : "";
|
||||||
|
return orphanedUseIds.Contains(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == "web_search_tool_result")
|
||||||
|
{
|
||||||
|
var toolUseId = el.TryGetProperty("tool_use_id", out var tid) ? tid.GetString() : "";
|
||||||
|
return orphanedResultIds.Contains(toolUseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user