-
Notifications
You must be signed in to change notification settings - Fork 287
Add ASP.NET Core example and update README #499
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for your contribution, @claudiogodoy99, and your interest in improving the OpenAI developer experience. We'll take a look and see if we can get this merged in! |
@scottaddie, @achandmsft: Would appreciate your thoughts on sample content and docs organization. |
@@ -138,6 +138,46 @@ AudioClient ttsClient = client.GetAudioClient("tts-1"); | |||
AudioClient whisperClient = client.GetAudioClient("whisper-1"); | |||
``` | |||
|
|||
## How to use dependency injection |
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.
Location seems a good choice to me and fits the taxonomy. Can we please add an entry to the Table of Contents for this?
@@ -0,0 +1,24 @@ | |||
Microsoft Visual Studio Solution File, Format Version 12.00 |
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.
We should probably rename the folder and solution to something like aspnet-core
to avoid spaces and make use across different OSes easier.
@@ -0,0 +1,15 @@ | |||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
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.
Can we please rename the project to match the solution/directory?
examples/ASP.NET Core/README.md
Outdated
|
||
1. **Set your OpenAI API key** using one of these methods: | ||
|
||
**Environment Variable (Recommended):** |
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.
silly as it may seem, we should consider using Windows conventions here by default (or PowerShell) and linking out to docs for *nix shells. For some reason, we've seen a number of folks struggle with using environment variables in the .NET ecosystem.
examples/ASP.NET Core/README.md
Outdated
@@ -0,0 +1,118 @@ | |||
# OpenAI ASP.NET Core Example | |||
|
|||
This example demonstrates how to use the OpenAI .NET client library with ASP.NET Core's dependency injection container, registering a ChatClient as a singleton for optimal performance and resource usage. |
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.
We may want to consider linking to things for DI and ASP.NET Core and such. Probably better to go with an "Additional Resources" area at the bottom than inline links, but your call.
examples/ASP.NET Core/README.md
Outdated
**Chat Completion:** | ||
|
||
```bash | ||
curl -X POST "https://localhost:7071/chat/complete" \ |
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.
I wonder if we should demonstrate PowerShell or similar as well since cURL isn't baked into Windows.
examples/ASP.NET Core/Program.cs
Outdated
|
||
app.Run(); | ||
|
||
record ChatRequest(string Message); |
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.
probably worth a comment here, as record
types are fairly new and many .NET developers aren't yet familair.
Co-authored-by: Jesse Squire <[email protected]>
Co-authored-by: Jesse Squire <[email protected]>
hey @jsquire, thanks for reviewing, I've made some commits addressing the comments. |
Hi team,
This PR adds a concrete example showing how to properly register and use the OpenAIClient with dependency injection in an ASP.NET Core application. It also includes a short highlighted section in the main README.md under the heading "How to use dependency injection".
PR for issue #498