diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..cf4b8e9 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# Bot config +GEMINI_API_KEY= +ADDR=:8080 + +# Telegram client config +BOT_TOKEN= diff --git a/.gitignore b/.gitignore index 0df9dec..4e4dcd2 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ go.work.sum history-gemini/* !history-gemini/.gitkeep bot-context/* -!bot-context/.gitkeep \ No newline at end of file +!bot-context/.gitkeep diff --git a/README.md b/README.md index 50402da..6b1cfbc 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,10 @@ Required env variable(s): Optional env variable(s): - `ADDR` - Listen address for the server (Default: `:8080`) -- `GEMINI_MODEL` - Model to use (Default: `gemini-2.5-flash-preview-04-17`) +- `GEMINI_MODEL` - Model to use (Default: `gemini-2.5-flash`) - `MCP_SERVERS` - MCP HTTP stream server for external function calls (Eg.: `http://localhost:8081/sse`), this could be a comma separated list for multiple servers - `SEARCH_ENABLE` - Allow to use Google search for the AI service (Default: `false`, it won't work together with MCP servers) +- `HISTORY_SUMMARY` - After how many messages the history should be summarized (Default: `20`, `0` means no summary, both model and user messages counts) All the history will be stored under the `history-gemini` folder. @@ -83,6 +84,14 @@ If you have a user id, you can use it in the call. curl -v -H "X-User-ID: someuserid1" -X POST http://127.0.0.1:8080/message -d "message=Hi there" ``` +### Use docker + +There is a provided docker compose file. +First make a copy of the `.env.example` file and rename it to `.env` and set your Gemini api key, then you can run the following command to start the server: +``` +docker-compose up +``` + ### Client examples @@ -132,7 +141,6 @@ Optional env variables: - `GRAPHQL_URL` - GraphQL base url (Default: `https://graph.facebook.com/v22.0`) - `ADDR` - Server listening address (Default: `:8082`) - `AI_SERVICE` - AI service (the server-bot's) address (Default: `http://127.0.0.1:8080`) -- `HISTORY_SUMMARY` - After how many messages the history should be summarized (Default: `20`, `0` means no summary, both model and user messages counts) Then you can start chatting with the bot via sending a message to the page. (If you configured an MCP in the AI service it will be called too.) diff --git a/cmd/server-bot/main.go b/cmd/server-bot/main.go index 648429d..03e9362 100644 --- a/cmd/server-bot/main.go +++ b/cmd/server-bot/main.go @@ -24,7 +24,8 @@ import ( func main() { logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ - Level: slog.LevelDebug, // TODO: set to configurable level + // Level: slog.LevelDebug, // TODO: set to configurable level + Level: slog.LevelInfo, })) addr := os.Getenv("ADDR") diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0c74cb1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +# docker-compose.yml +version: '3.4' +services: + bot: + build: + context: . + dockerfile: docker/Dockerfile-bot + target: production + env_file: + - .env + ports: + - "8080:8080" + volumes: + - bot-data:/app + + client-telegram: + build: + context: . + dockerfile: docker/Dockerfile-client-telegram + target: production + environment: + AI_SERVICE: http://bot:8080 + env_file: + - .env + depends_on: + - bot + +volumes: + bot-data: \ No newline at end of file diff --git a/docker/Dockerfile-bot b/docker/Dockerfile-bot new file mode 100644 index 0000000..5983600 --- /dev/null +++ b/docker/Dockerfile-bot @@ -0,0 +1,16 @@ +FROM golang:1.25 AS build + +WORKDIR /go/src/app +COPY . . + +RUN go mod download +RUN CGO_ENABLED=0 go build -o /go/bin/server-bot -ldflags '-w -s' cmd/server-bot/main.go + + +FROM gcr.io/distroless/static as production +WORKDIR /app +COPY --from=build /go/bin/server-bot server-bot +COPY --from=build /go/src/app/history-gemini history-gemini +COPY --from=build /go/src/app/bot-context bot-context +COPY --from=build /go/src/app/personality.json personality.json +ENTRYPOINT ["./server-bot"] diff --git a/docker/Dockerfile-client-telegram b/docker/Dockerfile-client-telegram new file mode 100644 index 0000000..59dced4 --- /dev/null +++ b/docker/Dockerfile-client-telegram @@ -0,0 +1,12 @@ +FROM golang:1.25 AS build + +WORKDIR /go/src/app +COPY . . + +RUN go mod download +RUN CGO_ENABLED=0 go build -o /go/bin/client-telegram -ldflags '-w -s' cmd/client-telegram/main.go + + +FROM gcr.io/distroless/static as production +COPY --from=build /go/bin/client-telegram /client-telegram +ENTRYPOINT ["/client-telegram"]