Skip to content
Open
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
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { SalesModule } from './modules/sales/sales.module';
import { SigninModule } from './modules/signin/signin.module';
import { MenuModule } from './modules/menu/menu.module';
import { ModelsModule } from './modules/models/models.module';
import { ParseModule } from './modules/parse/parse.module';

@Global()
@Module({
Expand Down Expand Up @@ -75,6 +76,7 @@ import { ModelsModule } from './modules/models/models.module';
SigninModule,
MenuModule,
ModelsModule,
ParseModule,
],
providers: [
{
Expand Down
7 changes: 5 additions & 2 deletions service/src/modules/chatgpt/chatgpt.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { ChatBoxTypeEntity } from './chatBoxType.entity';
import { ChatBoxEntity } from './chatBox.entity';
import { ChatPreTypeEntity } from './chatPreType.entity';
import { ChatPreEntity } from './chatPre.entity';
import { ParseEntity } from '../parse/parse.entity';

@Global()
@Module({
imports: [
Expand All @@ -50,11 +52,12 @@ import { ChatPreEntity } from './chatPre.entity';
ChatBoxTypeEntity,
ChatBoxEntity,
ChatPreTypeEntity,
ChatPreEntity
ChatPreEntity,
ParseEntity,
]),
],
controllers: [ChatgptController],
providers: [ChatgptService, UserBalanceService, UserService, VerificationService, ChatLogService, RedisCacheService],
exports: [ChatgptService]
exports: [ChatgptService],
})
export class ChatgptModule {}
13 changes: 12 additions & 1 deletion service/src/modules/chatgpt/chatgpt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ChatPreTypeEntity } from './chatPreType.entity';
import { sendMessageFromKimi } from './kimi';
import { drawImageFromGlm, sendMessageFromGlm } from './glm';
import { parse } from './parse';
import { ParseEntity } from '../parse/parse.entity';

interface Key {
id: number;
Expand Down Expand Up @@ -75,6 +76,8 @@ export class ChatgptService implements OnModuleInit {
private readonly chatPreTypeEntity: Repository<ChatPreTypeEntity>,
@InjectRepository(ChatPreEntity)
private readonly chatPreEntity: Repository<ChatPreEntity>,
@InjectRepository(ParseEntity)
private readonly parseRepository: Repository<ParseEntity>,
private readonly configService: ConfigService,
private readonly userBalanceService: UserBalanceService,
private readonly chatLogService: ChatLogService,
Expand Down Expand Up @@ -1056,14 +1059,22 @@ export class ChatgptService implements OnModuleInit {
async contentParse(body: any, req: Request) {
await this.userService.checkUserStatus(req.user);
const money = 10;
await this.userBalanceService.validateBalance(req, 'model3Count', money);
await this.userBalanceService.validateBalance(req, 'model3', money);
/* 从glm的卡池随机拿一个key */
const detailKeyInfo = await this.modelsService.getGlmKey();
const keyId = detailKeyInfo?.id;
const { key, proxyResUrl } = await this.formatModelToken(detailKeyInfo);
console.log('keyId: ', keyId, proxyResUrl, key);
const res = await parse(body.messagesHistory, { key, proxyResUrl, keyId });
await this.userBalanceService.deductFromBalance(req.user.id, 'model3', 10, money);
// todo 存入数据库
const { model } = detailKeyInfo;
await this.parseRepository.save({
userId: req.user.id,
model,
messages: JSON.stringify(body.messagesHistory),
result: JSON.stringify(res),
});
return res;
}
}
20 changes: 20 additions & 0 deletions service/src/modules/parse/parse.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ParseController } from './parse.controller';
import { ParseService } from './parse.service';

describe('ParseController', () => {
let controller: ParseController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ParseController],
providers: [ParseService],
}).compile();

controller = module.get<ParseController>(ParseController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
7 changes: 7 additions & 0 deletions service/src/modules/parse/parse.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Controller } from '@nestjs/common';
import { ParseService } from './parse.service';

@Controller('parse')
export class ParseController {
constructor(private readonly parseService: ParseService) {}
}
25 changes: 25 additions & 0 deletions service/src/modules/parse/parse.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseEntity, Column, Entity, PrimaryColumn } from 'typeorm';

@Entity({ name: 'parse_log' })
export class ParseEntity extends BaseEntity {
@Column({ unique: true, comment: '解析ID', nullable: true })
id: number;

@Column({ comment: '请求消息', nullable: true })
messages: string;

@Column({ comment: '解析结果' })
result: string;

@Column({ comment: '模型', nullable: true })
model: string;

@Column({ comment: '用户ID', nullable: true })
userId: number;

@Column({ comment: '创建时间' })
createdAt: Date;

@Column({ comment: '更新时间' })
updatedAt: Date;
}
9 changes: 9 additions & 0 deletions service/src/modules/parse/parse.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ParseService } from './parse.service';
import { ParseController } from './parse.controller';

