Compare commits
2 commits
0b8391a7e0
...
f4592fff96
Author | SHA1 | Date | |
---|---|---|---|
f4592fff96 | |||
63e9986384 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -66,3 +66,4 @@ TEST-results.xml
|
||||||
messages.json
|
messages.json
|
||||||
dist/
|
dist/
|
||||||
.env
|
.env
|
||||||
|
persist/
|
||||||
|
|
25
Dockerfile
Normal file
25
Dockerfile
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
FROM node:20.12.2-alpine
|
||||||
|
|
||||||
|
RUN apk update > /dev/null && apk add git > /dev/null
|
||||||
|
|
||||||
|
RUN git clone https://git.povario.com/powermaker450/Tailchat-Assistant app > /dev/null
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
RUN npm i && npm run build
|
||||||
|
|
||||||
|
ENV HOST="http://localhost:11000"
|
||||||
|
ENV ID=""
|
||||||
|
ENV SECRET=""
|
||||||
|
ENV API_ENDPOINT="http://localhost:8080/v1"
|
||||||
|
ENV API_KEY="none"
|
||||||
|
ENV TEXT_MODEL="gpt-4"
|
||||||
|
ENV CREATE_IMAGE_MODEL="stablediffusion-cpp"
|
||||||
|
ENV ANALYZE_IMAGE_MODEL="gpt-4-vision-preview"
|
||||||
|
ENV TEMPERATURE=1
|
||||||
|
ENV ALLOWED_CHAT=""
|
||||||
|
ENV SAFE_WORD="\\"
|
||||||
|
|
||||||
|
COPY ./entrypoint.sh ./entrypoint.sh
|
||||||
|
RUN chmod +x ./entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["sh", "-c", "./entrypoint.sh"]
|
20
docker-compose.yml
Normal file
20
docker-compose.yml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
services:
|
||||||
|
assistant:
|
||||||
|
container_name: tailchat_assistant
|
||||||
|
image: tailchat_assistant
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
env_file: ".env"
|
||||||
|
environment:
|
||||||
|
- HOST=${HOST}
|
||||||
|
- ID=${ID}
|
||||||
|
- SECRET=${SECRET}
|
||||||
|
- API_ENDPOINT=${API_ENDPOINT}
|
||||||
|
- API_KEY=${API_KEY}
|
||||||
|
- TEXT_MODEL=${TEXT_MODEL}
|
||||||
|
- CREATE_IMAGE_MODEL=${CREATE_IMAGE_MODEL}
|
||||||
|
- ANALYZE_IMAGE_MODEL=${ANALYZE_IMAGE_MODEL}
|
||||||
|
- ALLOWED_CHAT=${ALLOWED_CHAT}
|
||||||
|
- SAFE_WORD=${SAFE_WORD}
|
||||||
|
volumes:
|
||||||
|
- ./persist:/app/persist
|
16
entrypoint.sh
Normal file
16
entrypoint.sh
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
cd /app
|
||||||
|
|
||||||
|
echo "" > .env && \
|
||||||
|
echo "HOST=$HOST" >> .env && \
|
||||||
|
echo "ID=$ID" >> .env && \
|
||||||
|
echo "SECRET=$SECRET" >> .env && \
|
||||||
|
echo "API_ENDPOINT=$API_ENDPOINT" >> .env && \
|
||||||
|
echo "API_KEY=$API_KEY" >> .env && \
|
||||||
|
echo "TEXT_MODEL=$TEXT_MODEL" >> .env && \
|
||||||
|
echo "CREATE_IMAGE_MODEL=$CREATE_IMAGE_MODEL" >> .env && \
|
||||||
|
echo "ANALYZE_IMAGE_MODEL=$ANALYZE_IMAGE_MODEL" >> .env && \
|
||||||
|
echo "TEMPERATURE=$TEMPERATURE" >> .env && \
|
||||||
|
echo "ALLOWED_CHAT=$ALLOWED_CHAT" >> .env && \
|
||||||
|
echo "SAFE_WORD=$SAFE_WORD" >> .env
|
||||||
|
|
||||||
|
npm run start
|
12
src/bot.ts
12
src/bot.ts
|
@ -38,7 +38,7 @@ if (!allVarsFilled) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the initial system message for the LLM.
|
// Define the initial system message for the LLM.
|
||||||
const session = new GuildData(checkFile("./messages.json", "utf-8"));
|
const session = new GuildData(checkFile("messages.json", "utf-8"));
|
||||||
|
|
||||||
session.data.toString()
|
session.data.toString()
|
||||||
? console.log("Our conversation is:", session.data)
|
? console.log("Our conversation is:", session.data)
|
||||||
|
@ -146,7 +146,7 @@ client.connect().then(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
"./messages.json",
|
"messages.json",
|
||||||
JSON.stringify(session.data),
|
JSON.stringify(session.data),
|
||||||
"utf8",
|
"utf8",
|
||||||
);
|
);
|
||||||
|
@ -181,7 +181,7 @@ client.connect().then(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
"./messages.json",
|
"messages.json",
|
||||||
JSON.stringify(session.data),
|
JSON.stringify(session.data),
|
||||||
"utf8",
|
"utf8",
|
||||||
);
|
);
|
||||||
|
@ -223,11 +223,7 @@ client.connect().then(async () => {
|
||||||
content: `[md]${contentOf(response)}[/md]`,
|
content: `[md]${contentOf(response)}[/md]`,
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync("messages.json", JSON.stringify(session.data), "utf8");
|
||||||
"./messages.json",
|
|
||||||
JSON.stringify(session.data),
|
|
||||||
"utf8",
|
|
||||||
);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Failed", err);
|
console.log("Failed", err);
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,7 @@ import {
|
||||||
ChatCompletionSystemMessageParam,
|
ChatCompletionSystemMessageParam,
|
||||||
} from "openai/resources";
|
} from "openai/resources";
|
||||||
import { TailchatWsClient } from "tailchat-client-sdk";
|
import { TailchatWsClient } from "tailchat-client-sdk";
|
||||||
import { ChatMessage } from "tailchat-types";
|
import { formatNewHistory } from "./utils";
|
||||||
import { formatNewHistory, formatUserMessage, getUsername } from "./utils";
|
|
||||||
import { HOST } from "./bot";
|
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
|
||||||
export interface ImageMessage {
|
export interface ImageMessage {
|
||||||
|
|
52
src/utils.ts
52
src/utils.ts
|
@ -1,7 +1,6 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import {
|
import {
|
||||||
AnyChatCompletion,
|
AnyChatCompletion,
|
||||||
AnyChatCompletionRole,
|
|
||||||
ChatHistory,
|
ChatHistory,
|
||||||
ChatHistoryData,
|
ChatHistoryData,
|
||||||
ImageMessage,
|
ImageMessage,
|
||||||
|
@ -9,61 +8,22 @@ import {
|
||||||
import { system } from "./assistant";
|
import { system } from "./assistant";
|
||||||
import { ChatCompletion, ChatCompletionMessage } from "openai/resources";
|
import { ChatCompletion, ChatCompletionMessage } from "openai/resources";
|
||||||
import { stripMentionTag } from "tailchat-client-sdk";
|
import { stripMentionTag } from "tailchat-client-sdk";
|
||||||
import { ChatMessage } from "tailchat-types";
|
|
||||||
import { HOST } from "./bot";
|
|
||||||
import chalk from "chalk";
|
|
||||||
|
|
||||||
//export function checkFile(
|
|
||||||
// file: string,
|
|
||||||
// encoding: fs.EncodingOption,
|
|
||||||
// defaultContent: string,
|
|
||||||
//): Messages {
|
|
||||||
// let final: Messages;
|
|
||||||
// const generic: Messages = [
|
|
||||||
// {
|
|
||||||
// role: "system",
|
|
||||||
// content: defaultContent,
|
|
||||||
// },
|
|
||||||
// ];
|
|
||||||
//
|
|
||||||
// if (fs.existsSync(file)) {
|
|
||||||
// const data = fs.readFileSync(file, encoding);
|
|
||||||
//
|
|
||||||
// final = !data.toString().trim() ? generic : JSON.parse(data.toString());
|
|
||||||
// } else {
|
|
||||||
// fs.createWriteStream(file);
|
|
||||||
// final = generic;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return final;
|
|
||||||
//}
|
|
||||||
|
|
||||||
export function checkFile(
|
export function checkFile(
|
||||||
file: string,
|
file: string,
|
||||||
encoding: fs.EncodingOption,
|
encoding: fs.EncodingOption,
|
||||||
): ChatHistory {
|
): ChatHistory {
|
||||||
|
const dirname = "./persist/";
|
||||||
|
const fullPath = dirname + file;
|
||||||
let final: ChatHistory;
|
let final: ChatHistory;
|
||||||
|
|
||||||
if (fs.existsSync(file)) {
|
if (fs.existsSync(fullPath)) {
|
||||||
const data = fs.readFileSync(file, encoding);
|
const data = fs.readFileSync(fullPath, encoding);
|
||||||
|
|
||||||
final = !data.toString().trim() ? [] : JSON.parse(data.toString());
|
final = !data.toString().trim() ? [] : JSON.parse(data.toString());
|
||||||
|
|
||||||
try {
|
|
||||||
// @ts-ignore
|
|
||||||
if (final.at(0).role) {
|
|
||||||
console.warn(
|
|
||||||
chalk.yellow(
|
|
||||||
"Your persistent storage uses the old data structure for persistent messages. These messages will be moved to a backup file and the existing file will be overwritten.",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
fs.writeFileSync(`${file}.bak`, data);
|
|
||||||
|
|
||||||
final = [];
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
} else {
|
} else {
|
||||||
fs.createWriteStream(file);
|
fs.mkdirSync(dirname);
|
||||||
|
fs.createWriteStream(fullPath);
|
||||||
final = [];
|
final = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue