added basic flow and prompting
This commit is contained in:
@@ -8,5 +8,7 @@ namespace finder2e_foundry_converter.Services
|
||||
{
|
||||
Task<List<string>> GetModelsAsync(string baseUrl);
|
||||
Task<string> GenerateResponseAsync(string baseUrl, string model, string text, List<string> imagePaths);
|
||||
// Ask a single prompt and return assistant's textual response (no streaming)
|
||||
Task<string> AskAsync(string baseUrl, string model, string prompt, List<string> imagePaths);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -72,6 +72,12 @@ namespace finder2e_foundry_converter.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> AskAsync(string baseUrl, string model, string prompt, List<string> imagePaths)
|
||||
{
|
||||
// Reuse GenerateResponseAsync semantics for single-shot prompts
|
||||
return await GenerateResponseAsync(baseUrl, model, prompt, imagePaths);
|
||||
}
|
||||
|
||||
private class OllamaModelsResponse
|
||||
{
|
||||
[JsonPropertyName("models")]
|
||||
|
||||
Reference in New Issue
Block a user