Path: blob/main/extensions/copilot/src/platform/chat/test/common/mockChatMLFetcher.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Event } from '../../../../util/vs/base/common/event';6import { IChatMLFetcher } from '../../common/chatMLFetcher';7import { ChatFetchResponseType, ChatResponse, ChatResponses } from '../../common/commonTypes';89export class MockChatMLFetcher implements IChatMLFetcher {10_serviceBrand: undefined;11onDidMakeChatMLRequest = Event.None;1213private _nextResponse: ChatResponse = {14type: ChatFetchResponseType.Success,15requestId: 'test-request-id',16serverRequestId: 'test-server-request-id',17usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0, prompt_tokens_details: { cached_tokens: 0 } },18value: '10',19resolvedModel: 'test-model'20};2122setNextResponse(response: ChatResponse): void {23this._nextResponse = response;24}2526async fetchOne(): Promise<ChatResponse> {27return this.fetchMany().then(responses => {28if (responses.type === ChatFetchResponseType.Success) {29return {30...responses,31value: responses.value[0]32};33}34return responses;35});36}3738async fetchMany(): Promise<ChatResponses> {39if (this._nextResponse.type === ChatFetchResponseType.Success) {40return {41...this._nextResponse,42value: [this._nextResponse.value]43};44}45return this._nextResponse;46}47}484950