Skip to content

Commit

Permalink
include python documentation getter as a builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk committed Aug 29, 2023
1 parent 2df8a10 commit 8799160
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chatlab/builtins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from deprecation import deprecated

from .files import chat_functions as file_functions
from .python import run_python
from .python import get_python_docs, run_python
from .shell import chat_functions as shell_functions

# To prevent naming confusion, the builtin that isn't really running a cell
Expand All @@ -15,6 +15,6 @@
)(run_python)

# compose all the file, shell, and python functions into one list for ease of use
os_functions = file_functions + shell_functions + [run_python]
os_functions = file_functions + shell_functions + [run_python, get_python_docs]

__all__ = ["run_python", "run_cell", "file_functions", "shell_functions", "os_functions"]
__all__ = ["run_python", "get_python_docs", "run_cell", "file_functions", "shell_functions", "os_functions"]
10 changes: 10 additions & 0 deletions chatlab/builtins/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ def run_python(code: str):
return __shell.run_cell(code)


@expose_exception_to_llm
def get_python_docs(module_name: str):
"""Read docs for a Python package."""
import importlib
import inspect

package = importlib.import_module(module_name)
return inspect.getdoc(package)


__all__ = ["run_python", "ChatLabShell"]


Expand Down

0 comments on commit 8799160

Please sign in to comment.