Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/chat/test/common/mockChatMLFetcher.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Event } from '../../../../util/vs/base/common/event';
7
import { IChatMLFetcher } from '../../common/chatMLFetcher';
8
import { ChatFetchResponseType, ChatResponse, ChatResponses } from '../../common/commonTypes';
9
10
export class MockChatMLFetcher implements IChatMLFetcher {
11
_serviceBrand: undefined;
12
onDidMakeChatMLRequest = Event.None;
13
14
private _nextResponse: ChatResponse = {
15
type: ChatFetchResponseType.Success,
16
requestId: 'test-request-id',
17
serverRequestId: 'test-server-request-id',
18
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0, prompt_tokens_details: { cached_tokens: 0 } },
19
value: '10',
20
resolvedModel: 'test-model'
21
};
22
23
setNextResponse(response: ChatResponse): void {
24
this._nextResponse = response;
25
}
26
27
async fetchOne(): Promise<ChatResponse> {
28
return this.fetchMany().then(responses => {
29
if (responses.type === ChatFetchResponseType.Success) {
30
return {
31
...responses,
32
value: responses.value[0]
33
};
34
}
35
return responses;
36
});
37
}
38
39
async fetchMany(): Promise<ChatResponses> {
40
if (this._nextResponse.type === ChatFetchResponseType.Success) {
41
return {
42
...this._nextResponse,
43
value: [this._nextResponse.value]
44
};
45
}
46
return this._nextResponse;
47
}
48
}
49
50