Skip to content

Commit

Permalink
Add TaskWeaver website (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShilinHe authored Dec 21, 2023
2 parents ce58d46 + b0e9410 commit 7ee971f
Show file tree
Hide file tree
Showing 51 changed files with 26,334 additions and 199 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/deploy-website.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: docs

on:
push:
branches: [main]
path:
- 'website/*'
- '.github/workflows/deploy-website.yml'
workflow_dispatch:
merge_group:
types: [checks_requested]

jobs:
gh-release:
runs-on: ubuntu-latest
defaults:
run:
working-directory: website
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Build website
run: |
if [ -e yarn.lock ]; then
yarn install --frozen-lockfile --ignore-engines
yarn build
elif [ -e package-lock.json ]; then
npm ci
npm run build
else
npm i --legacy-peer-deps
npm run build
fi
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Build output to publish to the `gh-pages` branch:
publish_dir: ./website/build
176 changes: 47 additions & 129 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,46 @@
A **code-first** agent framework for seamlessly planning and executing data analytics tasks.
This innovative framework interprets user requests through coded snippets and efficiently
coordinates a variety of plugins in the form of functions to execute
data analytics tasks

**Highlighted Features**

- [x] **Rich data structure** - TaskWeaver allows you to work with rich data
structures in Python, such as DataFrames, instead of having to work with
text strings.
- [x] **Customized algorithms** - TaskWeaver allows you to encapsulate your
own algorithms into plugins (in the form of Python functions),
and orchestrate them to achieve complex tasks.
- [x] **Incorporating domain-specific knowledge** - TaskWeaver is designed to
be easily incorporating domain-specific knowledge, such as the knowledge
of execution flow, to improve the reliability of the AI copilot.
- [x] **Stateful conversation** - TaskWeaver is designed to support stateful
conversation. It can remember the context of the conversation and
leverage it to improve the user experience.
- [x] **Code verification** - TaskWeaver is designed to verify the generated code
before execution. It can detect potential issues in the generated code
and provide suggestions to fix them.
- [x] **Easy to use** - TaskWeaver is designed to be easy to use.
We provide a set of sample plugins and a tutorial to help you get started.
Users can easily create their own plugins based on the sample plugins.
TaskWeaver offers an open-box experience, allowing users to run a service immediately after installation.
- [x] **Easy to debug** - TaskWeaver is designed to be easy to debug.
We have detailed logs to help you understand what is going on during calling the LLM,
the code generation, and execution process.
- [x] **Security consideration** - TaskWeaver supports a basic session management to keep
different users' data separate. The code execution is separated into different processes in order not to interfere with each other.
- [x] **Easy extension** - TaskWeaver is designed to be easily extended to accomplish
more complex tasks. You can create multiple AI copilots to
act in different roles, and orchestrate them to achieve complex tasks.

# News

- [2023-12-12] A simple UI demo is available in playground/UI folder, try with the [README](/playground/UI/README.md)
- [2023-11-30] TaskWeaver is released on GitHub🎈.


# Getting started

## Prerequisites

- Python 3.10 or above
- OpenAI (or Azure OpenAI) access with GPT-3.5 above models. However, it is strongly recommended to use the GPT-4, which is more stable.
- Other requirements can be found in the `requirements.txt` file.

> OpenAI API had a major [update](https://github.com/openai/openai-python) from 0.xx to 1.xx in November 2023.
> Please make sure you are not using an old version because the API is not backward compatible.
data analytics tasks.

# News🆕
- 📅2023-12-21: TaskWeaver now supports a number of LLMs, such as LiteLLM, Ollama, Gemini, and QWen🎈.
- 📅2023-12-21: TaskWeaver Website is now [available](https://microsoft.github.io/TaskWeaver/) with more documentations.
- 📅2023-12-12: A simple UI demo is available in playground/UI folder, try it [here](https://microsoft.github.io/TaskWeaver/docs/usage/webui)!
<!-- - [2023-11-30] TaskWeaver is released on GitHub🎈. -->


## Highlights

- [x] **Rich data structure** - TaskWeaver allows you to work with rich data structures in Python, such as DataFrames, instead of dealing with strings.
- [x] **Customized algorithms** - TaskWeaver allows you to encapsulate your own algorithms into plugins and orchestrate them.
- [x] **Incorporating domain-specific knowledge** - TaskWeaver is designed to incorporat domain-specific knowledge easily to improve the reliability.
- [x] **Stateful execution** - TaskWeaver is designed to support stateful execution of the generated code to ensure consistent and smooth user experience.
- [x] **Code verification** - TaskWeaver is designed to verify the generated code before execution. It can detect potential issues in the generated code and provide suggestions to fix them.
- [x] **Easy to use** - TaskWeaver is easy to use with sample plugins, examples and tutorials to help you get started. TaskWeaver offers an open-box experience, allowing users to run it immediately after installation.
- [x] **Easy to debug** - TaskWeaver is easy to debug with detailed and transparent logs to help you understand the entire process, including LLM prompts, the code generation, and execution process.
- [x] **Security consideration** - TaskWeaver supports a basic session management to keep different users' data separate. The code execution is separated into different processes to avoid mutal interference.
- [x] **Easy extension** - TaskWeaver is easy to extend to accomplish more complex tasks with multiple agents as the plugins.

## Quick Start

### Installation
You can install TaskWeaver by running the following command:
TaskWeaver requires **Python >= 3.10**. It can be installed by running the following command:
```bash
# [optional to create conda environment]
# conda create -n taskweaver python=3.10
# conda activate taskweaver

# clone the repository
git clone https://github.com/microsoft/TaskWeaver.git
cd TaskWeaver
# install the requirements
pip install -r requirements.txt
```


### Project Directory
TaskWeaver runs as a process, you need to create a project directory to store plugins and configuration files.
We provided a sample project directory in the `project` folder. You can copy the `project` folder to your workspace.
A project directory typically contains the following files and folders:

```bash
📦project
┣ 📜taskweaver_config.json # the configuration file for TaskWeaver
┣ 📂plugins # the folder to store plugins
┣ 📂planner_examples # the folder to store planner examples
┣ 📂codeinterpreter_examples # the folder to store code interpreter examples
┣ 📂sample_data # the folder to store sample data used for evaluations
┣ 📂logs # the folder to store logs, will be generated after program starts
┗ 📂workspace # the directory stores session data, will be generated after program starts
┗ 📂 session_id
┣ 📂ces # the folder used by the code execution service
┗ 📂cwd # the current working directory to run the generated code
```

### OpenAI Configuration
Before running TaskWeaver, you need to provide your OpenAI API key and other necessary information.
You can do this by editing the `taskweaver_config.json` file.
If you are using Azure OpenAI, you need to set the following parameters in the `taskweaver_config.json` file:
#### Azure OpenAI
```json
{
"llm.api_base": "https://xxx.openai.azure.com/",
"llm.api_key": "your_api_key",
"llm.api_type": "azure",
"llm.api_version": "the api version",
"llm.model": "the model name, e.g., gpt-4"
}
```
### Configure the LLMs
Before running TaskWeaver, you need to provide your LLM configurations. Taking OpenAI as an example, you can configure `taskweaver_config.json` file as follows.

#### OpenAI
```json
Expand All @@ -108,15 +53,14 @@ If you are using Azure OpenAI, you need to set the following parameters in the `
"llm.model": "the model name, e.g., gpt-4"
}
```
>💡 Only the latest OpenAI API supports the `json_object` response format.
> If you are using an older version of OpenAI API, you need to set the `llm.response_format` to `null`.

More configuration options can be found in the [configuration documentation](docs/configuration.md).
💡 TaskWeaver also supports other LLMs and advanced configurations, please check the [documents](https://microsoft.github.io/TaskWeaver/docs/overview) for more details.

### Start TaskWeaver

#### 1. Command Line Interaction
```bash
# assume you are in the taskweaver folder
# -p is the path to the project directory
# assume you are in the cloned TaskWeaver folder
python -m taskweaver -p ./project/
```
This will start the TaskWeaver process and you can interact with it through the command line interface.
Expand All @@ -134,7 +78,22 @@ TaskWeaver: I am TaskWeaver, an AI assistant. To get started, could you please e
Human: ___
```

### Two Walkthrough Examples
#### 2. Web UI
TaskWeaver also supports WebUI for demo purpose, please refers to [web UI docs](https://microsoft.github.io/TaskWeaver/docs/usage/webui) for more details.

#### 3. Import as a Library
TaskWeaver can be imported as a library to integrate with your existing project, more information can be found in [docs](https://microsoft.github.io/TaskWeaver/docs/usage/library)

## Documentation
More documentations can be found on [TaskWeaver Website](https://microsoft.github.io/TaskWeaver).



---
---


## Demo Examples



Expand Down Expand Up @@ -178,47 +137,6 @@ For more examples, please refer to our [paper](http://export.arxiv.org/abs/2311.
> 💡 The planning of TaskWeaver are based on the LLM model. Therefore, if you want to repeat the examples, the execution process may be different
> from what you see in the videos. Typically, more concrete prompts will help the model to generate better plans and code.

## How to use TaskWeaver in your project

### Using TaskWeaver as a library
After cloning the TaskWeaver repository, you can install TaskWeaver as a library by running the following command:
```bash
# clone the repository
cd TaskWeaver
pip install -e .
```
Then, you can follow the [documentation](docs/taskweaver_as_a_lib.md) to use TaskWeaver in your code.

### Using TaskWeaver as a service
TaskWeaver can be used as a service that can be called by other programs. More details are TBD.

## Customizing TaskWeaver

There are two ways to customize TaskWeaver: creating plugins and creating examples.

### Creating Plugins

Since TaskWeaver can already perform some basic tasks, you can create plugins to extend its capabilities.
A plugin is a python function that takes a set of arguments and returns a set of results.

Typically, you only need to write a plugin in the following example scenarios:
- You want to encapsulate your own algorithm into a plugin.
- You want to import a python package that is not supported by TaskWeaver.
- You want to connect to an external data source to pull data.
- You want to query a web API.

Refer to the [plugin documentation](docs/plugin.md) for more details. Otherwise, you can leverage TaskWeaver's code generation capability to perform tasks.

### Creating Examples

The purpose of examples is to help LLMs understand how to perform tasks especially when
the tasks are complex and need domain-specific knowledge.

There are two types of examples: (1) planning examples and (2) code interpreter examples.
Planning examples are used to demonstrate how to use TaskWeaver to plan for a specific task.
Code generation examples are used to demonstrate how to generate code or orchestrate plugins to perform a specific task.

Refer to the [example documentation](docs/example.md) for more details.

## Citation
Our paper could be found [here](http://export.arxiv.org/abs/2311.17541).
Expand Down
39 changes: 0 additions & 39 deletions docs/configuration.md

This file was deleted.

23 changes: 18 additions & 5 deletions taskweaver/llm/google_genai.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,29 @@ def _chat_completion(
**kwargs: Any,
) -> Generator[ChatMessageType, None, None]:
genai_messages = []
prev_role = ""
for msg in messages:
if msg["role"] == "system" or msg["role"] == "user":
if msg["role"] == "system":
genai_messages.append({"role": "user", "parts": [msg["content"]]})
genai_messages.append(
{
"role": "model",
"parts": ["I understand your requirements, and I will assist you in the conversations."],
},
)
prev_role = "model"
elif msg["role"] == "user":
if prev_role == "user":
# a placeholder to create alternating user and model messages
genai_messages.append({"role": "model", "parts": [" "]})
genai_messages.append({"role": "user", "parts": [msg["content"]]})
prev_role = "user"
elif msg["role"] == "assistant":
genai_messages.append({"role": "model", "parts": [msg["content"]]})
prev_role = "model"
else:
raise Exception(f"Invalid role: {msg['role']}")

genai_messages.insert(
1,
{"role": "model", "parts": ["I understand your requirements, and I will assist you in the conversations."]},
)
if stream is False:
response = self.model.generate_content(genai_messages, stream=False)
yield format_chat_message("assistant", response.text)
Expand Down
Loading

0 comments on commit 7ee971f

Please sign in to comment.