Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tablegpt kernel setups #81

Merged
merged 5 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 32 additions & 30 deletions collect_script.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
import platform
import sys
import subprocess
import traceback
import sys


def get_os_info():
return {
'system': platform.system(),
'node': platform.node(),
'release': platform.release(),
'version': platform.version(),
'machine': platform.machine(),
'processor': platform.processor(),
"system": platform.system(),
"node": platform.node(),
"release": platform.release(),
"version": platform.version(),
"machine": platform.machine(),
"processor": platform.processor(),
}


def get_python_info():
return {
'implementation': platform.python_implementation(),
'version': platform.python_version(),
'compiler': platform.python_compiler(),
"implementation": platform.python_implementation(),
"version": platform.python_version(),
"compiler": platform.python_compiler(),
}


def get_pip_list():
try:
result = subprocess.run([sys.executable, '-m', 'pip', 'list'], capture_output=True, text=True)
if result.returncode == 0:
return result.stdout
else:
return f"Failed to get pip list: {result.stderr}"
except Exception as e:
return f"An error occurred: {str(e)}"

def write_to_log_file(content, filename='env_output.log'):
try:
with open(filename, 'w') as file:
file.write(content)
except Exception as e:
print(f"Error writing to file {filename}: {e}")
traceback.print_exc()
result = subprocess.run(
[sys.executable, "-m", "pip", "list"],
capture_output=True,
text=True,
check=False,
)
if result.returncode == 0:
return result.stdout

return f"Failed to get pip list: {result.stderr}"


def write_to_log_file(content, filename="env_output.log"):
with open(filename, "w") as file:
file.write(content)


def main():
os_info = get_os_info()
python_info = get_python_info()
pip_list = get_pip_list()


content = "Operating System Information:\n"
for key, value in os_info.items():
content += f"{key}: {value}\n"
Expand All @@ -56,10 +57,11 @@ def main():
content += pip_list

# stdout
print(content)
print(content) # noqa: T201

# file
write_to_log_file(content)


if __name__ == "__main__":
main()
main()
8 changes: 6 additions & 2 deletions docs/tutorials/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ pip install tablegpt-agent
This package depends on [pybox](https://github.com/edwardzjl/pybox), a Python code sandbox delegator. By default, `pybox` operates in an in-cluster mode. If you wish to run `tablegpt-agent` in a local environment, you need to install an optional dependency:

```sh
pip install pppybox[local]
pip install tablegpt-agent[local]
```

## Setup LLM Service

Before using `tablegpt-agent`, ensure that you have an OpenAI-compatible server set up to host TableGPT2. We recommend using [vllm](https://github.com/vllm-project/vllm) for this:

> **Note:** If you need to use `tablegpt-agent` to analyze tabular data, please ensure your `vllm>=0.5.5`
```sh
```sh
pip install 'vllm>=0.5.5'
```

Expand All @@ -33,6 +33,10 @@ python -m vllm.entrypoints.openai.api_server --served-model-name TableGPT2-7B --
## Chat with TableGPT Agent

To create a `TablegptAgent`, you'll need both an `LLM` and a `PyBoxManager` instance:
> **NOTE** The `llm` is created using `langchain-openai`, please install it first.
```sh
pip install langchain-openai
```

```pycon
>>> from langchain_openai import ChatOpenAI
Expand Down
11 changes: 8 additions & 3 deletions examples/data_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from pybox import LocalPyBoxManager
from tablegpt import DEFAULT_TABLEGPT_IPYKERNEL_PROFILE_DIR
from tablegpt.agent import create_tablegpt_graph
from tablegpt.agent.file_reading import Stage

Expand All @@ -19,10 +20,14 @@ class Attachment(TypedDict):

# tablegpt-agent fully supports async invocation
async def main() -> None:
llm = ChatOpenAI(openai_api_base="YOUR_VLLM_URL", openai_api_key="whatever", model_name="TableGPT2-7B")
llm = ChatOpenAI(
openai_api_base="YOUR_VLLM_URL",
openai_api_key="whatever",
model_name="TableGPT2-7B",
)

# Use local pybox manager for development and testing
pybox_manager = LocalPyBoxManager()
pybox_manager = LocalPyBoxManager(profile_dir=DEFAULT_TABLEGPT_IPYKERNEL_PROFILE_DIR)

agent = create_tablegpt_graph(
llm=llm,
Expand All @@ -37,7 +42,7 @@ async def main() -> None:
attachment_msg = HumanMessage(
content="",
# The dataset can be viewed in examples/datasets/titanic.csv.
additional_kwargs={"attachments": [Attachment(filename="titanic.csv")]},
additional_kwargs={"attachments": [Attachment(filename="examples/datasets/titanic.csv")]},
)
await agent.ainvoke(
input={
Expand Down
31 changes: 30 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,38 @@ dependencies = [
"langchain-qdrant>=0.1.4,<1.0.0",
"langgraph>=0.0.68,<1.0.0",
"pandas>=2.2,<3.0.0",
"pppybox>=0.0.13",
"pppybox>=0.0.14"
]

[project.urls]
Documentation = "https://github.com/tablegpt/tablegpt/blob/main/README.md"
Issues = "https://github.com/tablegpt/tablegpt/issues"
Source = "https://github.com/tablegpt/tablegpt"

[project.optional-dependencies]
local = [
"pandas >=2.2,<3.0.0",
"scipy >=1.13.0,<2.0.0",
"tabulate >=0.9.0,<1.0.0",
"scikit-learn >=1.0.0,<2.0.0",
"statsmodels >=0.10.0,<1.0.0",
"matplotlib >=3.8.4,<4.0.0",
"seaborn >=0.13.1,<1.0.0",
"mplfonts >=0.0.8,<1.0.0",
"numexpr >=2.8.4",
"openpyxl >=3.1.2,<4.0.0",
"xlrd >= 2.0.1",
"odfpy",
"pppybox[local]>=0.0.14"
]


[tool.hatch.build.targets.wheel]
packages = ["src/tablegpt"]

[tool.hatch.build.targets.wheel.shared-data]
"ipython/ipython-startup-scripts" = "share/ipykernel/profile/tablegpt/startup"

[tool.hatch.version]
path = "src/tablegpt/__about__.py"

Expand Down Expand Up @@ -75,3 +96,11 @@ exclude_lines = [
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
"ipython"
]
# Allow lines to be as long as 120.
line-length = 120
4 changes: 4 additions & 0 deletions src/tablegpt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

DEFAULT_TABLEGPT_IPYKERNEL_PROFILE_DIR = os.path.join(sys.prefix, "share/ipykernel/profile/tablegpt")