Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions packages/ai-native/src/browser/chat/chat-proxy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ export class ChatProxyService extends Disposable {
} else {
apiKey = this.preferenceService.get<string>(AINativeSettingSectionsId.AnthropicApiKey, '');
}

const MAX_INPUT_TOKENS = 30720;
const stream = await this.aiBackService.requestStream(
prompt,
{
requestId: request.requestId,
sessionId: request.sessionId,
history: this.aiChatService.getHistoryMessages(),
history: this.aiChatService.getHistoryMessages(MAX_INPUT_TOKENS),
clientId: this.applicationService.clientId,
apiKey,
model,
Expand Down
4 changes: 2 additions & 2 deletions packages/ai-native/src/browser/chat/chat.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class ChatService extends Disposable {
this._onChatMessageListLaunch.fire(list);
}

public getHistoryMessages(): IHistoryChatMessage[] {
return this.chatInternalService.sessionModel?.history.getMessages() || [];
public getHistoryMessages(maxInputTokens = 128000): IHistoryChatMessage[] {
return this.chatInternalService.sessionModel?.history.getMessages(maxInputTokens) || [];
Comment thread
ensorrow marked this conversation as resolved.
}

public scrollToBottom(): void {
Expand Down
9 changes: 9 additions & 0 deletions packages/ai-native/src/browser/chat/chat.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,12 @@
}
}
}

.chat_tips_container {
display: flex;
align-items: center;
justify-content: center;
color: var(--tab-inactiveForeground);
font-size: 12px;
margin-top: 16px;
}
7 changes: 7 additions & 0 deletions packages/ai-native/src/browser/chat/chat.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,13 @@ export const AIChatView = () => {
dataSource={messageListData}
/>
</div>
{msgHistoryManager.slicedMessageCount ? (
<div className={styles.chat_tips_text}>
<div className={styles.chat_tips_container}>
{`${msgHistoryManager.slicedMessageCount} ${localize('aiNative.chat.ai.assistant.limit.message')}`}
</div>
</div>
) : null}
<div className={styles.chat_input_wrap}>
<ChatContext />
<div className={styles.header_operate}>
Expand Down
22 changes: 21 additions & 1 deletion packages/ai-native/src/browser/model/msg-history-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,30 @@ export class MsgHistoryManager extends Disposable {
return id;
}

public getMessages(): IHistoryChatMessage[] {
private get messageList(): IHistoryChatMessage[] {
return Array.from(this.messageMap.values()).sort((a, b) => a.order - b.order);
}

private startIndex = 0;

Comment thread
ensorrow marked this conversation as resolved.
private get totalTokens(): number {
const list = this.messageList.slice(this.startIndex);
return list.reduce((acc, msg) => acc + (msg.content.length || 0), 0) / 3;
}

public get slicedMessageCount(): number {
return this.startIndex;
}

public getMessages(maxTokens?: number): IHistoryChatMessage[] {
if (maxTokens && this.totalTokens > maxTokens) {
while (this.totalTokens > maxTokens) {
this.startIndex++;
}
}
return this.messageList.slice(this.startIndex);
}
Comment thread
ensorrow marked this conversation as resolved.

public addUserMessage(
message: Required<Pick<IExcludeMessage, 'agentId' | 'agentCommand' | 'content' | 'relationId'>>,
): string {
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/common/en-US.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ export const localizationBundle = {
'aiNative.operate.clear.title': 'Clear',

'aiNative.chat.welcome.loading.text': 'Initializing...',
'aiNative.chat.ai.assistant.limit.message': 'earlest messages are dropped due to the input token limit',
Comment thread
ensorrow marked this conversation as resolved.
Outdated
Comment thread
ensorrow marked this conversation as resolved.
Outdated

'preference.ai.native.inlineChat.title': 'Inline Chat',
'preference.ai.native.chat.title': 'Chat',
Expand Down
1 change: 1 addition & 0 deletions packages/i18n/src/common/zh-CN.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,7 @@ export const localizationBundle = {
'aiNative.operate.clear.title': '清空',

'aiNative.chat.welcome.loading.text': '初始化中...',
'aiNative.chat.ai.assistant.limit.message': '条最早的消息因输入 Tokens 限制而被丢弃',
Comment thread
Ricbet marked this conversation as resolved.
Outdated

'preference.ai.native.inlineChat.title': 'Inline Chat',
'preference.ai.native.chat.title': 'Chat',
Expand Down