Spaces:
Sleeping
Sleeping
Commit ·
bfcec43
1
Parent(s): 248dd04
fix(AIService): robust model name validation to fallback to gemini-2.5-flash if configured model looks like API key
Browse files
FlowAPI.Application/Services/AIService.cs
CHANGED
|
@@ -122,6 +122,15 @@ namespace FlowAPI.Application.Services
|
|
| 122 |
}
|
| 123 |
|
| 124 |
var model = _config["Gemini:Model"] ?? "gemini-2.5-flash";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
if (model.StartsWith("models/"))
|
| 126 |
{
|
| 127 |
model = model.Substring("models/".Length);
|
|
@@ -176,7 +185,7 @@ namespace FlowAPI.Application.Services
|
|
| 176 |
|
| 177 |
if (!response.IsSuccessStatusCode)
|
| 178 |
{
|
| 179 |
-
throw new Exception($"Gemini API error (Status {response.StatusCode})
|
| 180 |
}
|
| 181 |
|
| 182 |
using var doc = JsonDocument.Parse(responseString);
|
|
|
|
| 122 |
}
|
| 123 |
|
| 124 |
var model = _config["Gemini:Model"] ?? "gemini-2.5-flash";
|
| 125 |
+
if (string.IsNullOrWhiteSpace(model) ||
|
| 126 |
+
model.StartsWith("AIzaSy", StringComparison.OrdinalIgnoreCase) ||
|
| 127 |
+
model.StartsWith("AQ.Ab", StringComparison.OrdinalIgnoreCase) ||
|
| 128 |
+
model.Length > 30 ||
|
| 129 |
+
!model.Contains("gemini", StringComparison.OrdinalIgnoreCase))
|
| 130 |
+
{
|
| 131 |
+
model = "gemini-2.5-flash";
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
if (model.StartsWith("models/"))
|
| 135 |
{
|
| 136 |
model = model.Substring("models/".Length);
|
|
|
|
| 185 |
|
| 186 |
if (!response.IsSuccessStatusCode)
|
| 187 |
{
|
| 188 |
+
throw new Exception($"Gemini API error (Status {response.StatusCode}): {responseString}");
|
| 189 |
}
|
| 190 |
|
| 191 |
using var doc = JsonDocument.Parse(responseString);
|