Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: voice speech from Sber #79

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/api/gpt/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ export const MODEL_GPT_DEFAULT = { title: 'GPT-3.5 Turbo', model: 'gpt-3.5-turbo
export const MODEL_SPEECH_DEFAULT = { title: 'Whisper', model: 'whisper-1' };
export const MODEL_IMAGE_DEFAULT = { title: 'DALL·E 3', model: 'dall-e-3', max: 1 };

export const TITLE_NONE = 'None';

export enum TypeGPT {
AUDIO = 'audio',
IMAGE = 'image',
SPEECH = 'speech',
TEXT = 'text',
}

Expand Down
7 changes: 4 additions & 3 deletions src/api/gpt/gpt.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ChatCompletionResponse,
GenerateImagesResponse,
GptModelResponse,
TranscriptionResponse,
} from '@bot/api/gpt/types';
import { TTL_CONFIG_CACHE_DEFAULT } from '@bot/common/constants';
import { fetchCachedData } from '@bot/common/utils';
Expand Down Expand Up @@ -61,12 +62,12 @@ export const chatCompletion = async (
}
};

export const transcription = async (voicePathApi: string, telegramId: number, model: string) => {
export const transcription = async (filename: string, telegramId: number, model: string) => {
try {
const response = await axios<string>({
const response = await axios<TranscriptionResponse>({
method: 'post',
data: {
voicePathApi,
filename,
telegramId,
model,
},
Expand Down
2 changes: 2 additions & 0 deletions src/api/gpt/types/gpt.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type ChatCompletionResponse = {
};
};

export type TranscriptionResponse = { text: string };

export type GenerateImagesResponse = {
clientRate: ClientRate;
images: {
Expand Down
8 changes: 4 additions & 4 deletions src/common/constants/common.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export enum AuthActions {
GET_AUTH = 'get_auth_action',
}

export enum ClientImagesMenuActions {
GENERATE_IMAGE = 'generate-image-action',
}

export enum FeedbackActions {
DISLIKE = 'dislike-feedback-action',
DISLIKE_IMAGE = 'dislike-image-feedback-action',
LIKE = 'like-feedback-action',
LIKE_IMAGE = 'like-image-feedback-action',
}

export enum ClientImagesMenuActions {
GENERATE_IMAGE = 'generate-image-action',
}
2 changes: 1 addition & 1 deletion src/conversations/change-gpt-model.conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const changeGptModelConversation: ConversationType = async (conversation,
gptModels.push(model);
}

if (model.type === TypeGPT.SPEECH) {
if (model.type === TypeGPT.AUDIO) {
speechModels.push(model);
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/about/about.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const aboutModule = (bot: BotType) =>
.join('');

const profileMessageHtml = `${ctx.t('description-message-start', {
botName,
botName: `<b>${botName}</b>`,
})}\n\r${ctx.t('description-message-body')}\n\r\n\r<b>${ctx.t('about-gpt-model')}</b> ${
gpt.title
} (<code>${gpt.model}</code>)\n\r<b>${ctx.t('about-speech-model')}</b> ${speech.title} (<code>${
Expand Down
1 change: 0 additions & 1 deletion src/modules/text/text.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const textModule = (bot: BotType) => {
reply_to_message_id: messageId,
});
} catch (error) {
await ctx.deleteMessage();
await ctx.reply(ctx.t('error-message-common'));

Logger.error(
Expand Down
8 changes: 4 additions & 4 deletions src/modules/voice/voice.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ export const voiceModule = (bot: BotType) => {

const { speech: selectedSpeechModel } = ctx.session.client.selectedModel;

const voicePathApi = (await ctx.getFile()).file_path ?? '';
const filename = (await ctx.getFile()).file_path ?? '';

const clientTranscription = await transcription(
voicePathApi,
filename,
telegramId,
selectedSpeechModel.model,
);
Expand All @@ -40,7 +41,7 @@ export const voiceModule = (bot: BotType) => {
});
}

const gptContent = await getGptContent(ctx, clientTranscription);
const gptContent = await getGptContent(ctx, clientTranscription.text);

if (gptContent) {
return await startMessage.editText(gptContent, {
Expand All @@ -53,7 +54,6 @@ export const voiceModule = (bot: BotType) => {
reply_to_message_id: messageId,
});
} catch (error) {
await ctx.deleteMessage();
await ctx.reply(ctx.t('error-message-common'));

Logger.error(
Expand Down
11 changes: 2 additions & 9 deletions src/services/logger.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'winston-mongodb';

import { winstonConfig } from '@bot/common/constants';
import { getTimestampUnix } from '@bot/common/utils';
import { config } from '@bot/config';
import { ClientLoggerModel } from '@bot/models';
import { addColors, createLogger, format, Logger, transports } from 'winston';
Expand All @@ -28,20 +27,14 @@ class LoggerService {
filename: 'errors.log',
level: 'error',
format: format.printf(
(info) =>
`${getTimestampUnix(info.timestamp)} ${info.level.toLocaleUpperCase()}: ${
info.message
}`,
(info) => `${info.timestamp} ${info.level.toLocaleUpperCase()}: ${info.message}`,
),
}),
new transports.File({
filename: 'combined.log',
level: 'silly',
format: format.printf(
(info) =>
`${getTimestampUnix(info.timestamp)} ${info.level.toLocaleUpperCase()}: ${
info.message
}`,
(info) => `${info.timestamp} ${info.level.toLocaleUpperCase()}: ${info.message}`,
),
}),
],
Expand Down
Loading