1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-28 04:04:58 +03:00

refactor(bridge/python): add key to settings.isAlreadySet

This commit is contained in:
louistiti 2023-05-27 09:00:00 +08:00
parent 1f9137bb20
commit 3648fef5fb
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
3 changed files with 19 additions and 17 deletions

View File

@ -11,13 +11,15 @@ class Settings:
self.settings_path = path.join(SKILL_PATH, 'src', 'settings.json')
self.settings_sample_path = path.join(SKILL_PATH, 'src', 'settings.sample.json')
def is_already_set(self) -> bool:
def is_already_set(self, key: str) -> bool:
"""
Check if the settings are already set
:param key: The key to verify whether its value is set
"""
settings_sample = self.get_settings_sample()
settings = self.get()
return json.dumps(settings) != json.dumps(settings_sample)
return key in settings and json.dumps(settings[key]) != json.dumps(settings_sample[key])
def clear(self) -> None:
"""
@ -48,6 +50,7 @@ class Settings:
if key is not None:
return settings[key]
return settings
except Exception as e:
print(f"Error while reading settings at '{self.settings_path}': {e}")

View File

@ -105,23 +105,21 @@ def run(params: ActionParams) -> None:
###
settings = Settings()
if not settings.is_already_set('apiKey'):
leon.answer({
'key': 'answer',
'data': {
'answer': f"Skill settings already set: {settings.is_already_set()}"
}
'key': "The API key isn't set..."
})
current_settings = settings.get()
settings.set({
'some_sample_config': 'Hello world'
**current_settings,
'apiKey': 'newAPIKey'
})
settings.set('some_sample_config', 'Hello world 2')
options = settings.get()
some_sample_config = settings.get('some_sample_config')
leon.answer({
'key': 'answer',
'data': {
'answer': f"{options['some_sample_config']} {some_sample_config}"
}
'key': f"Is API set now? {settings.is_already_set('apiKey')}"
})
###

View File

@ -1,3 +1,4 @@
{
"someSampleConfig": "someSampleValue"
"someSampleConfig": "someSampleValue",
"apiKey": "YOUR_API_KEY"
}