diff --git a/Dockerfile b/Dockerfile index 5df9774..e08a0d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,3 +9,6 @@ RUN npm install COPY /src /app/src ENV NODE_PATH=./node_modules + +ENV HELLO_FILE=hello.txt +ENV ALLOWED_FILE=allowed.list diff --git a/README.md b/README.md index 585e9c3..9a578e5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ### Simple Telegram bot for ChatGPT OpenAi API -`tgbot-chatgpt` https://git.rozenlab.com/leo/tgbot-chatgpt +`tgbot-chatgpt` #### Запустить контейнер: @@ -20,6 +20,19 @@ #### Сервисные команды: -Запустить с указанием `APP_INSTANCE`: `APP_INSTANCE=4o docker compose up` -Пересоздать образ: `APP_INSTANCE=4o docker compose up --build --force-recreate` +Останавливает и удаляет контейнеры, сети, тома и образы: `APP_INSTANCE=4o docker compose down -v` + +Пересоздать образ: +`APP_INSTANCE=4o docker compose -p 4o up --build --force-recreate` +`APP_INSTANCE=in docker compose -p in up --build --force-recreate` + Открыть консоль запущенного контейнера `docker exec -it tgbot-chatgpt-4o /bin/sh` + + +остановить контейнеры: + +`docker stop tgbot-chatgpt-4o` +`docker stop tgbot-chatgpt-in` + + + diff --git a/docker-compose.yml b/docker-compose.yml index 8be6f05..2cd3ef0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - app_node_modules:/app/node_modules - /data/secrets/${SERVER_DOMAIN}/tgbot-chatgpt/${APP_INSTANCE}/allowed.list:/app/allowed.list:ro command: npm run start - restart: always + restart: unless-stopped volumes: node_modules: app_node_modules: \ No newline at end of file diff --git a/logos/gpt-o1-raw.jpg b/logos/gpt-o1-raw.jpg new file mode 100755 index 0000000..52b567c Binary files /dev/null and b/logos/gpt-o1-raw.jpg differ diff --git a/logos/gpt-o1.jpg b/logos/gpt-o1.jpg new file mode 100755 index 0000000..f40d534 Binary files /dev/null and b/logos/gpt-o1.jpg differ diff --git a/logo-open-ai.png b/logos/gpt35-raw.png similarity index 100% rename from logo-open-ai.png rename to logos/gpt35-raw.png diff --git a/logos/gpt4-raw.png b/logos/gpt4-raw.png new file mode 100755 index 0000000..0d02f04 Binary files /dev/null and b/logos/gpt4-raw.png differ diff --git a/logos/gpt4.png b/logos/gpt4.png new file mode 100755 index 0000000..6251bdd Binary files /dev/null and b/logos/gpt4.png differ diff --git a/run/35.sh b/run/35.sh new file mode 100644 index 0000000..6b8373f --- /dev/null +++ b/run/35.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +APP_INSTANCE=35 docker compose -p 35 -f ../docker-compose.yml up -d diff --git a/run/4o.sh b/run/4o.sh new file mode 100644 index 0000000..468f855 --- /dev/null +++ b/run/4o.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +APP_INSTANCE=4o docker compose -p 4o -f ../docker-compose.yml up -d diff --git a/run/in.sh b/run/in.sh new file mode 100644 index 0000000..6a5171d --- /dev/null +++ b/run/in.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +APP_INSTANCE=in docker compose -p in -f ../docker-compose.yml up -d \ No newline at end of file diff --git a/src/index.js b/src/index.js index 0a175f6..99ea750 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,8 @@ import OpenAI from 'openai'; import { promises as fs } from 'fs'; import { SocksProxyAgent } from 'socks-proxy-agent'; +const isInstruct = process.env.API_INSTRUCT === 'true'; + const proxyEnable = process.env.PROXY_ENABLE; let proxyConfig = {}; @@ -12,6 +14,9 @@ const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); const timeout = parseInt(process.env.TIMEOUT, 10); let allowedUsers = []; +console.log("GPT_MODEL: " + process.env.GPT_MODEL); +console.log("API_INSTRUCT: " + process.env.API_INSTRUCT); + if(proxyEnable === 'true') { const proxyHost = process.env.PROXY_HOST; const proxyPort = process.env.PROXY_PORT; @@ -34,7 +39,10 @@ bot.command('start', initCommand); async function chatGPT(content) { try { const chatCompletion = await openai.chat.completions.create({ - messages: [{ role: 'user', content }], + messages: [ + { role: 'system', content: 'Ответ пиши без markdown.' }, + { role: 'user', content } + ], model: process.env.GPT_MODEL, }, proxyConfig); return chatCompletion.choices[0].message.content; @@ -43,11 +51,31 @@ async function chatGPT(content) { } } +async function chatGPTinstruct(content) { + try { + const chatCompletion = await openai.completions.create({ + model: process.env.GPT_MODEL, + prompt: content, + max_tokens: 3000 + }, proxyConfig); + return chatCompletion.choices[0].text; + } catch (e) { + console.log('Error while gpt chat', e.message); + } +} + bot.on(message('text'), async (ctx) => { if (await auth(ctx.message.from.id)) { try { await ctx.reply(code('🕰️⏰🕙⏱️⏳...')); - const responce = await chatGPT(ctx.message.text); + + let responce; + if(isInstruct) { + responce = await chatGPTinstruct(ctx.message.text); + } else { + responce = await chatGPT(ctx.message.text); + } + if(responce) { await ctx.reply(responce); } else {