Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jul 7, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from custodeexcessus July 7, 2023 12:41
chatbot: Optional[Chatbot] = None
app_cache = AppCache()
voices_by_features = dict()
voices_by_features = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 26-26 refactored with the following changes:

Comment on lines -66 to +101
if request.method == 'POST':
filename = request.form.get('filename')
data = {
"model": {
"name": request.form.get('model-name'),
"temperature": float(request.form.get('temperature'))
},
"user": {
"name": request.form.get('user-name'),
"image": request.form.get('profile-img-url'),
"gender": request.form.get('gender')
},
"bot": {
"name": request.form.get('tutor').split("-")[0],
"image": f"/static/bots_profile/{request.form.get('tutor').split('-')[0].lower()}.png",
"gender": request.form.get('tutor').split("-")[1].lower(),
"voice": request.form.get('voices-dropdown')
},
"language": {
"native": request.form.get('user-lang-dropdown').lower(),
"learning": request.form.get('tutor-lang-dropdown').split("-")[0].lower(),
"level": request.form.get('lang-level')
},
"behavior": {
"auto_send_recording": bool(request.form.get('auto-send-switch'))
}
}
with open(os.path.join(os.getcwd(), filename), 'w') as outfile:
yaml.dump(data, outfile, allow_unicode=True)
return jsonify({'status': 'success'})

else:
if request.method != 'POST':
return render_template('setup.html', males=MALE_TUTORS, females=FEMALE_TUTORS,
input_languages_codes_and_names=[[language.language_name_to_iso6391(lang), lang]
for lang in INPUT_LANGUAGES],
output_languages_locales_and_names=[[k, language.locale_code_to_language(k, name_in_same_language=True)]
for k in voices_by_features.keys()]
)
filename = request.form.get('filename')
data = {
"model": {
"name": request.form.get('model-name'),
"temperature": float(request.form.get('temperature'))
},
"user": {
"name": request.form.get('user-name'),
"image": request.form.get('profile-img-url'),
"gender": request.form.get('gender')
},
"bot": {
"name": request.form.get('tutor').split("-")[0],
"image": f"/static/bots_profile/{request.form.get('tutor').split('-')[0].lower()}.png",
"gender": request.form.get('tutor').split("-")[1].lower(),
"voice": request.form.get('voices-dropdown')
},
"language": {
"native": request.form.get('user-lang-dropdown').lower(),
"learning": request.form.get('tutor-lang-dropdown').split("-")[0].lower(),
"level": request.form.get('lang-level')
},
"behavior": {
"auto_send_recording": bool(request.form.get('auto-send-switch'))
}
}
with open(os.path.join(os.getcwd(), filename), 'w') as outfile:
yaml.dump(data, outfile, allow_unicode=True)
return jsonify({'status': 'success'})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setup refactored with the following changes:

Comment on lines -143 to +141
app_cache.bot_recordings = list()
app_cache.bot_recordings = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_response refactored with the following changes:

Comment on lines -272 to +270
user_recording = memory[message_id]['user_recording']
if user_recording:
if user_recording := memory[message_id]['user_recording']:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function play_user_message refactored with the following changes:

data = [
{"role": m["role"], "content": m["content"]}
for m in memory.get_chat_history()[1:]
]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function save_session refactored with the following changes:

Comment on lines -10 to +11
self._memory: List[dict] = list()
self._updates: List[dict] = list()
self._memory: List[dict] = []
self._updates: List[dict] = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Memory.__init__ refactored with the following changes:

Comment on lines -36 to +47
mem = {"role": role, "content": message, "recording": recording or list(), "user_recording": user_recording}
mem = {
"role": role,
"content": message,
"recording": recording or [],
"user_recording": user_recording,
}
updates = [u.copy() for u in self._updates]
updates = [u for u in updates if u["index"] == len(self._memory)]
[u.pop("index") for u in updates]
for u in updates:
u["recording"] = u["recording"] or []
mem.update(u)
mem |= u
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Memory.add refactored with the following changes:

:return: Dict: {lang: {gender: [list of voices]}}
"""
voices_dict = dict()
voices_dict = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function voices_by_features refactored with the following changes:

Comment on lines -22 to +35
characters = [c+' ' for c in ['.', '!', "?", ":", ";"]]
characters = [f'{c} ' for c in ['.', '!', "?", ":", ";"]]
escaped_characters = [re.escape(c) for c in characters]
if any([c in text for c in characters]):
if any(c in text for c in characters):
pattern = '|'.join(escaped_characters)
split_list = re.split(pattern, text)
return re.split(pattern, text)
elif '\n' in text:
lst = text.split('\n')
lst = [s for s in lst if len(s.strip()) > 0]
if len(lst) > 1:
split_list = [lst[0], "\n".join(lst[1:])]
else:
split_list = lst
return [lst[0], "\n".join(lst[1:])] if len(lst) > 1 else lst
elif ', ' in text and len(text) > 100:
lst = re.split(re.escape(',') + r'\s', text)
split_list = [lst[0], ", ".join(lst[1:])]
return [lst[0], ", ".join(lst[1:])]
else:
split_list = [text]
return split_list
return [text]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function split_to_sentences refactored with the following changes:

Credentials.from_service_account_info(sa)
if (sa := config.get("google_sa", None))
else None
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_gcs_credentials refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants