From f56ec79ac7d62228d2a9f60df2f0801b3d49dbde Mon Sep 17 00:00:00 2001 From: rex <1073853456@qq.com> Date: Wed, 20 Dec 2023 20:43:05 +0800 Subject: [PATCH] udpate readme --- README-EN.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 74 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 README-EN.md diff --git a/README-EN.md b/README-EN.md new file mode 100644 index 0000000..051a01d --- /dev/null +++ b/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") +``` \ No newline at end of file diff --git a/README.md b/README.md index dd522eb..4784a83 100644 --- a/README.md +++ b/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") +```