appl icon indicating copy to clipboard operation
appl copied to clipboard

Feature Request: keep the core language as a pure library

Open yihuang opened this issue 1 year ago • 3 comments

Feature Title

decouple settings and execution layer from the core language

Motivation

Make it easier to play with core module without worrying the settings. and easier call core module as a pure library, help with adoption.

Feature Description

The language design looks very interesting, one issue for me is whenever I import appl, it's slow and output bunch of logs.

If we can decouple the core language module from the execution and settings, keep a pure core library, people can embed the language into other application easier, that'll help with the adoption.

Not sure if that's a direction for this project. and I'd be glad to help with some implementations.

Potential Impact

No response

yihuang avatar Feb 07 '25 02:02 yihuang

Thanks for your suggestion.

For the time of import appl, it is about 1.2s on my end, whereas about 1.0s come from import litellm. APPL depends on the litellm package to call various LLMs, so there is not much APPL can do to significantly reduce the time for import. If you want to play with that, you can create a Jupyter Notebook, import appl in a code block in the beginning, and play with APPL in other code cells without importing APPL again.

For the logs during initialization, you can now setup env variable APPL_SHOW_INIT_LOG as false to disable that (see this commit 5bc77ac6e9bfa46ce5303bca286b8ec4bd474cec). Does this sound like a good solution for you? do you have any further suggestions?

After initialization, you can disable other logging by:

from loguru import logger
logger.remove()

dhh1995 avatar Feb 07 '25 07:02 dhh1995

I guess it depends on the direction of this library, I find there are many goodies inside, and it'd be ideal if it's more reusable, for a simple example:

>>> def test(a: int, b: int): pass
...
>>> from appl.func import as_tool
2025-02-11 10:59:19 | INFO     | appl.settings:_appl_init:295 | Loaded configs from appl.yaml
2025-02-11 10:59:19 | INFO     | appl.settings:_setup_logging:75 | Logging to file: ./logs/appl_2025_02_11__10_59_19.log with level INFO
2025-02-11 10:59:19 | INFO     | appl.settings:_setup_caching:115 | Using cache folder: ~/.appl/caches
2025-02-11 10:59:19 | INFO     | appl.caching.db:_cleanup:106 | Cleaning up expired caching entries before 2025-01-12 10:59:19.559845
2025-02-11 10:59:19 | INFO     | appl.settings:_log_servers_info:188 | Default server is now configured to deepseek/deepseek-chat
2025-02-11 10:59:19 | INFO     | appl.settings:_log_servers_info:194 | Large server is now configured to deepseek/deepseek-reasoner
>>> as_tool(test)
Tool(name='test', short_desc='', long_desc='', params=<class 'appl.core.tool.parameters'>, returns=<class 'appl.core.tool.returns'>, raises=[], examples=[], info={})
>>> as_tool(test).openai_schema
2025-02-11 10:59:34 | WARNING  | appl.core.tool:_get_description:190 | Tool test has no description.
{'type': 'function', 'function': {'name': 'test', 'description': 'test', 'parameters': {'properties': {'a': {'title': 'A', 'type': 'integer'}, 'b': {'title': 'B', 'type': 'integer'}}, 'required': ['a', 'b'], 'title': 'parameters', 'type': 'object'}}}

as_tool is useful is many context, I hope it can be used as a pure library. I'd suggest we split out a core library which don't depends on settings/loggers/litellm, etc.

yihuang avatar Feb 11 '25 03:02 yihuang

I see your point from the example and thanks for the suggestion. I think one way is to move these useful functions out of the core folder into a standalone lib (applib?), where the appl also depends on the applib but applib can be imported independently. Then, for example, users can from applib import as_tool.

Do you have any other suggestions for that? Would you be interested in doing such refactoring?

Thanks!

dhh1995 avatar Feb 11 '25 04:02 dhh1995