removing diacritics from response

This commit is contained in:
Rudis Muiznieks 2025-04-02 20:49:18 -05:00
parent 0357a8e436
commit 5e06c03a15
Signed by: rudism
GPG key ID: CABF2F86EF7884F9
3 changed files with 10 additions and 4 deletions

View file

@ -6,7 +6,7 @@
pip install --upgrade git+https://code.sitosis.com/rudism/skill-ovos-fallback-kagi.git
```
Then reboot.
Then restart OVOS (`systemctl --user restart ovos`, or reboot).
### Configure

View file

@ -16,6 +16,7 @@ import requests
import json
import html
import re
import unicodedata
from urllib.parse import quote_plus
class KagiSkill(FallbackSkill):
@ -100,12 +101,12 @@ class KagiSkill(FallbackSkill):
text = re.sub(pattern_refs, '', html_text)
text = re.sub(pattern_sups, '', text)
text = re.sub(pattern_tags, '', text)
return html.unescape(text)
return self.remove_diacritics(html.unescape(text))
def clean_api_string(self, text):
text = text.replace('*', '').replace('_', '')
text = re.sub(r'\\d+】', '', text)
return text
return self.remove_diacritics(text)
def get_api_response(self, json_data):
if not isinstance(json_data.get("data"), dict):
@ -119,3 +120,8 @@ class KagiSkill(FallbackSkill):
self.log.error(f"'output' was not a string in kagi api response (found {type(output_value).__name__})")
return None
return output_value
def remove_diacritics(self, text):
normalized = unicodedata.normalize('NFD', text)
ascii = ''.join(c for c in normalized if not unicodedata.combining(c))
return ascii

View file

@ -4,7 +4,7 @@ import os
from os import walk, path
PYPI_NAME = "skill-ovos-fallback-kagi" # pip install PYPI_NAME
VERSION = "0.1.2"
VERSION = "0.1.3"
URL = f"https://code.sitosis.com/rudism/{PYPI_NAME}"
SKILL_CLAZZ = "KagiSkill" # needs to match __init__.py class name