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:
parent
1f9137bb20
commit
3648fef5fb
@ -11,13 +11,15 @@ class Settings:
|
|||||||
self.settings_path = path.join(SKILL_PATH, 'src', 'settings.json')
|
self.settings_path = path.join(SKILL_PATH, 'src', 'settings.json')
|
||||||
self.settings_sample_path = path.join(SKILL_PATH, 'src', 'settings.sample.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
|
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_sample = self.get_settings_sample()
|
||||||
settings = self.get()
|
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:
|
def clear(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -48,6 +50,7 @@ class Settings:
|
|||||||
|
|
||||||
if key is not None:
|
if key is not None:
|
||||||
return settings[key]
|
return settings[key]
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error while reading settings at '{self.settings_path}': {e}")
|
print(f"Error while reading settings at '{self.settings_path}': {e}")
|
||||||
|
@ -105,23 +105,21 @@ def run(params: ActionParams) -> None:
|
|||||||
|
|
||||||
###
|
###
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
leon.answer({
|
|
||||||
'key': 'answer',
|
if not settings.is_already_set('apiKey'):
|
||||||
'data': {
|
leon.answer({
|
||||||
'answer': f"Skill settings already set: {settings.is_already_set()}"
|
'key': "The API key isn't set..."
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
current_settings = settings.get()
|
||||||
|
|
||||||
settings.set({
|
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({
|
leon.answer({
|
||||||
'key': 'answer',
|
'key': f"Is API set now? {settings.is_already_set('apiKey')}"
|
||||||
'data': {
|
|
||||||
'answer': f"{options['some_sample_config']} {some_sample_config}"
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
###
|
###
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"someSampleConfig": "someSampleValue"
|
"someSampleConfig": "someSampleValue",
|
||||||
|
"apiKey": "YOUR_API_KEY"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user