-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (44 loc) · 1.79 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (44 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.ImageToText;
using OpenAI.Chat;
// web aplication oluþtur
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddKernel()
.AddOllamaChatCompletion(
modelId: "moondream:latest",
endpoint: new Uri("http://localhost:11434")
);
var app = builder.Build();
app.MapPost("/image-captioning", async (IChatCompletionService chatService, IFormFile file) =>
{
using var memoryStream = new MemoryStream();
await file.CopyToAsync(memoryStream);
var imageBytes = memoryStream.ToArray();
//göreli açýklama
var chatHistory = new ChatHistory();
chatHistory.AddUserMessage([
new TextContent("Please describe this image in detail."),
new ImageContent(imageBytes, "image/jpeg")
]);
var captionResponse = await chatService.GetChatMessageContentAsync(chatHistory);
var englishCaption = captionResponse.ToString();
//deep seek ile türkçeye çevirme
var translateKernel = Kernel.CreateBuilder()
.AddOllamaChatCompletion(
modelId: "deepseek-r1:latest",
endpoint: new Uri("http://localhost:11434"))
.Build();
var translateService = translateKernel.GetRequiredService<IChatCompletionService>();
var trabslateHistory = new ChatHistory();
trabslateHistory.AddUserMessage($"Translate the following English text to Turkish. Only return the translation, nothing else:\n\n{englishCaption}");
var translateResponse = await translateService.GetChatMessageContentAsync(trabslateHistory);
return new
{
EnglishCaption = englishCaption,
TurkishCaption = translateResponse.Content
};
}).DisableAntiforgery();
#pragma warning restore SKEXP0001
app.Run();