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

Ci build and test #4

Merged
merged 3 commits into from
May 29, 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
5 changes: 0 additions & 5 deletions .eslintrc.js

This file was deleted.

36 changes: 36 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Unit Testing

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use Node v20
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: "yarn"

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Lint
run: yarn lint

- name: Unit Tests
run: yarn test
3 changes: 1 addition & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"dev:prod": "cross-env NODE_ENV=production nodemon",
"build": "swc src -d dist --source-maps --copy-files",
"build:tsc": "tsc && tsc-alias",
"test": "jest --forceExit --detectOpenHandles",
"lint": "eslint --ignore-path .gitignore --ext .ts src",
"lint:fix": "npm run lint -- --fix",
"deploy:prod": "npm run build && pm2 start ecosystem.config.js --only prod",
Expand Down Expand Up @@ -83,4 +82,4 @@
"tsconfig-paths": "^4.0.0",
"typescript": "^4.7.4"
}
}
}
1 change: 0 additions & 1 deletion apps/backend/src/dtos/submission.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ export class SubmitDto {
@IsNotEmpty()
public captcha: string;
}

2 changes: 1 addition & 1 deletion apps/backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { App } from '@/app';
import { ValidateEnv } from '@utils/validateEnv';
import { initializeOpenAI } from './utils/initializeOpenAI';
import { SubmissionRoute } from './routes/submission.route';
import { SubmissionRoute } from './routes/submission.route';

ValidateEnv();

Expand Down
36 changes: 12 additions & 24 deletions apps/backend/src/services/helpers/openai.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OPENAI_API_KEY } from "@/config";
import OpenAI from "openai";
import { ChatCompletion } from "openai/resources";
import { OPENAI_API_KEY } from '@/config';
import OpenAI from 'openai';
import { ChatCompletion } from 'openai/resources';

export class OpenAIHelper {
private openai: OpenAI;
Expand All @@ -19,28 +19,20 @@ export class OpenAIHelper {
dangerouslyAllowBrowser: true, // TODO: Check if this is necessary
});

public askChatGPTAboutImage = async ({
base64Image,
maxTokens = 350,
prompt,
}: {
base64Image: string;
prompt: string;
maxTokens?: number;
}) =>
public askChatGPTAboutImage = async ({ base64Image, maxTokens = 350, prompt }: { base64Image: string; prompt: string; maxTokens?: number }) =>
this.openai.chat.completions.create({
model: "gpt-4-vision-preview",
model: 'gpt-4-vision-preview',
max_tokens: maxTokens,
messages: [
{
role: "user",
role: 'user',
content: [
{
type: "text",
type: 'text',
text: prompt,
},
{
type: "image_url",
type: 'image_url',
image_url: {
url: base64Image,
},
Expand All @@ -50,15 +42,11 @@ export class OpenAIHelper {
],
});

public getResponseJSONString = (response: ChatCompletion) =>
response.choices[0].message.content;
public getResponseJSONString = (response: ChatCompletion) => response.choices[0].message.content;

private cleanChatGPTJSONString = (jsonString: string) =>
jsonString.replace("```json", "").replace("```", "");
private cleanChatGPTJSONString = (jsonString: string) => jsonString.replace('```json', '').replace('```', '');

public parseChatGPTJSONString = <Response>(
jsonString?: string | null
): Response | undefined => {
public parseChatGPTJSONString = <Response>(jsonString?: string | null): Response | undefined => {
if (!jsonString) {
return;
}
Expand All @@ -68,7 +56,7 @@ export class OpenAIHelper {
const parsed = JSON.parse(content);
return parsed;
} catch (e) {
console.error("Failing parsing Chat GPT response:", e);
console.error('Failing parsing Chat GPT response:', e);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/utils/const/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./abi";
export * from "./network";
export * from './abi';
export * from './network';
2 changes: 1 addition & 1 deletion apps/backend/src/utils/initializeOpenAI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenAIHelper } from "@/services/helpers";
import { OpenAIHelper } from '@/services/helpers';

export const initializeOpenAI = () => {
return new OpenAIHelper();
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "vite --port 8082 --host",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "yarn lint --fix",
"preview": "vite preview"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"lint:fix": "turbo lint:fix",
"test": "turbo test",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"contracts:deploy:solo": "turbo run deploy:solo",
Expand Down
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
]
},
"lint": {},
"lint:fix": {},
"dev": {
"cache": false,
"persistent": true
Expand Down
Loading