Skip to content

Commit e3d685a

Browse files
committed
Remove the specialized ChatGPT model provider support and relocate the providers constant to the editor package
- remove support for chatgpt - move PROVIDERS to `apps/editor/src/constants`
1 parent 68bcb15 commit e3d685a

21 files changed

Lines changed: 42 additions & 444 deletions

apps/editor/src/commands/apply-chat-response-command/response-processor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { apply_git_patch } from './handlers/diff-handler'
1717
import { apply_file_relocations } from './utils/file-operations'
1818
import { ModelProvidersManager } from '@/services/model-providers-manager'
1919
import { get_intelligent_update_config } from '@/utils/intelligent-update-utils'
20-
import { PROVIDERS } from '@shared/constants/providers'
20+
import { PROVIDERS } from '@/constants/providers'
2121
import { handle_active_editor_intelligent_update } from './handlers/active-editor-intelligent-update-handler'
2222
import { handle_fast_replace } from './handlers/fast-replace-handler'
2323
import { PanelProvider } from '@/views/panel/backend/panel-provider'

apps/editor/src/commands/code-at-cursor-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '../services/model-providers-manager'
1010
import { Logger } from '@shared/utils/logger'
1111
import he from 'he'
12-
import { PROVIDERS } from '@shared/constants/providers'
12+
import { PROVIDERS } from '@/constants/providers'
1313
import { RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY } from '@/constants/state-keys'
1414
import { ToolConfig } from '@/services/model-providers-manager'
1515
import { PanelProvider } from '@/views/panel/backend/panel-provider'

apps/editor/src/commands/generate-commit-message-command/utils/get-commit-message-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@/services/model-providers-manager'
77
import { dictionary } from '@shared/constants/dictionary'
88
import { Logger } from '@shared/utils/logger'
9-
import { PROVIDERS } from '@shared/constants/providers'
9+
import { PROVIDERS } from '@/constants/providers'
1010
import { display_token_count } from '@/utils/display-token-count'
1111
import { RECENTLY_USED_COMMIT_MESSAGES_CONFIG_IDS_STATE_KEY } from '@/constants/state-keys'
1212
import { t } from '@/i18n'

packages/shared/src/constants/providers.ts renamed to apps/editor/src/constants/providers.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ export const PROVIDERS = {
1111
Cerebras: {
1212
base_url: 'https://api.cerebras.ai/v1'
1313
},
14-
ChatGPT: {
15-
base_url: 'https://chatgpt.com/backend-api/codex'
16-
},
1714
Chutes: {
1815
base_url: 'https://llm.chutes.ai/v1'
1916
},

apps/editor/src/services/model-fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Logger } from '@shared/utils/logger'
2-
import { PROVIDERS } from '@shared/constants/providers'
2+
import { PROVIDERS } from '@/constants/providers'
33
import axios from 'axios'
44

55
export const MODELS_ROUTE_NOT_FOUND_ERROR = '/models route not found'

apps/editor/src/services/model-providers-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode'
2-
import { PROVIDERS } from '@shared/constants/providers'
2+
import { PROVIDERS } from '@/constants/providers'
33
import { SECRET_STORAGE_MODEL_PROVIDERS_KEY } from '@/constants/secret-storage-keys'
44

