0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

# Semantic Kernel:図識文

Posted at

 マルチモーダルは、LLM(大規模言語モデル)が持つ機能の一つであり、画像は最も一般的な情報キャリアです。GPTは早くから画像認識を行っており、GPTのバージョンが進化するにつれてその効果もますます良くなっています。SKも多くの場面で画像認識に適応してきましたが、最近のバージョンでやっとローカル画像のアップロードをサポートするようになりました。(少し遅いですが)

画像シーンの認識:

using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;

var chatModelId = "gpt-4o";
var key = File.ReadAllText(@"C:\GPT\key.txt");

#pragma warning disable SKEXP0070
#pragma warning disable SKEXP0010
#pragma warning disable SKEXP0001
#pragma warning disable SKEXP0110

var kernel = Kernel.CreateBuilder()
   .AddOpenAIChatCompletion(chatModelId, key)
   .Build();

var chat = kernel.GetRequiredService<IChatCompletionService>();
var chatHistory = new ChatHistory();

chatHistory.AddUserMessage(new ChatMessageContentItemCollection
{
     new TextContent("请说明这是那里,什么样的天气,大家在干什么?一共有多少人"),
     new ImageContent(File.ReadAllBytes("tam.jpg"),"image/jpeg")
});

var settings = new Dictionary<string, object>
{
    ["max_tokens"] = 1000,
    ["temperature"] = 0.2,
    ["top_p"] = 0.8,
    ["presence_penalty"] = 0.0,
    ["frequency_penalty"] = 0.0
};

var content = chat.GetStreamingChatMessageContentsAsync(chatHistory, new PromptExecutionSettings
{
    ExtensionData = settings
});

await foreach (var item in content)
{
    Console.Write(item.Content);
}
Console.ReadLine();

画像:

画像

結果:

結果画像

文字認識:

using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;

var chatModelId = "gpt-4o";
var key = File.ReadAllText(@"C:\GPT\key.txt");

#pragma warning disable SKEXP0070
#pragma warning disable SKEXP0010
#pragma warning disable SKEXP0001
#pragma warning disable SKEXP0110

var kernel = Kernel.CreateBuilder()
   .AddOpenAIChatCompletion(chatModelId, key)
   .Build();

var chat = kernel.GetRequiredService<IChatCompletionService>();
var chatHistory = new ChatHistory();

chatHistory.AddUserMessage(new ChatMessageContentItemCollection
{
     new TextContent("请识别图片上的文字,并输出"),
     new ImageContent(File.ReadAllBytes("japancard.png"),"image/jpeg")
});

var settings = new Dictionary<string, object>
{
    ["max_tokens"] = 1000,
    ["temperature"] = 0.2,
    ["top_p"] = 0.8,
    ["presence_penalty"] = 0.0,
    ["frequency_penalty"] = 0.0
};

var content = chat.GetStreamingChatMessageContentsAsync(chatHistory, new PromptExecutionSettings
{
    ExtensionData = settings
});

await foreach (var item in content)
{
    Console.Write(item.Content);
}
Console.ReadLine();

画像:

画像

結果:

結果画像

(Translated by GPT)

元のリンク:https://mp.weixin.qq.com/s?__biz=MzA3NDM1MzIyMQ==&mid=2247488312&idx=1&sn=81b481d4a5f0779d944b1f18d9b5d8ec&chksm=9f004c12a877c504200aa43c395f8f2cf041f9a84825c5362fa474c575395f85cb8db9667051&token=49086317&lang=zh_CN#rd&wt.mc_id=MVP_325642

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?