Skip to content

Commit e848d4f

Browse files
authored
fetch cleanup (#1337)
Random cleanup while in the neighborhood
1 parent ff98761 commit e848d4f

2 files changed

Lines changed: 20 additions & 33 deletions

File tree

src/platform/endpoint/node/responsesApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { Raw } from '@vscode/prompt-tsx';
77
import { ClientHttp2Stream } from 'http2';
8-
import { OpenAI } from 'openai';
8+
import type { OpenAI } from 'openai';
99
import { Response } from '../../../platform/networking/common/fetcherService';
1010
import { coalesce } from '../../../util/vs/base/common/arrays';
1111
import { AsyncIterableObject } from '../../../util/vs/base/common/async';

src/platform/openai/node/fetch.ts

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { IChatQuotaService } from '../../chat/common/chatQuotaService';
1313
import { ChatLocation } from '../../chat/common/commonTypes';
1414
import { IInteractionService } from '../../chat/common/interactionService';
1515
import { ICAPIClientService } from '../../endpoint/common/capiClient';
16-
import { IDomainService } from '../../endpoint/common/domainService';
17-
import { IEnvService } from '../../env/common/envService';
1816
import { ILogService } from '../../log/common/logService';
1917
import { FinishedCallback, OptionalChatRequestParams, RequestId, getProcessingTime, getRequestId } from '../../networking/common/fetch';
2018
import { FetcherId, IFetcherService, Response } from '../../networking/common/fetcherService';
@@ -113,13 +111,8 @@ export async function fetchAndStreamChat(
113111
): Promise<ChatResults | ChatRequestFailed | ChatRequestCanceled> {
114112
const logService = accessor.get(ILogService);
115113
const telemetryService = accessor.get(ITelemetryService);
116-
const fetcherService = accessor.get(IFetcherService);
117-
const envService = accessor.get(IEnvService);
118114
const chatQuotaService = accessor.get(IChatQuotaService);
119-
const domainService = accessor.get(IDomainService);
120-
const capiClientService = accessor.get(ICAPIClientService);
121115
const authenticationService = accessor.get(IAuthenticationService);
122-
const interactionService = accessor.get(IInteractionService);
123116
const instantiationService = accessor.get(IInstantiationService);
124117
if (cancel?.isCancellationRequested) {
125118
return { type: FetchResponseKind.Canceled, reason: 'before fetch request' };
@@ -146,24 +139,19 @@ export async function fetchAndStreamChat(
146139
// Generate unique ID to link input and output messages
147140
const modelCallId = generateUuid();
148141

149-
const response = await fetchWithInstrumentation(
150-
logService,
151-
telemetryService,
152-
fetcherService,
153-
envService,
154-
domainService,
155-
capiClientService,
156-
interactionService,
157-
chatEndpointInfo,
158-
ourRequestId,
159-
request,
160-
secretKey,
161-
location,
162-
userInitiatedRequest,
163-
cancel,
164-
{ ...telemetryProperties, modelCallId },
165-
useFetcher,
166-
);
142+
const response = await instantiationService.invokeFunction(accessor =>
143+
fetchWithInstrumentation(
144+
accessor,
145+
chatEndpointInfo,
146+
ourRequestId,
147+
request,
148+
secretKey,
149+
location,
150+
userInitiatedRequest,
151+
cancel,
152+
{ ...telemetryProperties, modelCallId },
153+
useFetcher,
154+
));
167155

168156
if (cancel?.isCancellationRequested) {
169157
const body = await response!.body();
@@ -463,13 +451,7 @@ async function handleError(
463451
}
464452

465453
async function fetchWithInstrumentation(
466-
logService: ILogService,
467-
telemetryService: ITelemetryService,
468-
fetcherService: IFetcherService,
469-
envService: IEnvService,
470-
domainService: IDomainService,
471-
capiClientService: ICAPIClientService,
472-
interactionService: IInteractionService,
454+
accessor: ServicesAccessor,
473455
chatEndpoint: IChatEndpoint,
474456
ourRequestId: string,
475457
request: IEndpointBody,
@@ -480,6 +462,11 @@ async function fetchWithInstrumentation(
480462
telemetryProperties?: TelemetryProperties,
481463
useFetcher?: FetcherId,
482464
): Promise<Response> {
465+
const logService = accessor.get(ILogService);
466+
const telemetryService = accessor.get(ITelemetryService);
467+
const fetcherService = accessor.get(IFetcherService);
468+
const capiClientService = accessor.get(ICAPIClientService);
469+
const interactionService = accessor.get(IInteractionService);
483470

484471
// If request contains an image, we include this header.
485472
const additionalHeaders: Record<string, string> = {

0 commit comments

Comments
 (0)