Skip to content

Commit

Permalink
fix: resolved issue with missing env keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianmusial committed Mar 14, 2024
1 parent 2adfe86 commit 9a0ca44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions libs/ai-assistant/src/lib/ai/ai.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AiController } from './ai.controller';
import { AiService } from './ai.service';
import { mockFileData, transcriptionMock } from './ai.mock';
import { mockBuffer, mockFileData, transcriptionMock } from './ai.mock';
import { Response } from 'openai/core';

describe('AiController', () => {
let aiController: AiController;
Expand All @@ -13,6 +14,10 @@ describe('AiController', () => {
jest
.spyOn(aiService.provider.audio.transcriptions, 'create')
.mockResolvedValue(transcriptionMock);

jest.spyOn(aiService.provider.audio.speech, 'create').mockResolvedValue({
arrayBuffer: jest.fn().mockResolvedValue(mockBuffer),
} as unknown as Response);
});

afterEach(() => {
Expand All @@ -27,10 +32,6 @@ describe('AiController', () => {
});

it('should throw an error', async () => {
jest
.spyOn(aiService.provider.audio.transcriptions, 'create')
.mockRejectedValue(new Error());

try {
await aiController.postTranscription(mockFileData);
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion libs/ai-assistant/src/lib/ai/ai.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'dotenv/config';

@Injectable()
export class AiService {
provider = new OpenAI();
provider = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'] || '',
});

async transcription(file: Uploadable): Promise<AiTranscription> {
return this.provider.audio.transcriptions.create({
Expand Down
1 change: 0 additions & 1 deletion libs/ai-assistant/src/lib/run/run.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,5 @@ describe('RunService', () => {

afterEach(() => {
jest.clearAllMocks();
runService.isRunning = true;
});
});

0 comments on commit 9a0ca44

Please sign in to comment.