added basic flow and prompting

This commit is contained in:
grimsace
2026-07-01 15:33:12 -05:00
parent 6c306a4a0f
commit c3f6cc2375
5 changed files with 595 additions and 301 deletions
+36
View File
@@ -93,6 +93,42 @@ namespace finder2e_foundry_converter.Services
}
}
public async Task<string> AskAsync(string baseUrl, string model, string prompt, List<string> imagePaths)
{
// LM Studio expects messages content; reuse the same structure but with a simple text message
try
{
var requestBody = new
{
model = model,
messages = new[]
{
new { role = "user", content = new[] { new { type = "text", text = prompt } } }
}
};
var response = await _httpClient.PostAsJsonAsync($"{baseUrl.TrimEnd('/')}/v1/chat/completions", requestBody);
var body = await response.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(body);
if (doc.RootElement.TryGetProperty("error", out var error))
{
return $"Error: {error.GetProperty("message").GetString()}";
}
if (doc.RootElement.TryGetProperty("choices", out var choices) && choices.GetArrayLength() > 0)
{
return choices[0].GetProperty("message").GetProperty("content").GetString() ?? "No content returned";
}
return "No response choices returned.";
}
catch (Exception ex)
{
return $"Error: {ex.Message}";
}
}
private class ModelsResponse
{
[JsonPropertyName("data")]