Skip to content
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

Switch Docker 🐳 to non-root #7

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ FROM golang:1.21.5 as builder
WORKDIR /app

# Copy the go.mod and go.sum to download all dependencies.
COPY go.mod ./
COPY go.sum ./
COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed.
RUN go mod download
Expand All @@ -27,10 +26,15 @@ FROM alpine:latest
# Install ca-certificates in case the application makes HTTPS requests.
RUN apk --no-cache add ca-certificates

WORKDIR /root/
# Create a non-root user and switch to it.
RUN adduser -D gogenaiterminal
USER gogenaiterminal

# Set the working directory to the user's home directory.
WORKDIR /home/gogenaiterminal

# Copy the pre-built binary file from the previous stage.
COPY --from=builder /app/cmd/ .
COPY --from=builder /app/cmd/ /usr/local/bin/

# Run the binary.
ENTRYPOINT ["./goaiterminal-chat"]
ENTRYPOINT ["gogenaiterminal-chat"]
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,37 @@ Interesting to built it in terminal after touring journey through the Go program
- **Session Chat History**: Maintain a transcript of your dialogue, capturing both queries and AI responses for a continuous conversational flow.
- **Intelligent Shutdown**: Benefit from built-in signal handling for a smooth exit process, ensuring your session ends without disruption and with proper resource cleanup.
- **Realistic Typing Animation**: Enjoy a more lifelike interaction with a simulated typing effect that mimics human conversation timing.
- **Ease of Deployment**: Quickly deploy the chat application using Docker, minimizing setup time and complexity.

> [!NOTE]
> Subject to add more in future without any complex of each functions.
> Subject planning to continuously improve and add features, enhancing functionality without adding unnecessary complexity. Stay tuned for updates!

**`Go`** is designed to be straightforward and efficient, avoiding the unnecessary complexities (fuck complexities, this is `go` anti complexities) often encountered in other programming languages.

## Installation

To use GoGenAI Terminal Chat, you need to have Docker installed on your machine. If you don't have Docker installed, please follow the [official Docker installation guide](https://docs.docker.com/get-docker/).

Once Docker is set up, you can pull the image from GitHub Packages by running:

```sh
docker pull ghcr.io/h0llyw00dzz/gogenai-terminal-chat:latest
```

## Usage

To start a chat session with GoGenAI, run the following command in your terminal. Make sure to replace `YOUR_API_KEY` with the actual API key provided to you.

```sh
docker run -it --rm --name mychatapp -e API_KEY=YOUR_API_KEY ghcr.io/h0llyw00dzz/gogenai-terminal-chat:latest
```

This command will start the GoGenAI Terminal Chat application in interactive mode. You will be able to type your messages and receive responses from the AI.

### Environment Variables

- `API_KEY`: Your API key for accessing the generative AI model. This is a required environment variable.


## Example how it wok

Expand Down
3 changes: 3 additions & 0 deletions terminal/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (s *Session) Start() {
userInput = strings.TrimSpace(userInput)
s.ChatHistory.AddMessage(YouNerd, userInput)

// Add a newline right after the user's input
fmt.Println()

// Pass the entire chat history as context for the AI's response
chatContext := s.ChatHistory.GetHistory()
aiResponse, err := SendMessage(s.Ctx, s.Client, chatContext)
Expand Down