Skip to content

Commit 28d26ee

Browse files
committed
Merge branch 'feat/openai' of github.com:codex-team/hawk.api.nodejs into stage
2 parents e0bf8be + 58a335e commit 28d26ee

File tree

19 files changed

+248
-39
lines changed

19 files changed

+248
-39
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.16.0
1+
v22.12.0

docker/Dockerfile.dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16-alpine as builder
1+
FROM node:22-alpine as builder
22

33
WORKDIR /usr/src/app
44
RUN apk add --no-cache git gcc g++ python3 make musl-dev
@@ -7,7 +7,7 @@ COPY package.json yarn.lock ./
77

88
RUN yarn install
99

10-
FROM node:16-alpine
10+
FROM node:22-alpine
1111

1212
WORKDIR /usr/src/app
1313

docker/Dockerfile.prod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16-alpine as builder
1+
FROM node:22-alpine as builder
22

33
WORKDIR /usr/src/app
44
RUN apk add --no-cache git gcc g++ python3 make musl-dev
@@ -11,7 +11,7 @@ COPY . .
1111

1212
RUN yarn build
1313

14-
FROM node:16-alpine
14+
FROM node:22-alpine
1515

1616
WORKDIR /usr/src/app
1717

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.2.20",
3+
"version": "1.2.23",
44
"main": "index.ts",
55
"license": "BUSL-1.1",
66
"scripts": {
@@ -33,6 +33,7 @@
3333
"typescript": "^4.7.4"
3434
},
3535
"dependencies": {
36+
"@ai-sdk/openai": "^2.0.64",
3637
"@amplitude/node": "^1.10.0",
3738
"@graphql-tools/merge": "^8.3.1",
3839
"@graphql-tools/schema": "^8.5.1",
@@ -52,9 +53,9 @@
5253
"@types/mongodb": "^3.6.20",
5354
"@types/morgan": "^1.9.10",
5455
"@types/node": "^16.11.46",
55-
"@types/node-fetch": "^2.5.4",
5656
"@types/safe-regex": "^1.1.6",
5757
"@types/uuid": "^8.3.4",
58+
"ai": "^5.0.89",
5859
"amqp-connection-manager": "^3.1.0",
5960
"amqplib": "^0.5.5",
6061
"apollo-server-express": "^3.10.0",
@@ -85,6 +86,7 @@
8586
"redis": "^4.7.0",
8687
"safe-regex": "^2.1.0",
8788
"ts-node-dev": "^2.0.0",
88-
"uuid": "^8.3.2"
89+
"uuid": "^8.3.2",
90+
"zod": "^3.25.76"
8991
}
9092
}

src/billing/cloudpayments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default class CloudPaymentsWebhooks {
202202
return;
203203
}
204204

205-
telegram.sendMessage(` [Billing / Check] All checks passed successfully «${workspace.name}»`, TelegramBotURLs.Money)
205+
telegram.sendMessage(`🤗 [Billing / Check] All checks passed successfully «${workspace.name}»`, TelegramBotURLs.Money)
206206
.catch(e => console.error('Error while sending message to Telegram: ' + e));
207207

208208
HawkCatcher.send(new Error('[Billing / Check] All checks passed successfully'), body as any);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { EventAddons, EventData } from '@hawk.so/types';
2+
import { generateText } from 'ai';
3+
import { openai } from '@ai-sdk/openai';
4+
import { eventSolvingInput } from './inputs/eventSolving';
5+
import { ctoInstruction } from './instructions/cto';
6+
7+
/**
8+
* Interface for interacting with Vercel AI Gateway
9+
*/
10+
class VercelAIApi {
11+
/**
12+
* Model ID to use for generating suggestions
13+
*/
14+
private readonly modelId: string;
15+
16+
constructor() {
17+
/**
18+
* @todo make it dynamic, get from project settings
19+
*/
20+
this.modelId = 'gpt-4o';
21+
}
22+
23+
/**
24+
* Generate AI suggestion for the event
25+
*
26+
* @param {EventData<EventAddons>} payload - event data
27+
* @returns {Promise<string>} AI suggestion for the event
28+
* @todo add defence against invalid prompt injection
29+
*/
30+
public async generateSuggestion(payload: EventData<EventAddons>) {
31+
const { text } = await generateText({
32+
model: openai(this.modelId),
33+
system: ctoInstruction,
34+
prompt: eventSolvingInput(payload),
35+
});
36+
37+
return text;
38+
}
39+
}
40+
41+
export const vercelAIApi = new VercelAIApi();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { EventData, EventAddons } from '@hawk.so/types';
2+
3+
export const eventSolvingInput = (payload: EventData<EventAddons>) => `
4+
Payload: ${JSON.stringify(payload)}
5+
`;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const ctoInstruction = `Ты технический директор ИТ компании, тебе нужно пояснить ошибку и предложить решение.
2+
3+
Предоставь ответ в следующем формате:
4+
5+
1. Описание проблемы
6+
2. Решение проблемы
7+
3. Описание того, как можно предотвратить подобную ошибку в будущем
8+
9+
Ответь на русском языке.`;

src/models/eventsFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ class EventsFactory extends Factory {
688688
/**
689689
* If originalEventId equals repetitionId than user wants to get first repetition which is original event
690690
*/
691-
if (repetitionId === originalEventId) {
691+
if (repetitionId.toString() === originalEventId.toString()) {
692692
const originalEvent = await this.eventsDataLoader.load(originalEventId);
693693

694694
/**

src/resolvers/billingNew.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default {
156156
* Send info to Telegram (non-blocking)
157157
*/
158158
telegram
159-
.sendMessage(` [Billing / Compose payment]
159+
.sendMessage(`👀 [Billing / Compose payment]
160160
161161
card link operation: ${isCardLinkOperation}
162162
amount: ${+plan.monthlyCharge} RUB

0 commit comments

Comments
 (0)