This is a full stack application built with ASP.NET Core 8 and Next.js with TypeScript and TailwindCSS. The application is a chat bot powered by PaLM 2.
This application is part of the blog post titled "Creating a Chatbot with ASP.NET Core, Next.js and PaLM API". Feel free to read the article for a more detailed explanation of the application.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Clone the repository
git clone https://github.com/RianNegreiros/DotNetChatBot.git
- Setup the server configuration
cd src/API
cp appsettings.json.example appsettings.json
Then set the LANGUAGE_MODEL:API_KEY
with your PaLM API key or get one here
- Setup the client configuration
cd src/client
cp .env.example .env
- Restore the .NET packages and run the ASP.NET API
dotnet restore
dotnet run --project src/API
- Navigate to the client directory, install the dependencies and run the client
cd src/client
npm install
npm run dev
If you have Docker Compose installed, you can use it to run the application:
- Setup the server configuration
cd src/API
cp appsettings.json.example appsettings.json
Then set the LANGUAGE_MODEL:API_KEY
with your PaLM API key or get one here
- Setup the client configuration
cd src/client
cp .env.example .env
- Run the Docker compose
docker compose up --build
The application should now be running at http://localhost:3000
.
The API has the following endpoints:
-
/prompt/{text}
: This endpoint generates a language model response from the PaLM API. The{text}
parameter is the text to be processed by the language model. The endpoint returns a JSON response with the generated message. -
/health
: This endpoint checks the health of the application and its connection to the Google API.
The API also includes Swagger UI for testing and documenting the API endpoints. You can access it at /swagger
.
The project includes the following extensions:
-
AddSwaggerExtension
: This extension adds Swagger/OpenAPI support to the project. -
AddCorsExtension
: This extension adds CORS policy to the project. By default, it allows POST requests fromhttp://localhost:3000
. -
AddHealthChecksExtension
: This extension adds health checks to the project. It includes a custom health check for the Google API. -
AddServicesExtension
: This extension adds an HTTP client to the project.
The project uses rate limiting to limit the number of requests from a single IP address. The limit is set to 10 requests per 10 seconds. If the limit is exceeded, the API will return a 429 Too Many Requests status code.
The client has a chat interface where you can interact with the chat bot. The chat interface is rendered by the Chat
component. The Chat
component uses the useChat
hook to manage the state of the chat.
The useChat
hook uses the axios
library to send POST requests to the chat bot API. The responses from the API are stored in the messages
state variable. The messages
state variable is also stored in the session storage to persist the chat history across page reloads.
The Chat
component also uses the Loading
component to display a loading animation while waiting for the response from the API, and the DangerError
component to display any error messages.
Website: riannegreiros.dev
This project is licensed under the MIT License - see the LICENSE file for details