Closed ilNikk closed 1 year ago
I think you filters out too many characters. It seems deleting all CJK characters 😭:
>>> print(s)
几点了?
何時ですか?
몇 시예요?
What time is it?
What time is it?
Wie spät ist es?
Quelle heure est-il ?
Che ora è?
¿Qué hora es?
كم الساعة؟
ตอนนี้กี่โมงแล้ว?
который сейчас час?
🙋♂️🕐❓
>>> print(filter_emoji(s))
?
?
What time is it?
What time is it?
Wie spät ist es?
Quelle heure est-il ?
Che ora è?
¿Qué hora es?
كم الساعة؟
ตอนนี้กี่โมงแล้ว?
который сейчас час?
Ouch, my fault 😞
Pls check with this. I also added a standard emoticon like:) :( :D
etcetc
functions
# added for emoji and emoticon filter
import re
def filter_emoji(text): # emoji filter
emoji_pattern = re.compile("["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags
u"\U0001F910-\U0001F95F" # people & body
u"\U00002600-\U000027BF" # dingbats
u"\U000026A0-\U000026FF" # misc symbols
u"\U0000FE0F" # emoji variation selector
u"\u2640-\u2642" # gender symbols
"]+", flags=re.UNICODE)
filtered_text = re.sub(emoji_pattern, '', text)
return filtered_text
def filter_emoticons(text): # emoticon filter :( :D :P :O :o ;) :| :/ :\ :^) :'( :_ :S :@ :x :X :\$ :# :%
emoticon_pattern = r'(?::|;|=)(?:-)?(?:\)|\(|D|P|O|o|\[|\]|3|>|<|\/|\||\\|\^|\'|_|S|@|x|X|\$|#|%)'
filtered_text = re.sub(emoticon_pattern, '', text)
return filtered_text
def filter_response(text):
text = str(text)
filtered_text = filter_emoji(text)
filtered_text = filter_emoticons(filtered_text)
return filtered_text
ask()
def ask(self, session_id, prompt, **kwargs) -> str: # raises Exception
"""Ask ChatGPT with prompt, return response text
- session_id: unused
Raises:
ChatGPTError: ChatGPT error
"""
response: str | None = None
try:
with self.lock:
response = self.chatbot.ask(prompt)
except Exception as e:
logging.warning(f"ChatGPT ask error: {e}")
raise ChatGPTError(str(e))
if not response:
raise ChatGPTError("ChatGPT response is None")
filteredemoji_resp = filter_response(response) #filter emoji and emoticon on response
return filteredemoji_resp #return filtered message
Wow, thanks for your work. 👏 Would you mind to make a Pull Request?
committed
Merged. Thanks a lot for your contribution. 🎉
ChatGPT responses are annoying when there are emojis. I made changes to filter emojis on answers.
chatgpt_chatbot/chatgpt/chatbot.py: import re, filter_emoji() function
chatgpt_chatbot/chatgpt/chatbot.py: ask() return updated
A nice idea would be to then take the filtered emoji and send them to live2ddriver as instructions for expressions or movements!
Suggestions are welcome 😃