Skip to content

Commit

Permalink
✨ feat: 支持展示 token 使用量 (lobehub#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Jul 30, 2023
1 parent 43be8de commit e4d4dac
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/pages/chat/[id]/edit/AgentPrompt/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { CodeEditor, FormGroup } from '@lobehub/ui';
import { CodeEditor, FormGroup, TokenTag } from '@lobehub/ui';
import { createStyles } from 'antd-style';
import { Bot } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { shallow } from 'zustand/shallow';

import { FORM_STYLE } from '@/const/layoutTokens';
import { agentSelectors, useSessionStore } from '@/store/session';
import { ModelTokens } from '@/const/modelTokens';
import { agentSelectors, chatSelectors, useSessionStore } from '@/store/session';

export const useStyles = createStyles(({ css, token }) => ({
input: css`
Expand All @@ -24,12 +25,25 @@ export const useStyles = createStyles(({ css, token }) => ({
const AgentPrompt = memo(() => {
const { t } = useTranslation('setting');

const systemRole = useSessionStore(agentSelectors.currentAgentSystemRole, shallow);

const [updateAgentConfig] = useSessionStore((s) => [s.updateAgentConfig], shallow);
const [systemRole, model, systemTokenCount, updateAgentConfig] = useSessionStore(
(s) => [
agentSelectors.currentAgentSystemRole(s),
agentSelectors.currentAgentModel(s),
chatSelectors.systemRoleTokenCount(s),
s.updateAgentConfig,
],
shallow,
);

return (
<FormGroup icon={Bot} style={FORM_STYLE.style} title={t('settingAgent.prompt.title')}>
<FormGroup
extra={
<TokenTag displayMode={'used'} maxValue={ModelTokens[model]} value={systemTokenCount} />
}
icon={Bot}
style={FORM_STYLE.style}
title={t('settingAgent.prompt.title')}
>
<CodeEditor
language={'md'}
onValueChange={(e) => {
Expand Down

0 comments on commit e4d4dac

Please sign in to comment.