55
export type BuiltInProvider = {

apps/editor/src/utils/apply-reasoning-effort.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ export const apply_reasoning_effort = (params: {
2222
}
2323
}
2424
}
25-
} else if (params.provider.name == 'ChatGPT') {
26-
if (params.reasoning_effort) {
27-
params.body.reasoning_effort =
28-
params.reasoning_effort == 'extra high'
29-
? 'xhigh'
30-
: params.reasoning_effort
31-
}
3225
} else {
3326
if (params.reasoning_effort) {
3427
params.body.reasoning_effort = params.reasoning_effort

apps/editor/src/utils/make-api-request.ts

Lines changed: 4 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,7 @@ const process_stream_chunk = (
3333
if (!json_string || json_string == DONE_TOKEN) continue
3434

3535
const json_data = JSON.parse(json_string)
36-
let content = json_data.choices?.[0]?.delta?.content
37-
38-
// Special handling for ChatGPT provider
39-
if (content === undefined && json_data.type) {
40-
if (
41-
[
42-
'response.text.delta',
43-
'response.output_text.delta',
44-
'response.reasoning.delta',
45-
'response.reasoning_text.delta'
46-
].includes(json_data.type)
47-
) {
48-
content = json_data.delta
49-
} else if (json_data.type === 'response.content_part.added') {
50-
content =
51-
typeof json_data.part?.text === 'string'
52-
? json_data.part.text
53-
: json_data.part?.text?.value
54-
} else if (
55-
json_data.type === 'response.output_item.added' &&
56-
json_data.item?.type === 'text'
57-
) {
58-
content = json_data.item?.text
59-
}
60-
}
36+
const content = json_data.choices?.[0]?.delta?.content
6137

6238
if (typeof content == 'string') {
6339
new_content += content
@@ -139,75 +115,8 @@ export const make_api_request = async (params: {
139115
}
140116

141117
try {
142-
const is_chatgpt = params.endpoint_url.includes('chatgpt.com/backend-api')
143-
const request_url = is_chatgpt
144-
? params.endpoint_url + '/responses'
145-
: params.endpoint_url + '/chat/completions'
146-
147-
let request_body: any = { ...params.body, stream: true }
148-
149-
if (is_chatgpt) {
150-
const system_message = params.body.messages?.find(
151-
(m: any) => m.role === 'system'
152-
)
153-
const other_messages =
154-
params.body.messages?.filter((m: any) => m.role !== 'system') || []
155-
156-
const formatted_input = other_messages.map((m: any) => {
157-
if (m.role == 'user') {
158-
const content = []
159-
if (typeof m.content == 'string') {
160-
content.push({ type: 'input_text', text: m.content })
161-
} else if (Array.isArray(m.content)) {
162-
for (const block of m.content) {
163-
if (block.type == 'text') {
164-
content.push({ type: 'input_text', text: block.text })
165-
} else if (block.type == 'image_url') {
166-
content.push({
167-
type: 'input_image',
168-
image_url: block.image_url.url
169-
})
170-
}
171-
}
172-
}
173-
return { role: 'user', content }
174-
} else if (m.role == 'assistant') {
175-
const content = []
176-
if (typeof m.content == 'string') {
177-
content.push({ type: 'output_text', text: m.content })
178-
} else if (Array.isArray(m.content)) {
179-
for (const block of m.content) {
180-
if (block.type == 'text') {
181-
content.push({ type: 'output_text', text: block.text })
182-
}
183-
}
184-
}
185-
return { role: 'assistant', content }
186-
}
187-
return m
188-
})
189-
190-
request_body = {
191-
model: params.body.model,
192-
input: formatted_input,
193-
stream: true,
194-
store: false
195-
}
196-
if (system_message) {
197-
request_body.instructions = system_message.content
198-
} else {
199-
request_body.instructions = ''
200-
}
201-
if (params.body.temperature !== undefined) {
202-
request_body.temperature = params.body.temperature
203-
}
204-
if (params.body.reasoning_effort) {
205-
request_body.reasoning = {
206-
effort: params.body.reasoning_effort,
207-
summary: 'auto'
208-
}
209-
}
210-
}
118+
const request_url = params.endpoint_url + '/chat/completions'
119+
const request_body: any = { ...params.body, stream: true }
211120

212121
Logger.info({
213122
function_name: 'make_api_request',
@@ -339,10 +248,6 @@ export const make_api_request = async (params: {
339248
: {})
340249
}
341250

342-
if (is_chatgpt) {
343-
headers['originator'] = 'code-web-chat'
344-
}
345-
346251
const response: AxiosResponse<NodeJS.ReadableStream> = await axios.post(
347252
request_url,
348253
request_body,
@@ -388,31 +293,7 @@ export const make_api_request = async (params: {
388293
const json_string = trimmed_line.slice(DATA_PREFIX.length).trim()
389294
if (json_string && json_string !== DONE_TOKEN) {
390295
const json_data = JSON.parse(json_string)
391-
let content = json_data.choices?.[0]?.delta?.content
392-
393-
// Special handling for ChatGPT provider
394-
if (content === undefined && json_data.type) {
395-
if (
396-
[
397-
'response.text.delta',
398-
'response.output_text.delta',
399-
'response.reasoning.delta',
400-
'response.reasoning_text.delta'
401-
].includes(json_data.type)
402-
) {
403-
content = json_data.delta
404-
} else if (json_data.type === 'response.content_part.added') {
405-
content =
406-
typeof json_data.part?.text === 'string'
407-
? json_data.part.text
408-
: json_data.part?.text?.value
409-
} else if (
410-
json_data.type === 'response.output_item.added' &&
411-
json_data.item?.type === 'text'
412-
) {
413-
content = json_data.item?.text
414-
}
415-
}
296+
const content = json_data.choices?.[0]?.delta?.content
416297

417298
if (typeof content == 'string') {
418299
process_content(content)

apps/editor/src/views/panel/backend/message-handlers/handle-code-at-cursor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
get_tool_config_id
99
} from '@/services/model-providers-manager'
1010
import { Logger } from '@shared/utils/logger'
11-
import { PROVIDERS } from '@shared/constants/providers'
11+
import { PROVIDERS } from '@/constants/providers'
1212
import { RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY } from '@/constants/state-keys'
1313
import { PanelProvider } from '@/views/panel/backend/panel-provider'
1414
import { CodeAtCursorMessage } from '@/views/panel/types/messages'

apps/editor/src/views/panel/backend/message-handlers/handle-edit-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Provider
88
} from '@/services/model-providers-manager'
99
import axios from 'axios'
10-
import { PROVIDERS } from '@shared/constants/providers'
10+
import { PROVIDERS } from '@/constants/providers'
1111
import {
1212
API_EDIT_FORMAT_STATE_KEY,
1313
RECENTLY_USED_EDIT_CONTEXT_CONFIG_IDS_STATE_KEY

0 commit comments

Comments
 (0)