This project is a simple console-based chatbot that interacts with OpenAI's GPT-3.5 model. The chatbot takes user input, sends it to the OpenAI API, and displays the response.
The purpose of this Chat Bot is to chat with potential job candidates. The chatbot will discover the following information about the candidate:
- How many years of experience he or she has.
- What is your favorite programming language.
- Whether or not you are willing to program using Ruby.
- Whether or not you are willing to work on site.
- Answer any questions the potential tenant may have about the job.
- When the candidate wants to be interviewed.
The rules:
- It is not possible to write messages with more than 30 words.
- You cannot talk about anything other than the job
- As soon as the bot finds out everything about the above objectives (and the candidate has no more doubts) he must say goodbye
- Language: C#
- Framework: .NET Core
- API: OpenAI GPT-3.5
- Libraries:
System.TextSystem.Text.JsonSystem.Net.HttpChatbotIA.Model
- User Interaction: The application prompts the user to enter a question. (In principle it works this way, but the features described in the overview will be increased)
- API Request: The user's question is sent to the OpenAI API. (As stated in topic one, questions and answers will be held)
- API Response: The API response is processed and displayed back to the user.
- Repeat: The process repeats until the user types "exit" to exit the application. (As said in topic one, as soon as all doubts are resolved and the user has no more questions, the bot will say goodbye)
The main logic of the application is divided into a few key parts:
-
Main Loop
Validation: Checks if the input is valid (non-empty).API Key: Sets the API key for authorization.HTTP Client: Creates an HTTP client to send the request.Request Payload: Constructs the request payload with model details, temperature, token limit, and user message.Send Request: Sends the request to the OpenAI API and waits for the response.Handle Response: If successful, parses and displays the response. Otherwise, displays an error message.
-
Resposta Class: Represents the structure of the API response.
- choices: A list of
Choiceobjects containing the response details. - data: An array of
Dataobjects (not used in the current implementation).
- choices: A list of
-
Choice Class: Represents individual choices in the response.
- index, logoprobs, finish_reason, message, description: Various properties related to the response.
-
Message Class: Represents the message content and role.
-
Data Class: Represents additional data (not used in the current implementation).
- Clone the repository.
- Open the project in your preferred C# IDE.
- Replace
your-api-key-herewith your actual OpenAI API key. - Run the project.
- Follow the on-screen instructions to interact with the chatbot.
- Ensure you have an active OpenAI API key.
- The model used is
gpt-3.5-turbo-0125; you can change it based on availability and requirements. - Adjust
temperatureandmax_tokensas needed to fine-tune the responses.