-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add OpenAI , process PDF sample #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <RootNamespace>OpenAI_FileProcessing_Pdf_01</RootNamespace> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>0ef9e832-4d1e-45cf-acff-f7bb41388649</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" /> | ||
| <PackageReference Include="Microsoft.SemanticKernel" Version="1.55.0" /> | ||
| <PackageReference Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.55.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="docs\real-state-contract-1.pdf"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| <None Update="docs\real-state-contract-2.pdf"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,96 @@ | ||||||
| // based on the original sample for Semantic Kernel and Gemini | ||||||
| // https://medium.com/@johnidouglasmarangon/generating-structured-outputs-from-pdfs-with-semantic-kernel-and-gemini-aa4d4382e339 | ||||||
|
|
||||||
| using Microsoft.Extensions.Configuration; | ||||||
| using Microsoft.SemanticKernel; | ||||||
| using Microsoft.SemanticKernel.ChatCompletion; | ||||||
| using Microsoft.SemanticKernel.Connectors.OpenAI; | ||||||
| using System.ComponentModel; | ||||||
| using System.Text.Json; | ||||||
|
|
||||||
| // load OpenAI api_key value | ||||||
| var configBuilder = new ConfigurationBuilder().AddUserSecrets<Program>(); | ||||||
| var configuration = configBuilder.Build(); | ||||||
| string modelId = "gpt-4.1"; | ||||||
| string apiKey = configuration["api_key"]; | ||||||
|
|
||||||
| var builder = Kernel.CreateBuilder(); | ||||||
| builder.AddOpenAIChatCompletion(modelId, apiKey); | ||||||
| var kernel = builder.Build(); | ||||||
| var chatService = kernel.GetRequiredService<IChatCompletionService>(); | ||||||
|
|
||||||
| var filePath = Path.Combine(Directory.GetCurrentDirectory(), "docs", "real-state-contract-1.pdf"); | ||||||
|
||||||
| var filePath = Path.Combine(Directory.GetCurrentDirectory(), "docs", "real-state-contract-1.pdf"); | |
| var filePath = Path.Combine(Directory.GetCurrentDirectory(), "docs", "real-estate-contract-1.pdf"); |
Copilot
AI
Jun 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You’re passing response.ToString() into the deserializer, which may not be the raw JSON. Use response.Content instead to deserialize the actual payload.
| var contract = JsonSerializer.Deserialize<Contract>(response.ToString()); | |
| var contract = JsonSerializer.Deserialize<Contract>(response.Content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution entry references a "12 Files" folder without a project file; it won’t build. Remove or update this stub entry to avoid confusion.