-
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.
Merge pull request #53 from dev-jpnobrega/feature/addChatHistory
- adjust README
- Loading branch information
Showing
8 changed files
with
250 additions
and
70 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
|
||
import { IDatabaseConfig } from '../../interface/agent.interface'; | ||
import { BaseChatMessageHistory } from 'langchain/schema'; | ||
import { BaseChatMessageHistory, BaseMessage } from 'langchain/schema'; | ||
|
||
import RedisChatHistory from './redis-chat-history'; | ||
import { BufferMemory } from 'langchain/memory'; | ||
import MemoryChatHistory from './memory-chat-history'; | ||
|
||
interface IChatHistory { | ||
addUserMessage(message: string): Promise<void>; | ||
addAIChatMessage(message: string): Promise<void>; | ||
getMessages(): Promise<BaseMessage[]>; | ||
getFormatedMessages(messages: BaseMessage[]): string; | ||
clear(): Promise<void>; | ||
getChatHistory(): BaseChatMessageHistory; | ||
getBufferMemory(): BufferMemory; | ||
} | ||
|
||
const Services = { | ||
redis: RedisChatHistory, | ||
memory: MemoryChatHistory, | ||
} as any; | ||
|
||
class ChatHistoryFactory { | ||
public static async create(settings: IDatabaseConfig): Promise<BaseChatMessageHistory> { | ||
return await new Services[settings.type](settings).build(); | ||
public static async create(settings: IDatabaseConfig): Promise<IChatHistory> { | ||
const service = new Services[settings?.type](settings); | ||
|
||
if (!service) { | ||
return await new MemoryChatHistory(settings).build(); | ||
} | ||
|
||
return await service.build(); | ||
} | ||
} | ||
|
||
export default ChatHistoryFactory; | ||
export { | ||
IChatHistory, | ||
ChatHistoryFactory, | ||
}; |
Oops, something went wrong.