This repository contains a simple console application demonstrating how to interact with the OpenAI API using C# (.NET Core).
The application allows you to chat with an AI model (GPT-3.5-Turbo), taking user input from the command line, sending it to the OpenAI API and displaying the AI's response.
The project is composed of a single console application that interacts with the OpenAI API. It is structured as follows:
Program.cs
: The entry point of the application. Contains a chat loop that continually prompts the user for input, sends it to the OpenAI API, and displays the AI's response.OpenAIService.cs
: A service class that encapsulates the logic for sending prompts to the OpenAI API and parsing the API's response.ChatSession.cs
: A class that manages a chat session, keeping track of the conversation history and adding user prompts to it.
- Clone the repository to your local machine.
- Navigate to the root directory of the project.
- Add your OpenAI API key to the project using .NET's Secret Manager:
dotnet user-secrets set "OpenAI:ApiKey" "<Your OpenAI API Key>"
- Run the project:
dotnet run
Once the application is running, simply type your message at the prompt and hit enter. The AI's response will be displayed on the next line.
This project was created as part of a blog post tutorial on using OpenAI with .NET Core. Read the full tutorial here.
This project is licensed under the terms of the MIT license.