GroqChat4J Tailwind Templates

Groqchat4j

A chat application built with Spring Boot, Thymeleaf, HTMX, and Tailwind CSS that integrates with the Groq API using GroqClient4J.

GroqChat4J

A chat application built with Spring Boot, Thymeleaf, HTMX, and Tailwind CSS that integrates with the Groq API using GroqClient4J.

Features

  • Real-time chat interface using HTMX for seamless interactions
  • UI with Tailwind CSS
  • Integration with Groq LLM models for AI-powered responses

Technologies

  • Backend: Java 17, Spring Boot 3.2.x
  • Frontend: Thymeleaf, HTMX, Tailwind CSS
  • API Integration: GroqClient4J
  • Build Tool: Maven

Prerequisites

  • Java 17 or higher
  • Maven 3.8.x or higher
  • Groq API key

Getting Started

1. Clone the repository

git clone https://github.com/yourusername/GroqChat4J.git
cd GroqChat4J

2. Set up your Groq API key

Add your Groq API key as an environment variable:

# Linux/macOS
export GROQ_API_KEY=your_api_key_here

# Windows (Command Prompt)
set GROQ_API_KEY=your_api_key_here

# Windows (PowerShell)
$env:GROQ_API_KEY="your_api_key_here"

Alternatively, you can add it to application.properties (not recommended for production):

groq.api.key=your_api_key_here

3. Build the application

mvn clean install

4. Run the application

mvn spring-boot:run

The application will be available at http://localhost:8080

Project Structure

GroqChat4J/
├── src/
│   ├── main/
│   │   ├── java/
│   │   │   └── com/
│   │   │       └── gazapps/
│   │   │           └── groqchat4j/
│   │   │               ├── GroqChat4JApplication.java
│   │   │               ├── config/
│   │   │               │   └── AppConfig.java
│   │   │               ├── controller/
│   │   │               │   └── ChatController.java
│   │   │               ├── service/
│   │   │               │   └── ChatService.java
│   │   │               └── model/
│   │   │                   └── ChatMessage.java
│   │   └── resources/
│   │       ├── application.properties
│   │       ├── static/
│   │       │   └── css/
│   │       │       └── main.css
│   │       └── templates/
│   │           ├── index.html
│   │           ├── chat-response.html
│   │           └── chat-response-clear.html
│   └── test/
│       └── java/
│           └── com/
│               └── gazapps/
│                   └── groqchat4j/
│                       └── GroqChat4JApplicationTests.java
└── pom.xml

Configuration Options

You can customize the application by modifying the following properties in application.properties:

# Server configuration
server.port=8080

# Groq API configuration
groq.api.key=${GROQ_API_KEY}
groq.model=llama-3.2-70b

# Application settings
app.system.message=You are a helpful, friendly, and concise assistant.

Key Components

ChatController

Handles HTTP requests and manages the chat interface using Thymeleaf fragments and HTMX.

ChatService

Manages communication with the Groq API using GroqClient4J.

Templates

  • index.html: Main chat interface with HTMX for dynamic interactions
  • chat-response.html: Thymeleaf fragment for rendering chat messages
  • chat-response-clear.html: Thymeleaf fragment for clearing chat history

Extending the App

Adding Authentication

To add user authentication to the chat:

  1. Add Spring Security dependencies
  2. Implement user repository and service
  3. Configure security settings
  4. Create login/register templates

Storing Chat History

To persist chat history:

  1. Configure a database (H2, PostgreSQL, etc.)
  2. Create entity and repository classes
  3. Update service to store and retrieve conversations

Deployment

Building for Production

mvn clean package

This will create a deployable JAR file in the target directory.

Running in Production

java -jar target/GroqChat4J-0.0.1-SNAPSHOT.jar

Docker Deployment

# Build Docker image
docker build -t groqchat4j .

# Run Docker container
docker run -p 8080:8080 -e GROQ_API_KEY=your_api_key_here groqchat4j

License

MIT License

Acknowledgements


Created with ❤️ by Me

Top categories

Loading Svelte Themes