Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Jun 10, 2024
1 parent 7f0957f commit 3eafc96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('API tests', () => {
);
});

it('calls the non-stream API when assistantStreamingEnabled is true and actionTypeId is gemini and isEnabledKnowledgeBase is true', async () => {
it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is gemini and isEnabledKnowledgeBase is true', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
apiConfig: apiConfig.gemini,
Expand All @@ -145,13 +145,13 @@ describe('API tests', () => {
expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...staticDefaults,
body: '{"message":"This is a test","subAction":"invokeAI","conversationId":"test","actionTypeId":".gemini","replacements":{},"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}',
...streamingDefaults,
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".gemini","replacements":{},"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}',
}
);
});

it('calls the non-stream API when assistantStreamingEnabled is true and actionTypeId is gemini and isEnabledKnowledgeBase is false and isEnabledRAGAlerts is true', async () => {
it('calls the stream API when assistantStreamingEnabled is true and actionTypeId is gemini and isEnabledKnowledgeBase is false and isEnabledRAGAlerts is true', async () => {
const testProps: FetchConnectorExecuteAction = {
...fetchConnectorArgs,
apiConfig: apiConfig.gemini,
Expand All @@ -164,8 +164,8 @@ describe('API tests', () => {
expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
...staticDefaults,
body: '{"message":"This is a test","subAction":"invokeAI","conversationId":"test","actionTypeId":".gemini","replacements":{},"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true}',
...streamingDefaults,
body: '{"message":"This is a test","subAction":"invokeStream","conversationId":"test","actionTypeId":".gemini","replacements":{},"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true}',
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { mockActionResponse } from './mocks';
import { BaseMessage } from '@langchain/core/messages';
import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
import { parseBedrockStream } from '../utils/bedrock';
import { parseGeminiStream } from '../utils/gemini';

const connectorId = 'mock-connector-id';

Expand Down Expand Up @@ -94,6 +95,7 @@ const defaultArgs = {
streaming: false,
};
jest.mock('../utils/bedrock');
jest.mock('../utils/gemini');

describe('ActionsClientSimpleChatModel', () => {
beforeEach(() => {
Expand Down Expand Up @@ -216,6 +218,7 @@ describe('ActionsClientSimpleChatModel', () => {
describe('_call streaming: true', () => {
beforeEach(() => {
(parseBedrockStream as jest.Mock).mockResolvedValue(mockActionResponse.message);
(parseGeminiStream as jest.Mock).mockResolvedValue(mockActionResponse.message);
});
it('returns the expected content when _call is invoked with streaming and llmType is Bedrock', async () => {
const actionsClientSimpleChatModel = new ActionsClientSimpleChatModel({
Expand All @@ -238,7 +241,7 @@ describe('ActionsClientSimpleChatModel', () => {
it('returns the expected content when _call is invoked with streaming and llmType is Gemini', async () => {
const actionsClientSimpleChatModel = new ActionsClientSimpleChatModel({
...defaultArgs,
actions: mockActions,
actions: mockStreamActions,
llmType: 'gemini',
streaming: true,
});
Expand All @@ -248,8 +251,8 @@ describe('ActionsClientSimpleChatModel', () => {
callOptions,
callRunManager
);
const subAction = mockExecute.mock.calls[0][0].params.subAction;
expect(subAction).toEqual('invokeAI');
const subAction = mockStreamExecute.mock.calls[0][0].params.subAction;
expect(subAction).toEqual('invokeStream');

expect(result).toEqual(mockActionResponse.message);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export class ActionsClientSimpleChatModel extends SimpleChatModel {
return content; // per the contact of _call, return a string
}

// Bedrock streaming
const readable = get('data', actionResult) as Readable;

if (typeof readable?.read !== 'function') {
Expand Down

0 comments on commit 3eafc96

Please sign in to comment.