This commit is contained in:
mmrbnjd
2025-08-29 19:01:13 +03:30
parent 564429be01
commit 49304f93a2
6 changed files with 127 additions and 8 deletions

View File

@@ -38,6 +38,50 @@ namespace AIAss.Services;
reponse="خطا در ارتباط سرور ai";
}
return new aiaReply
{
Message = $" {reponse}"
};
}
public async override Task<aiaReply> imageAnalize(aiaRequest request, ServerCallContext context)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", request.Apitoken);
var content = new
{
model = request.Model,
messages = new object[]
{
new {
role = "user",
content = new object[]
{
new { type = "text", text =request.Prompts},
new {
type = "image_url",
image_url = new {
url = $"data:image/jpeg;base64,{request.Question}"
}
}
}
}
}
};
var response = await client.PostAsync(request.Url,
new StringContent(JsonSerializer.Serialize(content), Encoding.UTF8, "application/json"));
string reponse = "";
if (response.IsSuccessStatusCode)
{
var json = await response.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(json);
reponse = doc.RootElement.GetProperty("choices")[0].GetProperty("message").GetProperty("content").GetString();
}
else
{
reponse = "خطا در ارتباط سرور ai";
}
return new aiaReply
{
Message = $" {reponse}"