@Module({
controllers: [ParseController],
providers: [ParseService]
})
export class ParseModule {}
18 changes: 18 additions & 0 deletions service/src/modules/parse/parse.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ParseService } from './parse.service';

describe('ParseService', () => {
let service: ParseService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [ParseService],
}).compile();

service = module.get<ParseService>(ParseService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
9 changes: 9 additions & 0 deletions service/src/modules/parse/parse.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ParseEntity } from './parse.entity';

@Injectable()
export class ParseService {
constructor() {}
}
138 changes: 69 additions & 69 deletions service/src/modules/user/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
import { Check, Column, Entity, JoinColumn, OneToMany, OneToOne } from 'typeorm';
import { BaseEntity } from 'src/common/entity/baseEntity';
@Entity({ name: 'users' })
export class UserEntity extends BaseEntity {
@Column({ length: 12, comment: '用户昵称' })
username: string;
@Column({ length: 64, comment: '用户密码', nullable: true })
password: string;
@Column({ default: 0, comment: '用户状态' })
status: number;
@Column({ default: 1, comment: '用户性别' })
sex: number;
@Column({ length: 64, unique: true, comment: '用户邮箱' })
email: string;
@Column({ length: 64, nullable: true, comment: '用户手机号' })
phone: string;
@Column({
length: 300,
nullable: true,
default: 'https://public-1300678944.cos.ap-shanghai.myqcloud.com/ai/7f042f63f.png',
comment: '用户头像',
})
avatar: string;
@Column({
length: 300,
nullable: true,
default: '我是一台基于深度学习和自然语言处理技术的 AI 机器人,旨在为用户提供高效、精准、个性化的智能服务。',
comment: '用户签名',
})
sign: string;
@Column({ length: 64, default: '', comment: '注册IP', nullable: true })
registerIp: string;
@Column({ length: 64, default: '', comment: '最后一次登录IP', nullable: true })
lastLoginIp: string;
@Column({ length: 10, default: '', comment: '用户邀请码' })
inviteCode: string;
@Column({ length: 10, default: '', comment: '用户填写的别人的邀请码' })
invitedBy: string;
@Column({ length: 10, default: 'viewer', comment: '用户角色' })
role: string;
@Column({ length: 64, default: '', comment: '微信openId', nullable: true })
openId: string;
@Column({ length: 64, comment: '用户注册来源', nullable: true })
client: string;
@Column({ comment: '用户邀请链接被点击次数', default: 0 })
inviteLinkCount: number;
@Column({ comment: '用户连续签到天数', default: 0 })
consecutiveDays: number;
@Column({ comment: '用户违规记录次数', default: 0 })
violationCount: number;
}
import { Check, Column, Entity, JoinColumn, OneToMany, OneToOne } from 'typeorm';
import { BaseEntity } from 'src/common/entity/baseEntity';

@Entity({ name: 'users' })
export class UserEntity extends BaseEntity {
@Column({ length: 12, comment: '用户昵称' })
username: string;

@Column({ length: 64, comment: '用户密码', nullable: true })
password: string;

@Column({ default: 0, comment: '用户状态' })
status: number;

@Column({ default: 1, comment: '用户性别' })
sex: number;

@Column({ length: 64, unique: true, comment: '用户邮箱' })
email: string;

@Column({ length: 64, nullable: true, comment: '用户手机号' })
phone: string;

@Column({
length: 300,
nullable: true,
default: 'https://public-1300678944.cos.ap-shanghai.myqcloud.com/ai/7f042f63f.png',
comment: '用户头像',
})
avatar: string;

@Column({
length: 300,
nullable: true,
default: '我是一台基于深度学习和自然语言处理技术的 AI 机器人,旨在为用户提供高效、精准、个性化的智能服务。',
comment: '用户签名',
})
sign: string;

@Column({ length: 64, default: '', comment: '注册IP', nullable: true })
registerIp: string;

@Column({ length: 64, default: '', comment: '最后一次登录IP', nullable: true })
lastLoginIp: string;

@Column({ length: 10, default: '', comment: '用户邀请码' })
inviteCode: string;

@Column({ length: 10, default: '', comment: '用户填写的别人的邀请码' })
invitedBy: string;

@Column({ length: 10, default: 'viewer', comment: '用户角色' })
role: string;

@Column({ length: 64, default: '', comment: '微信openId', nullable: true })
openId: string;

@Column({ length: 64, comment: '用户注册来源', nullable: true })
client: string;

@Column({ comment: '用户邀请链接被点击次数', default: 0 })
inviteLinkCount: number;

@Column({ comment: '用户连续签到天数', default: 0 })
consecutiveDays: number;

@Column({ comment: '用户违规记录次数', default: 0 })
violationCount: number;
}