Skip to content

Commit

Permalink
udpate readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RexWzh committed Dec 20, 2023
1 parent 24fff45 commit f56ec79
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 10 deletions.
71 changes: 71 additions & 0 deletions README-EN.md
@@ -0,0 +1,71 @@
# WebChatter

[English](README-EN.md) | [简体中文](README.md)

[![PyPI version](https://img.shields.io/pypi/v/webchatter.svg)](https://pypi.python.org/pypi/webchatter)
[![Tests](https://github.com/cubenlp/webchatter/actions/workflows/test.yml/badge.svg)](https://github.com/cubenlp/webchatter/actions/workflows/test.yml/)
[![Documentation Status](https://img.shields.io/badge/docs-github_pages-blue.svg)](https://apicall.wzhecnu.cn)
[![Coverage](https://codecov.io/gh/cubenlp/webchatter/branch/main/graph/badge.svg)](https://codecov.io/gh/cubenlp/webchatter)

## Features

A Chat encapsulation based on AccessToken, useful for data annotation.

## Installation

```bash
pip install webchatter --upgrade
```

Set environment variables:
```bash
export OPENAI_ACCESS_TOKEN="your_access_token"
export API_REVERSE_PROXY="http://your_reverse_proxy"
export WEB_REVERSE_PROXY="http://your_reverse_proxy/backend-api"
```

Where `OPENAI_ACCESS_TOKEN` can be obtained after logging in to the website [/api/auth/session](https://chat.openai.com/api/auth/session). For reverse proxy setup, you can refer to the [ninja project](https://github.com/gngpp/ninja/).

## Basic Usage

Data annotation example, performing addition:
```py
from webchatter import process_messages
from random import randint

msgs = [f"find the result of {randint(3, 100)} + {randint(4, 100)}" for _ in range(4)]
# Annotate some data and get interrupted
process_messages(msgs[:2], "test.jsonl")
# Continue annotation
process_messages(msgs, "test.jsonl")
```

General usage:

```py
from webchatter import WebChat

# Create a conversation
chat = WebChat()
# Input a question | Return an answer
chat.ask("hello world!")
# Get conversation history
chat.print_log()
```

Other usage:

```py
from webchatter import WebChat
from pprint import pprint
chat = WebChat()

# View the total number of web chats
pprint(chat.num_of_chats())
# Get recent chats
pprint(chat.chat_list(limit=3))
# Continue a specific chat
chat_id = "xxx" # Retrieved from above
newchat = chat.chat_by_id(chat_id)
newchat.ask("ok, let's continue")
```
74 changes: 64 additions & 10 deletions README.md
@@ -1,18 +1,72 @@
# WebChatter

[![image](https://img.shields.io/pypi/v/webchatter.svg)](https://pypi.python.org/pypi/webchatter)
[English](README-EN.md) | [简体中文](README.md)

Wrapper of the web server of ChatGPT
[![PyPI version](https://img.shields.io/pypi/v/webchatter.svg)](https://pypi.python.org/pypi/webchatter)
[![Tests](https://github.com/cubenlp/webchatter/actions/workflows/test.yml/badge.svg)](https://github.com/cubenlp/webchatter/actions/workflows/test.yml/)
[![Documentation Status](https://img.shields.io/badge/docs-github_pages-blue.svg)](https://apicall.wzhecnu.cn)
[![Coverage](https://codecov.io/gh/cubenlp/webchatter/branch/main/graph/badge.svg)](https://codecov.io/gh/cubenlp/webchatter)

- Free software: MIT license

## Features
## 特性

- TODO
基于 AccessToken 的 Chat 封装,可用于数据标注。

## Credits
## 安装

This package was created with
[Cookiecutter](https://github.com/audreyr/cookiecutter) and the
[audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage)
project template.
```bash
pip install webchatter --upgrade
```

设置环境变量
```bash
export OPENAI_ACCESS_TOKEN="your_access_token"
export API_REVERSE_PROXY="http://your_reverse_proxy"
export WEB_REVERSE_PROXY="http://your_reverse_proxy/backend-api"
```

其中 `OPENAI_ACCESS_TOKEN` 可在登录会话后,访问网站 [/api/auth/session](https://chat.openai.com/api/auth/session) 得到,反向代理可以参考 [ninja 项目](https://github.com/gngpp/ninja/)进行构建。

## 基本使用

数据标注示例,计算加法:
```py
from webchatter import process_messages
from random import randint

msgs = [f"find the result of {randint(3, 100)} + {randint(4, 100)}" for _ in range(4)]
# 标注一部分后被中断
process_messages(msgs[:2], "test.jsonl")
# 继续标注
process_messages(msgs, "test.jsonl")
```

常规使用:

```py
from webchatter import WebChat

# 创建对话
chat = WebChat()
# 输入问题 | 返回答案
chat.ask("hello world!")
# 获取对话历史
chat.print_log()
```

其他用法:

```py
from webchatter import WebChat
from pprint import pprint
chat = WebChat()

# 查看 web 对话总数
pprint(chat.num_of_chats())
# 获取近期对话
pprint(chat.chat_list(limit=3))
# 继续某个对话
chat_id = "xxx" # 从前边获取
newchat = chat.chat_by_id(chat_id)
newchat.ask("ok, let's continue")
```

0 comments on commit f56ec79

Please sign in to comment.