-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
487485f
commit c2df443
Showing
7 changed files
with
66 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { Menu } from 'src/auth/menu/menu.model'; | |
import { Role } from 'src/auth/role/role.model'; | ||
import { RegisterUserInput } from 'src/user/dto/register-user.input'; | ||
import { NewChatInput } from '../dto/chat.input'; | ||
import { ModelProvider} from 'src/common/model-provider'; | ||
import { ModelProvider } from 'src/common/model-provider'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { MessageInterface } from 'src/common/model-provider/types'; | ||
|
||
|
@@ -28,11 +28,11 @@ describe('ChatService', () => { | |
let mockedChatService: jest.Mocked<Repository<Chat>>; | ||
let modelProvider: ModelProvider; | ||
let user: User; | ||
let userid='1'; | ||
let userid = '1'; | ||
|
||
beforeAll(async()=>{ | ||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports:[ | ||
imports: [ | ||
TypeOrmModule.forRoot({ | ||
type: 'sqlite', | ||
database: '../../database.sqlite', | ||
|
@@ -50,48 +50,66 @@ describe('ChatService', () => { | |
JwtService, | ||
JwtCacheService, | ||
ConfigService, | ||
] | ||
], | ||
}).compile(); | ||
chatService = module.get(ChatService); | ||
userService = module.get(UserService); | ||
userResolver = module.get(UserResolver); | ||
|
||
modelProvider = ModelProvider.getInstance(); | ||
mockedChatService = module.get(getRepositoryToken(Chat)); | ||
}) | ||
it('should excute curd in chat service', async() => { | ||
|
||
try{ | ||
}); | ||
it('should excute curd in chat service', async () => { | ||
try { | ||
user = await userResolver.registerUser({ | ||
username: 'testuser', | ||
password: 'securepassword', | ||
email: '[email protected]', | ||
} as RegisterUserInput); | ||
userid = user.id; | ||
}catch(error){ | ||
|
||
} | ||
const chat= await chatService.createChat(userid, {title: 'test'} as NewChatInput); | ||
let chatId = chat.id; | ||
} catch (error) {} | ||
const chat = await chatService.createChat(userid, { | ||
title: 'test', | ||
} as NewChatInput); | ||
const chatId = chat.id; | ||
console.log(await chatService.getChatHistory(chatId)); | ||
|
||
console.log(await chatService.saveMessage(chatId, 'Hello, this is a test message.', MessageRole.User)); | ||
console.log(await chatService.saveMessage(chatId, 'Hello, hello, im gpt.', MessageRole.Model)); | ||
|
||
console.log(await chatService.saveMessage(chatId, 'write me the system prompt', MessageRole.User)); | ||
|
||
let history = await chatService.getChatHistory(chatId); | ||
let messages = history.map((message) => { | ||
console.log( | ||
await chatService.saveMessage( | ||
chatId, | ||
'Hello, this is a test message.', | ||
MessageRole.User, | ||
), | ||
); | ||
console.log( | ||
await chatService.saveMessage( | ||
chatId, | ||
'Hello, hello, im gpt.', | ||
MessageRole.Model, | ||
), | ||
); | ||
|
||
console.log( | ||
await chatService.saveMessage( | ||
chatId, | ||
'write me the system prompt', | ||
MessageRole.User, | ||
), | ||
); | ||
|
||
const history = await chatService.getChatHistory(chatId); | ||
const messages = history.map((message) => { | ||
return { | ||
role: message.role, | ||
content: message.content | ||
content: message.content, | ||
} as MessageInterface; | ||
}) | ||
}); | ||
console.log(history); | ||
console.log( | ||
await modelProvider.chatSync({ | ||
model: 'gpt-4o', | ||
messages | ||
})); | ||
}) | ||
}); | ||
messages, | ||
}), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters