Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
- Update doc layout
- Add syntax highlight support
  • Loading branch information
edwardzjl committed Nov 12, 2024
1 parent 50021fb commit 98d4a33
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 215 deletions.
Empty file removed docs/how-to-guides.md
Empty file.
1 change: 1 addition & 0 deletions docs/howto/persist-messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Persist Messages
1 change: 1 addition & 0 deletions docs/howto/retrieval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Enhance TableGPT Agent with RAG
15 changes: 10 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ tablegpt-agent is a pre-built agent for [TableGPT2 (huggingface)](https://huggin

## Table Of Contents

1. [Tutorials](tutorials.md)
2. [How-To Guides](how-to-guides.md)
3. [Reference](reference.md)
4. [Explanation](explanation.md)
<!-- mkdocs requires 4 space to intent the list -->
- Tutorials
- [Quickstart](tutorials/quickstart.md)
- [Chat on Tabular Data](tutorials/table-chat.md)
- How-To Guides
- [Enhance TableGPT Agent with RAG](howto/retrieval.md)
- [Persist Messages](howto/persist-messages.md)
- [Reference](reference.md)
- [Explanation](explanation.md)

## Contributing

For more information on how to contribute, see [here](https://github.com/tablegpt/tablegpt-agent/blob/main/CONTRIBUTING.md).
Thank you for your interest in TableGPT Agent. For more information on contributing, please see [the contributing guide](https://github.com/tablegpt/tablegpt-agent/blob/main/CONTRIBUTING.md).

## Acknowledgements

Expand Down
125 changes: 125 additions & 0 deletions docs/tutorials/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Quickstart

## Installation

To install `tablegpt-agent`, use the following command:

```sh
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]
```

## 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:

```sh
python -m vllm.entrypoints.openai.api_server --served-model-name TableGPT2-7B --model path/to/weights
```

> **Note:** For production environments, it's important to optimize the vllm server configuration. For details, refer to the [vllm documentation on server configuration](https://docs.vllm.ai/en/v0.6.0/serving/openai_compatible_server.html#command-line-arguments-for-the-server).
## Chat with TableGPT Agent

To create a `TablegptAgent`, you'll need both `LLM` and `PyBoxManager` components:

```pycon
>>> from langchain_openai import ChatOpenAI
>>> from pybox import LocalPyBoxManager
>>> from tablegpt.agent import create_tablegpt_graph

>>> llm = ChatOpenAI(openai_api_base="YOUR_VLLM_URL", openai_api_key="whatever", model_name="TableGPT2-7B")
>>> pybox_manager = LocalPyBoxManager()

>>> agent = create_tablegpt_graph(
... llm=llm,
... pybox_manager=pybox_manager,
... )
```

To interact with the agent:

```pycon
>>> import asyncio
>>> from datetime import date
>>> from langchain_core.messages import HumanMessage

>>> message = HumanMessage(content="Hi")

>>> _input = {
... "messages": [message],
... "parent_id": "some-parent-id",
... "date": date.today(),
... }

>>> response = asyncio.run(agent.ainvoke(_input))
>>> print(response["messages"])
[HumanMessage(content='Hi', additional_kwargs={}, response_metadata={}, id='7da7e51c-0ad0-4481-aa22-54acce6a82d7'), AIMessage(content="Hello! How can I assist you with your data analysis today? Do you have a dataset you'd like to work with?", additional_kwargs={'parent_id': 'some-parent-id'}, response_metadata={}, id='43df249b-9c61-44bc-a535-eb33f9efaa9e')]
```

You can get more detailed outputs with the `astream_events` method:

```pycon
>>> async for event in agent.astream_events(
... input=_input,
... version="v2",
... ):
... # We ignore irrelevant events here.
... if event["event"] == "on_chat_model_end":
... print(event["data"]["output"])
content="Hello! How can I assist you with your data analysis today? Do you have a specific dataset or problem in mind that you'd like to work on?" additional_kwargs={} response_metadata={'finish_reason': 'stop', 'model_name': 'TableGPT2-7B'} id='run-677d42b7-ae79-4695-8e54-1b02fab07427'
```

<details>

<summary>Full code</summary>

```python
import asyncio
from datetime import date

from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
from pybox import LocalPyBoxManager
from tablegpt.agent import create_tablegpt_graph


# 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")

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

agent = create_tablegpt_graph(
llm=llm,
pybox_manager=pybox_manager,
)

message = HumanMessage(content="Hi")
_input = {
"messages": [message],
"parent_id": "some-parent-id",
"date": date.today(), # noqa: DTZ011
}

# response = await agent.ainvoke(_input)
# print(response["messages"])

# More details can be obtained through the astream_events method
async for event in agent.astream_events(
input=_input,
version="v2",
):
print(event) # noqa: T201


asyncio.run(main())
```

</details>
Loading

0 comments on commit 98d4a33

Please sign in to comment.