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

feat(backend): Backend config convention and pull model #54

Merged
merged 25 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7635a8a
feat(backend): backend config convention
NarwhalChen Oct 31, 2024
c6fde4a
feat: adding pull model function with test
NarwhalChen Nov 18, 2024
1deca3d
fix: adding default type
NarwhalChen Nov 28, 2024
e69b220
fix: fix the problem of prepare a unready config to other service
NarwhalChen Nov 28, 2024
618c20e
fix: File naming is more semantic
NarwhalChen Nov 30, 2024
f1382eb
Merge remote-tracking branch 'origin/main' into backend-config-conven…
NarwhalChen Dec 10, 2024
96a55d1
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 10, 2024
71b662d
fix: fixing bug in modeldowloader that cannot pull model
NarwhalChen Dec 10, 2024
a4f692d
fix: fixing bug in modeldowloader that cannot pull model
NarwhalChen Dec 10, 2024
458db40
Merge branch 'backend-config-convention' of https://github.com/Sma1lb…
NarwhalChen Dec 10, 2024
bf37046
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 10, 2024
5a6f4bf
to: makes model download when project start and download to local folder
NarwhalChen Dec 12, 2024
ed2e534
to: can load model both locally and remotely
NarwhalChen Dec 13, 2024
3ab6bc8
fix: fixing the layer structure of chatsconfig
NarwhalChen Dec 13, 2024
3fe86b4
fix: fixing the layer structure of chatsconfig and relative bug in Lo…
NarwhalChen Dec 13, 2024
a2c07a6
[autofix.ci] apply automated fixes
autofix-ci[bot] Dec 13, 2024
f97b97d
fix: fixing the layer structure of chatsconfig and relative bug in Lo…
NarwhalChen Dec 15, 2024
eb55281
Merge branch 'backend-config-convention' of https://github.com/Sma1lb…
NarwhalChen Dec 15, 2024
9c34f08
refactor: rename ConfigLoader and ModelLoader files, update imports, …
Sma1lboy Dec 15, 2024
ed07140
fix: updating layer structure of chatconfig and updating relative test
NarwhalChen Dec 15, 2024
8a311f0
Delete .editorconfig
Sma1lboy Dec 16, 2024
28d5f78
Delete pnpm-lock.yaml
Sma1lboy Dec 16, 2024
c1c8a98
Delete pnpm-lock.yaml
Sma1lboy Dec 16, 2024
3ea4222
Merge branch 'main' into backend-config-convention
Sma1lboy Dec 16, 2024
4e59695
Fix merge conflicts in pnpm-lock.yaml and update axios version to 1.7.8
Sma1lboy Dec 16, 2024
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
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions backend/__tests__/loadAllChatsModels.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ConfigService } from '../src/config/config.service';
import loadAllChatsModels from '../src/model/model.service';
import { getModel } from '../src/model/model.service';

const originalIsArray = Array.isArray;
Array.isArray = jest.fn((type: any): type is any[] => {
if (type && type.constructor && (type.constructor.name === 'Float32Array' || type.constructor.name === 'BigInt64Array')) {
return true;
}
return originalIsArray(type);
}) as unknown as (arg: any) => arg is any[];
;

jest.mock('../src/config/config.service', () => {
return {
ConfigService: jest.fn().mockImplementation(() => {
return {
get: jest.fn().mockReturnValue({
chat1: { model: 'Xenova/LaMini-Flan-T5-783M', task: 'text2text-generation' },
}),
};
}),
};
});

describe('loadAllChatsModels with real model loading', () => {
beforeAll(async () => {
await loadAllChatsModels();
});

it('should load real models specified in config', async () => {
expect(ConfigService).toHaveBeenCalled();
const chat1Model = getModel('chat1');

console.log(chat1Model);

expect(chat1Model).toBeDefined();
expect(chat1Model).toHaveProperty('model');
expect(chat1Model).toHaveProperty('tokenizer');
try {
const chat1Output = await chat1Model('Write me a love poem about cheese.', {
max_new_tokens: 200,
temperature: 0.9,
repetition_penalty: 2.0,
no_repeat_ngram_size: 3,
});
console.log('Model Output:', chat1Output);

expect(chat1Output).toBeDefined();

console.log(chat1Output[0].generated_text);
} catch (error) {
console.error('Error during model inference:', error);
}

}, 60000);
});

afterAll(() => {
Array.isArray = originalIsArray;
});
6 changes: 5 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"private": true,
"license": "UNLICENSED",
"packageManager": "[email protected]",
"type": "module",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
Expand All @@ -23,6 +24,8 @@
},
"dependencies": {
"@apollo/server": "^4.11.0",
"@huggingface/hub": "latest",
"@huggingface/transformers": "latest",
Comment on lines +29 to +30
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Pin Hugging Face dependencies to specific versions

Using "latest" for production dependencies is risky as it can lead to unexpected breaking changes. Consider pinning to specific versions.

- "@huggingface/hub": "latest",
- "@huggingface/transformers": "latest",
+ "@huggingface/hub": "^0.14.1",
+ "@huggingface/transformers": "^2.15.0",

Committable suggestion skipped: line range outside the PR's diff.

"@nestjs/apollo": "^12.2.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.3",
Expand All @@ -32,9 +35,11 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.2",
"@types/bcrypt": "^5.0.2",
"axios": "^1.7.7",
"bcrypt": "^5.1.1",
"class-validator": "^0.14.1",
"graphql": "^16.9.0",
"lodash": "^4.17.21",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"sqlite3": "^5.1.7",
Expand Down Expand Up @@ -69,7 +74,6 @@
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
Expand Down
Loading