Skip to content

Commit fb0c8ce

Browse files
committed
Separate token count tracking for edit and ask instructions and remove unused format instruction metrics
- provide to `apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx` also other types of token counts - remove passing 'edit format instructions' token count └── apps └── editor └── src ├── constants │ └── edit-format-instructions.ts └── views └── prompt ├── backend │ ├── message-handlers │ │ ├── handle-autofill.ts │ │ └── index.ts │ ├── prompt-view-provider.ts │ └── utils │ └── symbols │ ├── clipboard-paths │ │ └── replace-clipboard-paths-symbol.ts │ ├── fragment │ │ └── replace-fragment-symbol.ts │ ├── git │ │ └── replace-git-symbols.ts │ ├── image │ │ └── replace-image-symbol.ts │ ├── pasted-text │ │ └── replace-pasted-text-symbol.ts │ ├── replace-symbols.ts │ ├── saved-context │ │ └── replace-saved-context-symbol.ts │ ├── selection │ │ └── replace-selection-symbol.ts │ ├── skill │ │ └── replace-skill-symbol.ts │ └── website │ └── replace-website-symbol.ts ├── frontend │ ├── Main │ │ ├── Main.tsx │ │ └── MainView │ │ └── MainView.tsx │ ├── Prompt.tsx │ └── hooks │ └── use-prompt │ └── use-prompt.ts └── types └── messages.ts
1 parent 9786e84 commit fb0c8ce

6 files changed

Lines changed: 20 additions & 23 deletions

File tree

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ import { webview_html } from '@/views/shared/utils/webview-html'
114114
import { get_selected_files } from '@/context/helpers/get-selected-files'
115115
import { normalize_path } from '@/utils/normalize-path'
116116
import { replace_symbols } from './utils/symbols/replace-symbols'
117-
import {
118-
EDIT_FORMAT_INSTRUCTIONS_WHOLE,
119-
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
120-
EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE,
121-
EDIT_FORMAT_INSTRUCTIONS_DIFF
122-
} from '@/constants/edit-format-instructions'
123117

124118
export class PromptViewProvider implements vscode.WebviewViewProvider {
125119
public readonly extension_uri: vscode.Uri
@@ -554,17 +548,6 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
554548
remove_images: true
555549
})
556550

557-
let formatted_system_instructions = ''
558-
const edit_format_instructions = {
559-
whole: EDIT_FORMAT_INSTRUCTIONS_WHOLE,
560-
truncated: EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
561-
'search-replace': EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE,
562-
diff: EDIT_FORMAT_INSTRUCTIONS_DIFF
563-
}[this.edit_format]
564-
if (edit_format_instructions) {
565-
formatted_system_instructions = `# Output formatting\n\n${edit_format_instructions}`
566-
}
567-
568551
this.send_message({
569552
command: 'TOKEN_COUNT_UPDATED',
570553
selected_files_token_count: this.current_selected_files_token_count,
@@ -577,9 +560,6 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
577560
(ask_instructions_result.instruction.length +
578561
ask_instructions_result.skill_definitions.length) /
579562
4
580-
),
581-
edit_format_instructions_token_count: Math.ceil(
582-
formatted_system_instructions.length / 4
583563
)
584564
})
585565
}

‎apps/editor/src/views/prompt/frontend/Main/Main.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ type Props = {
6969
missing_web_configuration?: boolean
7070
voice_input_push_to_talk: boolean
7171
selected_files_token_count: number
72+
edit_instructions_token_count: number
73+
ask_instructions_token_count: number
7274
bottom_spacer_height?: number
7375
}
7476

@@ -488,6 +490,8 @@ export const Main: React.FC<Props> = (props) => {
488490
current_selection={props.current_selection}
489491
chat_history={current_history || []}
490492
selected_files_token_count={props.selected_files_token_count}
493+
edit_instructions_token_count={props.edit_instructions_token_count}
494+
ask_instructions_token_count={props.ask_instructions_token_count}
491495
web_prompt_type={props.web_prompt_type}
492496
api_prompt_type={props.api_prompt_type}
493497
on_web_prompt_type_change={props.on_web_prompt_type_change}

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type Props = {
5252
current_selection?: SelectionState | null
5353
chat_history: string[]
5454
selected_files_token_count: number
55+
edit_instructions_token_count: number
56+
ask_instructions_token_count: number
5557
web_prompt_type: WebPromptType
5658
api_prompt_type: ApiPromptType
5759
on_web_prompt_type_change: (prompt_type: WebPromptType) => void

‎apps/editor/src/views/prompt/frontend/Prompt.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ export const Prompt = () => {
7373
handle_tabs_reorder,
7474
voice_input_push_to_talk,
7575
is_modern_ui,
76-
selected_files_token_count
76+
selected_files_token_count,
77+
edit_instructions_token_count,
78+
ask_instructions_token_count
7779
} = use_panel(vscode)
7880

7981
const {
@@ -350,6 +352,8 @@ export const Prompt = () => {
350352
on_tabs_reorder={handle_tabs_reorder}
351353
voice_input_push_to_talk={voice_input_push_to_talk}
352354
selected_files_token_count={selected_files_token_count}
355+
edit_instructions_token_count={edit_instructions_token_count}
356+
ask_instructions_token_count={ask_instructions_token_count}
353357
/>
354358
</div>
355359
<div

‎apps/editor/src/views/prompt/frontend/hooks/use-prompt/use-prompt.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ export const use_prompt = (vscode: any) => {
2727
useState(0)
2828
const [selected_files_token_count, set_selected_files_token_count] =
2929
useState<number>(0)
30+
const [edit_instructions_token_count, set_edit_instructions_token_count] =
31+
useState<number>(0)
32+
const [ask_instructions_token_count, set_ask_instructions_token_count] =
33+
useState<number>(0)
3034

3135
const {
3236
ask_about_context_instructions,
@@ -121,6 +125,8 @@ export const use_prompt = (vscode: any) => {
121125
set_voice_input_push_to_talk(message.enabled)
122126
} else if (message.command == 'TOKEN_COUNT_UPDATED') {
123127
set_selected_files_token_count(message.selected_files_token_count)
128+
set_edit_instructions_token_count(message.edit_instructions_token_count)
129+
set_ask_instructions_token_count(message.ask_instructions_token_count)
124130
} else if (message.command == 'IS_MODERN_UI') {
125131
set_is_modern_ui(message.is_modern_ui)
126132
}
@@ -237,6 +243,8 @@ export const use_prompt = (vscode: any) => {
237243
handle_tabs_reorder,
238244
voice_input_push_to_talk,
239245
is_modern_ui,
240-
selected_files_token_count
246+
selected_files_token_count,
247+
edit_instructions_token_count,
248+
ask_instructions_token_count
241249
}
242250
}

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ export interface TokenCountMessage extends BaseMessage {
663663
selected_files_token_count: number
664664
edit_instructions_token_count: number
665665
ask_instructions_token_count: number
666-
edit_format_instructions_token_count: number
667666
}
668667

669668
export interface WebConfigurationUpdatedMessage extends BaseMessage {

0 commit comments

Comments
 (0)