-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
b2abd7e
commit d5a9a30
Showing
24 changed files
with
135 additions
and
184 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
...ion/webview-api/chat-context-processor/utils/convert-langchain-message-to-conversation.ts
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
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ChatContextType, type Conversation } from '@shared/types/chat-context' | ||
import type { SettingsContext } from '@shared/types/chat-context/settings-context' | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
import { BaseEntity, type IBaseEntity } from './base-entity' | ||
import { ChatSessionEntity, type ChatSession } from './chat-session-entity' | ||
|
||
export interface ChatContext extends IBaseEntity { | ||
type: ChatContextType | ||
createdAt: number | ||
updatedAt: number | ||
conversations: Conversation[] | ||
settings: SettingsContext | ||
} | ||
|
||
export class ChatContextEntity extends BaseEntity<ChatContext> { | ||
getDefaults(): ChatContext { | ||
const now = Date.now() | ||
return { | ||
id: uuidv4(), | ||
type: ChatContextType.Chat, | ||
createdAt: now, | ||
updatedAt: now, | ||
conversations: [], | ||
settings: { | ||
allowLongFileScan: false, | ||
explicitContext: '总是用中文回复', | ||
fastApplyModelName: 'gpt-4o-mini', | ||
modelName: 'gpt-4o', | ||
useFastApply: true | ||
} | ||
} | ||
} | ||
|
||
toChatSession(): ChatSession { | ||
const { entity } = this | ||
|
||
return new ChatSessionEntity({ | ||
id: entity.id, | ||
title: this.getTitleFromConversations(entity.conversations), | ||
type: entity.type, | ||
createdAt: entity.createdAt, | ||
updatedAt: entity.updatedAt | ||
}).entity | ||
} | ||
|
||
private getTitleFromConversations = ( | ||
conversations: Conversation[], | ||
defaultTitle = 'New Chat' | ||
) => { | ||
let firstHumanMessageText = '' | ||
|
||
conversations | ||
.filter(conversation => conversation.role === 'human') | ||
.forEach(conversation => | ||
conversation.contents.forEach(content => { | ||
if (content.type === 'text' && !firstHumanMessageText) { | ||
firstHumanMessageText = content.text | ||
} | ||
}) | ||
) | ||
|
||
return firstHumanMessageText || defaultTitle | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { MessageType } from '@langchain/core/messages' | ||
import type { PluginState } from '@shared/plugins/base/types' | ||
import type { LangchainMessageContents } from '@shared/types/chat-context/langchain-message' | ||
import { v4 as uuidv4 } from 'uuid' | ||
|
||
import { BaseEntity, type IBaseEntity } from './base-entity' | ||
|
||
export interface Conversation extends IBaseEntity { | ||
createdAt: number | ||
role: MessageType | ||
contents: LangchainMessageContents | ||
richText?: string | ||
pluginStates: Record<string, PluginState> | ||
} | ||
|
||
export class ConversationEntity extends BaseEntity<Conversation> { | ||
protected getDefaults(): Conversation { | ||
return { | ||
id: uuidv4(), | ||
createdAt: Date.now(), | ||
role: 'human', | ||
contents: [], | ||
pluginStates: {} | ||
} | ||
} | ||
} |
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,6 +1,8 @@ | ||
export * from './ai-model-entity' | ||
export * from './ai-provider-entity' | ||
export * from './base-entity' | ||
export * from './chat-context-entity' | ||
export * from './chat-session-entity' | ||
export * from './conversation-entity' | ||
export * from './doc-site-entity' | ||
export * from './settings-entity' |
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
Oops, something went wrong.