├── .gitignore
├── LICENSE
├── README.md
├── imgs
├── rpi5.png
└── ultrarunningmug.png
├── media
├── acesnow.mp4
└── gpt4otranslations.m4a
└── src
├── GPT4o_AOAI_lab01
├── GPT4o_AOAI_lab01.csproj
├── Program.cs
└── imgs
│ ├── foggyday.png
│ ├── foggydaysmall.png
│ ├── petsmusic.png
│ ├── rpi5.png
│ └── ultrarunningmug.png
├── GPT4o_AOAI_lab02
├── GPT4o_AOAI_lab02.csproj
├── Program.cs
└── imgs
│ ├── foggyday.png
│ ├── foggydaysmall.png
│ ├── petsmusic.png
│ ├── rpi5.png
│ └── ultrarunningmug.png
├── GPT4o_AOAI_lab03
├── GPT4o_AOAI_lab03.csproj
├── Program.cs
└── audio
│ └── NTNIntro.mp4
├── GPT4o_lab01
├── GPT4o_lab01.csproj
├── Program.cs
└── imgs
│ ├── rpi5.png
│ └── ultrarunningmug.png
├── GPT4o_lab02
├── GPT4o_lab02.csproj
├── Program.cs
└── media
│ └── NTNIntro.mp4
├── GPT4o_labs.sln
├── OAINETSDK_lab01
├── OAINETSDK_lab01.csproj
└── Program.cs
├── OAINETSDK_lab02
├── OAINETSDK_lab02.csproj
├── Program.cs
└── audio
│ └── NTNIntro.mp4
└── OAINETSDK_lab03
├── OAINETSDK_lab03.csproj
├── Program.cs
└── imgs
├── foggyday.png
├── foggydaysmall.png
├── petsmusic.png
├── rpi5.png
└── ultrarunningmug.png
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 | [Ll]ogs/
34 |
35 | # Visual Studio 2015/2017 cache/options directory
36 | .vs/
37 | # Uncomment if you have tasks that create the project's static files in wwwroot
38 | #wwwroot/
39 |
40 | # Visual Studio 2017 auto generated files
41 | Generated\ Files/
42 |
43 | # MSTest test Results
44 | [Tt]est[Rr]esult*/
45 | [Bb]uild[Ll]og.*
46 |
47 | # NUnit
48 | *.VisualState.xml
49 | TestResult.xml
50 | nunit-*.xml
51 |
52 | # Build Results of an ATL Project
53 | [Dd]ebugPS/
54 | [Rr]eleasePS/
55 | dlldata.c
56 |
57 | # Benchmark Results
58 | BenchmarkDotNet.Artifacts/
59 |
60 | # .NET Core
61 | project.lock.json
62 | project.fragment.lock.json
63 | artifacts/
64 |
65 | # ASP.NET Scaffolding
66 | ScaffoldingReadMe.txt
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.meta
77 | *.obj
78 | *.iobj
79 | *.pch
80 | *.pdb
81 | *.ipdb
82 | *.pgc
83 | *.pgd
84 | *.rsp
85 | *.sbr
86 | *.tlb
87 | *.tli
88 | *.tlh
89 | *.tmp
90 | *.tmp_proj
91 | *_wpftmp.csproj
92 | *.log
93 | *.tlog
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.)
298 | *.vbp
299 |
300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project)
301 | *.dsw
302 | *.dsp
303 |
304 | # Visual Studio 6 technical files
305 | *.ncb
306 | *.aps
307 |
308 | # Visual Studio LightSwitch build output
309 | **/*.HTMLClient/GeneratedArtifacts
310 | **/*.DesktopClient/GeneratedArtifacts
311 | **/*.DesktopClient/ModelManifest.xml
312 | **/*.Server/GeneratedArtifacts
313 | **/*.Server/ModelManifest.xml
314 | _Pvt_Extensions
315 |
316 | # Paket dependency manager
317 | .paket/paket.exe
318 | paket-files/
319 |
320 | # FAKE - F# Make
321 | .fake/
322 |
323 | # CodeRush personal settings
324 | .cr/personal
325 |
326 | # Python Tools for Visual Studio (PTVS)
327 | __pycache__/
328 | *.pyc
329 |
330 | # Cake - Uncomment if you are using it
331 | # tools/**
332 | # !tools/packages.config
333 |
334 | # Tabs Studio
335 | *.tss
336 |
337 | # Telerik's JustMock configuration file
338 | *.jmconfig
339 |
340 | # BizTalk build output
341 | *.btp.cs
342 | *.btm.cs
343 | *.odx.cs
344 | *.xsd.cs
345 |
346 | # OpenCover UI analysis results
347 | OpenCover/
348 |
349 | # Azure Stream Analytics local run output
350 | ASALocalRun/
351 |
352 | # MSBuild Binary and Structured Log
353 | *.binlog
354 |
355 | # NVidia Nsight GPU debugger configuration file
356 | *.nvuser
357 |
358 | # MFractors (Xamarin productivity tool) working folder
359 | .mfractor/
360 |
361 | # Local History for Visual Studio
362 | .localhistory/
363 |
364 | # Visual Studio History (VSHistory) files
365 | .vshistory/
366 |
367 | # BeatPulse healthcheck temp database
368 | healthchecksdb
369 |
370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
371 | MigrationBackup/
372 |
373 | # Ionide (cross platform F# VS Code tools) working folder
374 | .ionide/
375 |
376 | # Fody - auto-generated XML schema
377 | FodyWeavers.xsd
378 |
379 | # VS Code files for those working on multiple tools
380 | .vscode/*
381 | !.vscode/settings.json
382 | !.vscode/tasks.json
383 | !.vscode/launch.json
384 | !.vscode/extensions.json
385 | *.code-workspace
386 |
387 | # Local History for Visual Studio Code
388 | .history/
389 |
390 | # Windows Installer files from build outputs
391 | *.cab
392 | *.msi
393 | *.msix
394 | *.msm
395 | *.msp
396 |
397 | # JetBrains Rider
398 | *.sln.iml
399 |
400 | */bin/*
401 | */obj/*
402 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 El Bruno
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GPT-4o Labs Sample with C#
2 |
3 | [](/LICENSE)
4 | [](https://twitter.com/elbruno)
5 | 
6 |
7 | Welcome to the GPT-4o Labs samples using C#. This repository contains a demo projects that showcases how to integrate the powerful GPT-4o model with the new OpenAI Library for .NET and Semantic Kernel in a .NET environment.
8 |
9 | ## Prerequisites
10 |
11 | Before running the sample, ensure you have the following installed:
12 | - **.NET 8**: Make sure you have the latest version of .NET installed on your machine.
13 | - **(Optional) OpenAI Key**: An OpenAI API key is required to authenticate and interact with the GPT-4o model.
14 | - **(Optional) Azure OpenAI Services**: A GPT-4o model deployed in [Azure OpenAI Services](https://learn.microsoft.com/en-us/azure/ai-services/openai/overview?WT.mc_id=academic-00000-brunocapuano).
15 | - **(Optional) Visual Studio or Visual Studio Code**: You will need an IDE or code editor capable of running .NET projects. Visual Studio or Visual Studio Code are recommended.
16 |
17 | ## About the Samples
18 |
19 | The following samples demonstrates differnet capabilities of the GPT-4o model, in example: analyzing and describing an image. The samples uses the official OpenAI library for .NET and Semantic Kernel to process the image and generate a description using C#.
20 |
21 | Here is the list of projects:
22 |
23 | ### OpenAI APIs
24 |
25 | | Category | Name | Description | Source |
26 | |------|------|-------------|--------|
27 | | Semantic Kernel | GPT4o_lab01 | Chat sample analizing an image from a URL | `.\src\GPT4o_lab01` |
28 | | Semantic Kernel | GPT4o_lab02 | Audio to text sample | `.\src\GPT4o_lab02` |
29 | | OpenAI library for .NET | OAINETSDK_lab01 | Chat sample asking questions to `GPT-4o` | `.\src\OAINETSDK_lab01` |
30 | | OpenAI library for .NET | OAINETSDK_lab02 | Audio to text using `Whisper-1` | `.\src\OAINETSDK_lab02` |
31 | | OpenAI library for .NET | OAINETSDK_lab03 | Chat sample analizing an image from a local file with `GPT-4o` | `.\src\OAINETSDK_lab03` |
32 |
33 | ### Azure OpenAI Services
34 |
35 |
36 | | Category | Name | Description | Source |
37 | |------|------|-------------|--------|
38 | | Semantic Kernel | GPT4o_AOAI_lab01 | Chat sample analizing an image from a URL | `.\src\GPT4o_AOAI_lab01` |
39 | | Semantic Kernel | GPT4o_AOAI_lab02 | Upload an image to an Azure Blob and then analizes the image from the blob URL. | `.\src\GPT4o_AOAI_lab02` |
40 |
41 |
42 | ## Example: How to Run the Project
43 |
44 | To run the project, follow these steps:
45 | 1. Clone the repository to your local machine.
46 | 1. Open a terminal and enter your OpenAI Key with the following commands
47 |
48 | ```bash
49 | cd .\src\GPT4o_lab01\
50 |
51 | # init projecs user-secrets
52 | dotnet user-secrets init
53 |
54 | # add OpenAI API Key
55 | dotnet user-secrets set "APIKEY" "OpenAI API KEY"
56 | ```
57 |
58 | 1. Run the project with the command
59 |
60 | ```bash
61 | dotnet run
62 | ```
63 |
64 | 1. The current project analyzes this image
65 |
66 | 
67 |
68 | 1. You should see an output similar to this one:
69 |
70 | *The image shows a person holding a mug that has the text "Ultrarunning (verb) the art of running as far as you can, and then running another 20 miles." In the background, there is a scenic view of trees and lush greenery, along with an outdoor swimming pool surrounded by a paved deck with lounge chairs. Additionally, a dog is partially visible near the bottom right of the image, standing near the railing. The scene appears to be tranquil and picturesque, likely taking place in a backyard or a similar outdoor setting.*
71 |
72 |
73 |
74 |
75 | ## References
76 |
77 | - [Announcing the official OpenAI library for .NET](https://devblogs.microsoft.com/dotnet/openai-dotnet-library/?WT.mc_id=academic-00000-brunocapuano)
78 | - [What is Azure OpenAI Service?](https://learn.microsoft.com/en-us/azure/ai-services/openai/overview?WT.mc_id=academic-00000-brunocapuano)
79 | - [Quickstart: Azure Blob Storage client library for .NET](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet?WT.mc_id=academic-00000-brunocapuano)
80 |
81 | ## Author
82 |
83 | 👤 **Bruno Capuano**
84 |
85 | * Website: https://elbruno.com
86 | * Twitter: [@elbruno](https://twitter.com/elbruno)
87 | * Github: [@elbruno](https://github.com/elbruno)
88 | * LinkedIn: [@elbruno](https://linkedin.com/in/elbruno)
89 |
90 | ## 🤝 Contributing
91 |
92 | Contributions, issues and feature requests are welcome!
93 |
94 | Feel free to check [issues page](https://github.com/elbruno/gpt4ol-sk-csharp//issues).
95 |
96 | ## Show your support
97 |
98 | Give a ⭐️ if this project helped you!
99 |
100 |
101 | ## 📝 License
102 |
103 | Copyright © 2024 [Bruno Capuano](https://github.com/elbruno).
104 |
105 | This project is [MIT](/LICENSE) licensed.
106 |
107 | ***
108 |
--------------------------------------------------------------------------------
/imgs/rpi5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/imgs/rpi5.png
--------------------------------------------------------------------------------
/imgs/ultrarunningmug.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/imgs/ultrarunningmug.png
--------------------------------------------------------------------------------
/media/acesnow.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/media/acesnow.mp4
--------------------------------------------------------------------------------
/media/gpt4otranslations.m4a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/media/gpt4otranslations.m4a
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab01/GPT4o_AOAI_lab01.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | 54628801-6883-4e5f-9467-455b849582b1
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | PreserveNewest
23 |
24 |
25 | PreserveNewest
26 |
27 |
28 | PreserveNewest
29 |
30 |
31 | PreserveNewest
32 |
33 |
34 | PreserveNewest
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab01/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Configuration;
2 | using Microsoft.SemanticKernel;
3 | using Microsoft.SemanticKernel.ChatCompletion;
4 |
5 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
6 |
7 | var deploymentName = config["AZURE_OPENAI_MODEL"];
8 | var endpoint = config["AZURE_OPENAI_ENDPOINT"];
9 | var apiKey = config["AZURE_OPENAI_APIKEY"];
10 |
11 | #pragma warning disable SKEXP0001, SKEXP0003, SKEXP0010, SKEXP0011, SKEXP0050, SKEXP0052
12 | var builder = Kernel.CreateBuilder();
13 | builder.AddAzureOpenAIChatCompletion(deploymentName, endpoint, apiKey);
14 | var kernel = builder.Build();
15 |
16 | var chat = kernel.GetRequiredService();
17 | var history = new ChatHistory();
18 | history.AddSystemMessage("You are a useful assistant that replies using a direct style");
19 |
20 | var imageContent = new ImageContent();
21 |
22 | // use remote image
23 | imageContent.Uri = new Uri("https://github.com/elbruno/gpt4ol-sk-csharp/blob/main/src/GPT4o_lab03/imgs/foggyday.png?raw=true");
24 |
25 | var collectionItems = new ChatMessageContentItemCollection
26 | {
27 | new TextContent("What's in the image?"),
28 | imageContent
29 | };
30 |
31 |
32 | history.AddUserMessage(collectionItems);
33 |
34 | var result = await chat.GetChatMessageContentsAsync(history);
35 | Console.WriteLine("Image description: " + result[^1].Content);
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab01/imgs/foggyday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab01/imgs/foggyday.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab01/imgs/foggydaysmall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab01/imgs/foggydaysmall.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab01/imgs/petsmusic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab01/imgs/petsmusic.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab01/imgs/rpi5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab01/imgs/rpi5.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab01/imgs/ultrarunningmug.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab01/imgs/ultrarunningmug.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab02/GPT4o_AOAI_lab02.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | 6897942c-7c8e-441d-92c6-4e95192ce4de
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | PreserveNewest
21 |
22 |
23 | PreserveNewest
24 |
25 |
26 | PreserveNewest
27 |
28 |
29 | PreserveNewest
30 |
31 |
32 | PreserveNewest
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab02/Program.cs:
--------------------------------------------------------------------------------
1 | using Azure.Identity;
2 | using Azure.Storage.Blobs;
3 | using Microsoft.Extensions.Configuration;
4 | using Microsoft.SemanticKernel;
5 | using Microsoft.SemanticKernel.ChatCompletion;
6 |
7 |
8 |
9 |
10 |
11 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
12 |
13 | var deploymentName = config["AZURE_OPENAI_MODEL"];
14 | var endpoint = config["AZURE_OPENAI_ENDPOINT"];
15 | var apiKey = config["AZURE_OPENAI_APIKEY"];
16 | var azureBlobUri = config["AZURE_BLOB_URI"];
17 | var containerName = config["AZURE_BLOB_URI_CONTAINERNAME"];
18 |
19 | #pragma warning disable SKEXP0001, SKEXP0003, SKEXP0010, SKEXP0011, SKEXP0050, SKEXP0052
20 | var builder = Kernel.CreateBuilder();
21 | builder.AddAzureOpenAIChatCompletion(deploymentName, endpoint, apiKey);
22 | var kernel = builder.Build();
23 |
24 | // init chat
25 | var chat = kernel.GetRequiredService();
26 | var history = new ChatHistory();
27 | history.AddSystemMessage("You are a useful assistant that replies using a direct style");
28 |
29 | // use local image
30 | var imageFile = "foggyday.png";
31 | var imageFullPath = Path.Combine(Directory.GetCurrentDirectory(), "imgs", imageFile);
32 | var imgInBlobUri = await UploadFileToAzureBlob(azureBlobUri, containerName, imageFile, imageFullPath);
33 |
34 | // create chat collection items
35 | var collectionItems = new ChatMessageContentItemCollection
36 | {
37 | new TextContent("What's in the image?"),
38 | new ImageContent(new Uri(imgInBlobUri))
39 | };
40 | history.AddUserMessage(collectionItems);
41 |
42 | // get the image description
43 | var result = await chat.GetChatMessageContentsAsync(history);
44 | Console.WriteLine("Image description: " + result[^1].Content);
45 |
46 | async Task UploadFileToAzureBlob(string azureBlobUri, string containerName, string imageFileName, string imageFullPath)
47 | {
48 | var blobServiceClient = new BlobServiceClient(new Uri(azureBlobUri), new DefaultAzureCredential());
49 | var containerClient = blobServiceClient.GetBlobContainerClient(containerName);
50 | var blobClient = containerClient.GetBlobClient(imageFileName);
51 | Console.WriteLine($"Uploading to Blob storage as blob:\n\t {blobClient.Uri}\n");
52 | await blobClient.UploadAsync(imageFullPath, true);
53 | Console.WriteLine($"Uploading complete ...\n");
54 | return blobClient.Uri.ToString();
55 | }
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab02/imgs/foggyday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab02/imgs/foggyday.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab02/imgs/foggydaysmall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab02/imgs/foggydaysmall.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab02/imgs/petsmusic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab02/imgs/petsmusic.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab02/imgs/rpi5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab02/imgs/rpi5.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab02/imgs/ultrarunningmug.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab02/imgs/ultrarunningmug.png
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab03/GPT4o_AOAI_lab03.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | e6922458-db62-489f-be9f-aec7078f67e4
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | PreserveNewest
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab03/Program.cs:
--------------------------------------------------------------------------------
1 | using Azure.Identity;
2 | using Azure.Storage.Blobs;
3 | using Microsoft.Extensions.Configuration;
4 | using Microsoft.SemanticKernel;
5 | using Microsoft.SemanticKernel.ChatCompletion;
6 |
7 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
8 |
9 | var deploymentName = config["AZURE_OPENAI_MODEL"];
10 | var endpoint = config["AZURE_OPENAI_ENDPOINT"];
11 | var apiKey = config["AZURE_OPENAI_APIKEY"];
12 | var azureBlobUri = config["AZURE_BLOB_URI"];
13 | var containerName = config["AZURE_BLOB_URI_CONTAINERNAME"];
14 |
15 | #pragma warning disable SKEXP0001, SKEXP0003, SKEXP0010, SKEXP0011, SKEXP0050, SKEXP0052
16 | var builder = Kernel.CreateBuilder();
17 | builder.AddAzureOpenAIChatCompletion(deploymentName, endpoint, apiKey);
18 | var kernel = builder.Build();
19 |
20 | // init chat
21 | var chat = kernel.GetRequiredService();
22 | var history = new ChatHistory();
23 | history.AddSystemMessage("You are a useful assistant that replies using a direct style");
24 |
25 | // use local image
26 | var audioFile = "NTNIntro.mp4";
27 | var audioFullPath = Path.Combine(Directory.GetCurrentDirectory(), "audio", audioFile);
28 | var audioBytes = File.ReadAllBytes(audioFullPath);
29 |
30 | // create chat collection items
31 | var collectionItems = new ChatMessageContentItemCollection
32 | {
33 | new TextContent("What's in the image?"),
34 | new AudioContent(audioBytes, "audio/mp4")
35 | };
36 | history.AddUserMessage(collectionItems);
37 |
38 | // get the audio transcript
39 | var result = await chat.GetChatMessageContentsAsync(history);
40 | Console.WriteLine("Image description: " + result[^1].Content);
41 |
--------------------------------------------------------------------------------
/src/GPT4o_AOAI_lab03/audio/NTNIntro.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_AOAI_lab03/audio/NTNIntro.mp4
--------------------------------------------------------------------------------
/src/GPT4o_lab01/GPT4o_lab01.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | f6ffe400-e0d1-46bb-b13c-9a389d79a5fd
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | PreserveNewest
23 |
24 |
25 | PreserveNewest
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/GPT4o_lab01/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024
2 | // Author : Bruno Capuano
3 | // Change Log :
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 |
25 | using Microsoft.Extensions.Configuration;
26 | using Microsoft.SemanticKernel;
27 | using Microsoft.SemanticKernel.ChatCompletion;
28 |
29 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
30 | var apikey = config["APIKEY"];
31 | var model = "gpt-4o";
32 |
33 |
34 | #pragma warning disable SKEXP0001, SKEXP0003, SKEXP0010, SKEXP0011, SKEXP0050, SKEXP0052
35 | var builder = Kernel.CreateBuilder();
36 | builder.AddOpenAIChatCompletion (model, apikey);
37 | var kernel = builder.Build();
38 |
39 | var chat = kernel.GetRequiredService();
40 | var history = new ChatHistory();
41 | history.AddSystemMessage("You are a useful assistant that replies using a direct style");
42 |
43 | // analize image
44 | var collectionItems= new ChatMessageContentItemCollection
45 | {
46 | new TextContent("What's in the image?"),
47 | new ImageContent(new Uri("https://github.com/elbruno/gpt4ol-sk-csharp/blob/main/imgs/rpi5.png?raw=true"))
48 | };
49 | history.AddUserMessage(collectionItems);
50 |
51 | var result = await chat.GetChatMessageContentsAsync(history);
52 | Console.WriteLine("Image description: " + result[^1].Content);
--------------------------------------------------------------------------------
/src/GPT4o_lab01/imgs/rpi5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_lab01/imgs/rpi5.png
--------------------------------------------------------------------------------
/src/GPT4o_lab01/imgs/ultrarunningmug.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_lab01/imgs/ultrarunningmug.png
--------------------------------------------------------------------------------
/src/GPT4o_lab02/GPT4o_lab02.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | d84161c2-7b56-4822-8c9b-3e595bc6c9db
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | PreserveNewest
23 |
24 |
25 | PreserveNewest
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/GPT4o_lab02/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024
2 | // Author : Bruno Capuano
3 | // Change Log :
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 |
25 | using Microsoft.Extensions.Configuration;
26 | using Microsoft.SemanticKernel;
27 | using Microsoft.SemanticKernel.AudioToText;
28 | using Microsoft.SemanticKernel.ChatCompletion;
29 | using Microsoft.SemanticKernel.Connectors.OpenAI;
30 |
31 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
32 | var apikey = config["APIKEY"];
33 | var model = "whisper-1";
34 |
35 |
36 | #pragma warning disable SKEXP0001, SKEXP0003, SKEXP0010, SKEXP0011, SKEXP0050, SKEXP0052
37 | // Create a kernel with OpenAI audio to text service
38 | var kernel = Kernel.CreateBuilder()
39 | .AddOpenAIAudioToText(
40 | modelId: model,
41 | apiKey: apikey)
42 | .Build();
43 |
44 | var audioToTextService = kernel.GetRequiredService();
45 |
46 | // audio file data
47 | var audioFileName = "NTNIntro.mp4";
48 | var audioFullPath = Path.Combine(Directory.GetCurrentDirectory(), "media", audioFileName);
49 | var audioBytes = File.ReadAllBytes(audioFullPath);
50 |
51 | // Read audio content from a file
52 | AudioContent audioContent = new(audioBytes);
53 |
54 | // Set execution settings (optional)
55 | OpenAIAudioToTextExecutionSettings executionSettings = new()
56 | {
57 | Filename = audioFileName,
58 | Language = "es", // The language of the audio data as two-letter ISO-639-1 language code (e.g. 'en' or 'es').
59 | Prompt = "Extract text from audio", // An optional text to guide the model's style or continue a previous audio segment.
60 | // The prompt should match the audio language.
61 | ResponseFormat = "json", // The format to return the transcribed text in.
62 | // Supported formats are json, text, srt, verbose_json, or vtt. Default is 'json'.
63 | Temperature = 0.3f, // The randomness of the generated text.
64 | // Select a value from 0.0 to 1.0. 0 is the default.
65 | };
66 |
67 | //// get text single call
68 | var textContent = await audioToTextService.GetTextContentAsync(audioContent, executionSettings);
69 | Console.WriteLine("Audio : " + textContent.Text);
70 |
71 | // processing in List Mode
72 | //var textContents = await audioToTextService.GetTextContentsAsync(audioContent, executionSettings);
73 | //foreach (var text in textContents)
74 | //{
75 | // Console.Write(text);
76 | //}
77 |
78 |
--------------------------------------------------------------------------------
/src/GPT4o_lab02/media/NTNIntro.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/GPT4o_lab02/media/NTNIntro.mp4
--------------------------------------------------------------------------------
/src/GPT4o_labs.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31903.59
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GPT4o_lab01", "GPT4o_lab01\GPT4o_lab01.csproj", "{2CFF5FFA-D902-4625-92D1-31A1B0BB1C83}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GPT4o_lab02", "GPT4o_lab02\GPT4o_lab02.csproj", "{B14891A6-2766-4CA3-A331-6295B0299509}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GPT4o_AOAI_lab01", "GPT4o_AOAI_lab01\GPT4o_AOAI_lab01.csproj", "{6021304C-DE37-4299-B6D8-2A9A84861244}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GPT4o_AOAI_lab02", "GPT4o_AOAI_lab02\GPT4o_AOAI_lab02.csproj", "{93049FF4-74D3-4E9A-B2BF-02DBF1A9BF94}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OAINETSDK_lab01", "OAINETSDK_lab01\OAINETSDK_lab01.csproj", "{3D3DCAEC-CCB6-44C5-BF84-F154DE846A22}"
15 | EndProject
16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OAINETSDK_lab02", "OAINETSDK_lab02\OAINETSDK_lab02.csproj", "{1F12B9CC-BF7D-40DB-A831-98B7FB11B331}"
17 | EndProject
18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OAINETSDK_lab03", "OAINETSDK_lab03\OAINETSDK_lab03.csproj", "{161E5AF2-38F1-4B61-B57A-446583451087}"
19 | EndProject
20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SK OpenAI API Labs", "SK OpenAI API Labs", "{326EF34B-96CC-4E27-90E2-481DC2E8CB44}"
21 | EndProject
22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenAI Library Labs", "OpenAI Library Labs", "{4B7362A0-E943-48F8-96D4-A3FEAC723A2C}"
23 | EndProject
24 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SL AOAI Labs", "SL AOAI Labs", "{95CA4443-5DE9-42D0-953D-B31256F4655F}"
25 | EndProject
26 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GPT4o_AOAI_lab03", "GPT4o_AOAI_lab03\GPT4o_AOAI_lab03.csproj", "{12373DAF-A4BA-4B49-B98D-21DB7ED93253}"
27 | EndProject
28 | Global
29 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
30 | Debug|Any CPU = Debug|Any CPU
31 | Release|Any CPU = Release|Any CPU
32 | EndGlobalSection
33 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
34 | {2CFF5FFA-D902-4625-92D1-31A1B0BB1C83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {2CFF5FFA-D902-4625-92D1-31A1B0BB1C83}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {2CFF5FFA-D902-4625-92D1-31A1B0BB1C83}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {2CFF5FFA-D902-4625-92D1-31A1B0BB1C83}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {B14891A6-2766-4CA3-A331-6295B0299509}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {B14891A6-2766-4CA3-A331-6295B0299509}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {B14891A6-2766-4CA3-A331-6295B0299509}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {B14891A6-2766-4CA3-A331-6295B0299509}.Release|Any CPU.Build.0 = Release|Any CPU
42 | {6021304C-DE37-4299-B6D8-2A9A84861244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43 | {6021304C-DE37-4299-B6D8-2A9A84861244}.Debug|Any CPU.Build.0 = Debug|Any CPU
44 | {6021304C-DE37-4299-B6D8-2A9A84861244}.Release|Any CPU.ActiveCfg = Release|Any CPU
45 | {6021304C-DE37-4299-B6D8-2A9A84861244}.Release|Any CPU.Build.0 = Release|Any CPU
46 | {93049FF4-74D3-4E9A-B2BF-02DBF1A9BF94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 | {93049FF4-74D3-4E9A-B2BF-02DBF1A9BF94}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 | {93049FF4-74D3-4E9A-B2BF-02DBF1A9BF94}.Release|Any CPU.ActiveCfg = Release|Any CPU
49 | {93049FF4-74D3-4E9A-B2BF-02DBF1A9BF94}.Release|Any CPU.Build.0 = Release|Any CPU
50 | {3D3DCAEC-CCB6-44C5-BF84-F154DE846A22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51 | {3D3DCAEC-CCB6-44C5-BF84-F154DE846A22}.Debug|Any CPU.Build.0 = Debug|Any CPU
52 | {3D3DCAEC-CCB6-44C5-BF84-F154DE846A22}.Release|Any CPU.ActiveCfg = Release|Any CPU
53 | {3D3DCAEC-CCB6-44C5-BF84-F154DE846A22}.Release|Any CPU.Build.0 = Release|Any CPU
54 | {1F12B9CC-BF7D-40DB-A831-98B7FB11B331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
55 | {1F12B9CC-BF7D-40DB-A831-98B7FB11B331}.Debug|Any CPU.Build.0 = Debug|Any CPU
56 | {1F12B9CC-BF7D-40DB-A831-98B7FB11B331}.Release|Any CPU.ActiveCfg = Release|Any CPU
57 | {1F12B9CC-BF7D-40DB-A831-98B7FB11B331}.Release|Any CPU.Build.0 = Release|Any CPU
58 | {161E5AF2-38F1-4B61-B57A-446583451087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59 | {161E5AF2-38F1-4B61-B57A-446583451087}.Debug|Any CPU.Build.0 = Debug|Any CPU
60 | {161E5AF2-38F1-4B61-B57A-446583451087}.Release|Any CPU.ActiveCfg = Release|Any CPU
61 | {161E5AF2-38F1-4B61-B57A-446583451087}.Release|Any CPU.Build.0 = Release|Any CPU
62 | {12373DAF-A4BA-4B49-B98D-21DB7ED93253}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63 | {12373DAF-A4BA-4B49-B98D-21DB7ED93253}.Debug|Any CPU.Build.0 = Debug|Any CPU
64 | {12373DAF-A4BA-4B49-B98D-21DB7ED93253}.Release|Any CPU.ActiveCfg = Release|Any CPU
65 | {12373DAF-A4BA-4B49-B98D-21DB7ED93253}.Release|Any CPU.Build.0 = Release|Any CPU
66 | EndGlobalSection
67 | GlobalSection(SolutionProperties) = preSolution
68 | HideSolutionNode = FALSE
69 | EndGlobalSection
70 | GlobalSection(NestedProjects) = preSolution
71 | {2CFF5FFA-D902-4625-92D1-31A1B0BB1C83} = {326EF34B-96CC-4E27-90E2-481DC2E8CB44}
72 | {B14891A6-2766-4CA3-A331-6295B0299509} = {326EF34B-96CC-4E27-90E2-481DC2E8CB44}
73 | {6021304C-DE37-4299-B6D8-2A9A84861244} = {95CA4443-5DE9-42D0-953D-B31256F4655F}
74 | {93049FF4-74D3-4E9A-B2BF-02DBF1A9BF94} = {95CA4443-5DE9-42D0-953D-B31256F4655F}
75 | {3D3DCAEC-CCB6-44C5-BF84-F154DE846A22} = {4B7362A0-E943-48F8-96D4-A3FEAC723A2C}
76 | {1F12B9CC-BF7D-40DB-A831-98B7FB11B331} = {4B7362A0-E943-48F8-96D4-A3FEAC723A2C}
77 | {161E5AF2-38F1-4B61-B57A-446583451087} = {4B7362A0-E943-48F8-96D4-A3FEAC723A2C}
78 | {12373DAF-A4BA-4B49-B98D-21DB7ED93253} = {95CA4443-5DE9-42D0-953D-B31256F4655F}
79 | EndGlobalSection
80 | GlobalSection(ExtensibilityGlobals) = postSolution
81 | SolutionGuid = {92D6952D-35FB-410F-8F37-0895EFC49F3D}
82 | EndGlobalSection
83 | EndGlobal
84 |
--------------------------------------------------------------------------------
/src/OAINETSDK_lab01/OAINETSDK_lab01.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | 321a12a2-073f-4283-bce1-ade1dea9b4ea
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/OAINETSDK_lab01/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024
2 | // Author : Bruno Capuano
3 | // Change Log :
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 |
25 | using Microsoft.Extensions.Configuration;
26 | using OpenAI.Chat;
27 |
28 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
29 | var openAIKey = config["APIKEY"];
30 | var model = "gpt-4o";
31 |
32 | // chat client
33 | ChatClient client = new(model, openAIKey);
34 |
35 | // define system message
36 | var systemMessage = new
37 | SystemChatMessage("You are a useful assitant that replies using a funny style.");
38 | var userQ = new UserChatMessage("What is the capital of France?");
39 | var messages = new List { systemMessage, userQ };
40 |
41 | // run the chat
42 | ChatCompletion chatCompletion = client.CompleteChat(messages);
43 |
44 | // show the original question and the chat response in the console
45 | Console.WriteLine($@"System Prompt: {systemMessage.Content[^1].Text}
46 |
47 | User Question: {userQ.Content[^1].Text}
48 |
49 | Response: {chatCompletion.Content[^1].Text}");
--------------------------------------------------------------------------------
/src/OAINETSDK_lab02/OAINETSDK_lab02.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | e4900aaf-89fb-4d64-be35-d1e270ccdb6c
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | PreserveNewest
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/OAINETSDK_lab02/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024
2 | // Author : Bruno Capuano
3 | // Change Log :
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 |
25 | using Microsoft.Extensions.Configuration;
26 | using OpenAI.Audio;
27 |
28 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
29 | var openAIKey = config["APIKEY"];
30 | var model = "whisper-1";
31 |
32 | // audio client
33 | AudioClient client = new(model: model, openAIKey);
34 |
35 | string audioFilePath = Path.Combine("audio", "NTNIntro.mp4");
36 |
37 | AudioTranscriptionOptions options = new()
38 | {
39 | ResponseFormat = AudioTranscriptionFormat.Verbose,
40 | Granularities = AudioTimestampGranularities.Word | AudioTimestampGranularities.Segment,
41 | };
42 |
43 | AudioTranscription transcription = client.TranscribeAudio(audioFilePath, options);
44 |
45 | Console.WriteLine("Transcription:");
46 | Console.WriteLine($"{transcription.Text}");
47 |
48 | Console.WriteLine();
49 | Console.WriteLine($"Words:");
50 | foreach (TranscribedWord word in transcription.Words)
51 | {
52 | Console.WriteLine($" {word.Word,15} : {word.Start.TotalMilliseconds,5:0} - {word.End.TotalMilliseconds,5:0}");
53 | }
54 |
55 | Console.WriteLine();
56 | Console.WriteLine($"Segments:");
57 | foreach (TranscribedSegment segment in transcription.Segments)
58 | {
59 | Console.WriteLine($" {segment.Text,90} : {segment.Start.TotalMilliseconds,5:0} - {segment.End.TotalMilliseconds,5:0}");
60 | }
--------------------------------------------------------------------------------
/src/OAINETSDK_lab02/audio/NTNIntro.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/OAINETSDK_lab02/audio/NTNIntro.mp4
--------------------------------------------------------------------------------
/src/OAINETSDK_lab03/OAINETSDK_lab03.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | 6d50749a-95d9-4b11-9772-fc5906c23542
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | PreserveNewest
20 |
21 |
22 | PreserveNewest
23 |
24 |
25 | PreserveNewest
26 |
27 |
28 | PreserveNewest
29 |
30 |
31 | PreserveNewest
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/OAINETSDK_lab03/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024
2 | // Author : Bruno Capuano
3 | // Change Log :
4 | //
5 | // The MIT License (MIT)
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 |
25 | using Microsoft.Extensions.Configuration;
26 | using OpenAI;
27 | using OpenAI.Assistants;
28 | using OpenAI.Chat;
29 | using OpenAI.Files;
30 | using System.ClientModel;
31 |
32 | #pragma warning disable OPENAI001
33 |
34 | var config = new ConfigurationBuilder().AddUserSecrets().Build();
35 | var openAIKey = config["APIKEY"];
36 | var model = "gpt-4o";
37 |
38 | OpenAIClient openAIClient = new(openAIKey);
39 | FileClient fileClient = openAIClient.GetFileClient();
40 | var assistantClient = openAIClient.GetAssistantClient();
41 |
42 |
43 | var imageFile = "foggyday.png";
44 | var imageFullPath = Path.Combine(Directory.GetCurrentDirectory(), "imgs", imageFile);
45 | OpenAIFileInfo imgFile = fileClient.UploadFile(imageFullPath, FileUploadPurpose.Vision);
46 |
47 | var imageMessage = MessageContent.FromImageFileId(imgFile.Id);
48 |
49 | Assistant assistant = assistantClient.CreateAssistant(
50 | model: model,
51 | new AssistantCreationOptions()
52 | {
53 | Instructions = "You are a useful assistant that replies using a funny style and always in Spanish."
54 | });
55 |
56 | AssistantThread thread = assistantClient.CreateThread(new ThreadCreationOptions()
57 | {
58 | InitialMessages =
59 | {
60 | new ThreadInitializationMessage(
61 | [
62 | "Hello, assistant! Please describe this image for me:",
63 | MessageContent.FromImageFileId(imgFile.Id)
64 | ]),
65 | }
66 | });
67 |
68 | var streamingUpdates = assistantClient.CreateRunStreaming(thread,assistant);
69 |
70 | foreach (StreamingUpdate streamingUpdate in streamingUpdates)
71 | {
72 | if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
73 | {
74 | Console.WriteLine($"--- Run started! ---");
75 | }
76 | if (streamingUpdate is MessageContentUpdate contentUpdate)
77 | {
78 | Console.Write(contentUpdate.Text);
79 | }
80 | }
--------------------------------------------------------------------------------
/src/OAINETSDK_lab03/imgs/foggyday.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/OAINETSDK_lab03/imgs/foggyday.png
--------------------------------------------------------------------------------
/src/OAINETSDK_lab03/imgs/foggydaysmall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/OAINETSDK_lab03/imgs/foggydaysmall.png
--------------------------------------------------------------------------------
/src/OAINETSDK_lab03/imgs/petsmusic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/OAINETSDK_lab03/imgs/petsmusic.png
--------------------------------------------------------------------------------
/src/OAINETSDK_lab03/imgs/rpi5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/OAINETSDK_lab03/imgs/rpi5.png
--------------------------------------------------------------------------------
/src/OAINETSDK_lab03/imgs/ultrarunningmug.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elbruno/gpt4o-labs-csharp/4511245474231fa028f7e5aed10b531ec03f2236/src/OAINETSDK_lab03/imgs/ultrarunningmug.png
--------------------------------------------------------------------------------