added basic flow and prompting
This commit is contained in:
@@ -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")]
|
||||
|
||||
Reference in New Issue
Block a user