Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
n3d1117 committed Mar 11, 2023
1 parent cf1ceba commit 905f587
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions openai_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ def get_chat_response(self, chat_id: int, query: str) -> str:

if len(response.choices) > 1 and self.config['n_choices'] > 1:
for index, choice in enumerate(response.choices):
content = choice['message']['content'].strip()
if index == 0:
self.__add_to_history(chat_id, role="assistant", content=choice['message']['content'])
self.__add_to_history(chat_id, role="assistant", content=content)
answer += f'{index+1}\u20e3\n'
answer += choice['message']['content']
answer += content
answer += '\n\n'
else:
answer = response.choices[0]['message']['content']
answer = response.choices[0]['message']['content'].strip()
self.__add_to_history(chat_id, role="assistant", content=answer)

if self.config['show_usage']:
Expand Down
13 changes: 6 additions & 7 deletions telegram_bot.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import logging
import os

import telegram.constants as constants
from telegram import constants
from telegram import Update, InlineQueryResultArticle, InputTextMessageContent, BotCommand
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, filters, InlineQueryHandler, \
Application
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler, \
filters, InlineQueryHandler, Application

from openai_helper import OpenAIHelper
from pydub import AudioSegment
from openai_helper import OpenAIHelper


class ChatGPT3TelegramBot:
Expand Down Expand Up @@ -40,7 +40,7 @@ async def help(self, update: Update, context: ContextTypes.DEFAULT_TYPE) -> None
'\n\n' + \
'\n'.join(commands) + \
'\n\n' + \
'Send me a voice message or audio file and I\'ll transcribe it for you!' + \
'Send me a voice message or file and I\'ll transcribe it for you!' + \
'\n\n' + \
"Open source at https://github.com/n3d1117/chatgpt-telegram-bot"
await update.message.reply_text(help_text, disable_web_page_preview=True)
Expand Down Expand Up @@ -109,7 +109,7 @@ async def transcribe(self, update: Update, context: ContextTypes.DEFAULT_TYPE):

if update.message.voice:
filename = update.message.voice.file_unique_id
elif update.message.audio:
elif update.message.audio:
filename = update.message.audio.file_unique_id
elif update.message.video:
filename = update.message.video.file_unique_id
Expand Down Expand Up @@ -138,7 +138,6 @@ async def transcribe(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
audio_track = AudioSegment.from_file(filename)
audio_track.export(filename_mp3, format="mp3")


# Transcribe the audio file
transcript = self.openai.transcribe(filename_mp3)

Expand Down

0 comments on commit 905f587

Please sign in to comment.