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

Release a stable version #37

Merged
merged 11 commits into from
Aug 22, 2023
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
10 changes: 4 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,26 @@ on:

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.8, 3.9]

python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[test]
python -m pip install -r requirements_dev.txt

- name: Test with pytest and coverage
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_BASE_URL: ${{ secrets.OPENAI_API_BASE_URL }}
run: |
pip install coverage
coverage run -m pytest tests/
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
##### user defined ######
*.jsonl


##### seperated line ######

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
20 changes: 0 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ chat.save("chat_history.log", mode="w") # default to "a"
chat.print_log()
```

Moreover, you can check the usage status of the API key:

```py
# show usage status of the default API key
chat = Chat()
chat.show_usage_status()

# show usage status of the specified API key
chat.api_key = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
chat.show_usage_status()
```

### Advance usage

Save the chat history to a file:
Expand All @@ -171,14 +159,6 @@ Load the chat history from a file:
# load chats(default)
chats = load_chats(checkpoint)
assert chats == [Chat(log) for log in chat_logs]
# load chat log only
chat_logs = load_chats(checkpoint, chat_log_only=True)
assert chat_logs == [[], [{'role': 'user', 'content': 'hello!'}],
[{'role': 'user', 'content': 'hello!'},
{'role': 'assistant', 'content': '你好, how can I assist you today?'}]]
# load the last message only
chat_msgs = load_chats(checkpoint, last_message_only=True)
assert chat_msgs == ["", "hello!", "你好, how can I assist you today?"]
```

In general, one can create a function `msg2chat` and use `process_chats` to process the data:
Expand Down
17 changes: 0 additions & 17 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,6 @@ chat.save("chat_history.log", mode="w") # 默认为 "a"
chat.print_log()
```

此外,你可以使用 `Chat` 类的 `show_usage_status` 方法来查看 API 的使用情况:

```py
# 查看默认 API 的使用情况
chat = Chat()
chat.show_usage_status()

# 查看指定 API 的使用情况
chat.api_key = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
chat.show_usage_status()
```

### 进阶用法
将对话历史保存到文件中:

Expand All @@ -167,11 +155,6 @@ chat.save(checkpoint)
# 加载 Chat 对象(默认)
chats = load_chats(checkpoint)
assert chats == [Chat(log) for log in chat_logs]
# 仅加载对话历史
chat_logs = load_chats(checkpoint, chat_log_only=True)
# 仅加载最后一条消息
chat_msgs = load_chats(checkpoint, last_message_only=True)
assert chat_msgs == ["", "hello!", "你好, how can I assist you today?"]
```

一般来说,你可以定义函数 `msg2chat` 并使用 `process_chats` 来处理数据:
Expand Down
35 changes: 13 additions & 22 deletions openai_api_call/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__version__ = '0.6.0'

import os, requests
from .chattool import Chat, Resp, chat_completion, usage_status
from .chattool import Chat, Resp, chat_completion
from .checkpoint import load_chats, process_chats
from .proxy import proxy_on, proxy_off, proxy_status
from . import request
Expand Down Expand Up @@ -44,7 +44,7 @@ def show_base_url():
def debug_log( net_url:str="https://www.baidu.com"
, timeout:int=5
, message:str="hello world! 你好!"
, test_usage:bool=True
, test_apikey:bool=True
, test_response:bool=True
, test_model:bool=True):
"""Debug the API call
Expand All @@ -58,41 +58,32 @@ def debug_log( net_url:str="https://www.baidu.com"
Returns:
bool: True if the debug is finished.
"""
# 1. Test whether the network is available
# Network test
try:
requests.get(net_url, timeout=timeout)
except:
print("Warning: Network is not available.")
return False

print("Your network is available.")

# 2. Check the API key
print("\nPlease verify the API key:")
show_apikey()

# 3. Check the proxy status
print("\nYour proxy status:")
## Check the proxy status
print("\nPlease check your proxy:")
proxy_status()
print("Note that, you don't need to set proxy if your `base_url` has done it!")

# 4. Base url
## Base url
print("\nCheck your base url:")
show_base_url()
if request.url is not None:
print("Warning: the `url` parameter is deprecated, please use `base_url` instead.")

# 5. Get usage status
if test_usage:
print("\nThe usage status of your API key:")
Chat().show_usage_status(recent=3)

## Please check your API key
if test_apikey:
print("\nPlease verify your API key:")
show_apikey()

# 6. Get model list
# Get model list
if test_model:
print("\nThe model list:")
print(Chat().get_valid_models())

# 7. Test hello world
# Test hello world
if test_response:
print("\nTest message:", message)
chat = Chat(message)
Expand Down
Loading
Loading