Skip to content

Commit

Permalink
Merge pull request #25 from RexWzh/master
Browse files Browse the repository at this point in the history
Transfer the REPO to the CubeNLP LAB
  • Loading branch information
RexWzh authored May 16, 2023
2 parents 1231566 + 10031e7 commit 0692bcd
Showing 6 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@
# Openai API call
[![PyPI version](https://img.shields.io/pypi/v/openai_api_call.svg)](https://pypi.python.org/pypi/openai_api_call)
[![Tests](https://github.com/RexWzh/openai_api_call/actions/workflows/test.yml/badge.svg)](https://github.com/RexWzh/openai_api_call/actions/workflows/test.yml/)
[![Tests](https://github.com/cubenlp/openai_api_call/actions/workflows/test.yml/badge.svg)](https://github.com/cubenlp/openai_api_call/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/RexWzh/openai_api_call/branch/master/graph/badge.svg)](https://codecov.io/gh/RexWzh/openai_api_call.jl)
[![Coverage](https://codecov.io/gh/cubenlp/openai_api_call/branch/master/graph/badge.svg)](https://codecov.io/gh/cubenlp/openai_api_call.jl)

<!--
[![Updates](https://pyup.io/repos/github/RexWzh/openai_api_call/shield.svg)](https://pyup.io/repos/github/RexWzh/openai_api_call/)
[![Updates](https://pyup.io/repos/github/cubenlp/openai_api_call/shield.svg)](https://pyup.io/repos/github/cubenlp/openai_api_call/)
-->

A simple wrapper for OpenAI API, which can be used to send requests and get responses.
6 changes: 3 additions & 3 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# OpenAI API
[![PyPI version](https://img.shields.io/pypi/v/openai_api_call.svg)](https://pypi.python.org/pypi/openai_api_call)
[![Tests](https://github.com/RexWzh/openai_api_call/actions/workflows/test.yml/badge.svg)](https://github.com/RexWzh/openai_api_call/actions/workflows/test.yml/)
[![Tests](https://github.com/cubenlp/openai_api_call/actions/workflows/test.yml/badge.svg)](https://github.com/cubenlp/openai_api_call/actions/workflows/test.yml/)
[![Documentation Status](https://img.shields.io/badge/docs-github_pages-blue.svg)](https://apicall.wzhecnu.cn)

<!--
[![Updates](https://pyup.io/repos/github/RexWzh/openai_api_call/shield.svg)](https://pyup.io/repos/github/RexWzh/openai_api_call/)
[![Updates](https://pyup.io/repos/github/cubenlp/openai_api_call/shield.svg)](https://pyup.io/repos/github/cubenlp/openai_api_call/)
-->

OpenAI API 的简单封装,用于发送 prompt 并返回 response。
@@ -154,4 +154,4 @@ chat.show_usage_status()
- 版本 `0.2.0` 改用 `Chat` 类型作为中心交互对象
- 版本 `0.3.0` 开始不依赖模块 `openai.py` ,而是直接使用 `requests` 发送请求
- 支持对每个 `Chat` 使用不同 API 密钥
- 支持使用代理链接
- 支持使用代理链接
8 changes: 4 additions & 4 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -32,13 +32,13 @@ You can either clone the public repository:

.. code-block:: console
$ git clone git://github.com/RexWzh/openai_api_call
$ git clone git://github.com/cubenlp/openai_api_call
Or download the `tarball`_:

.. code-block:: console
$ curl -OJL https://github.com/RexWzh/openai_api_call/tarball/master
$ curl -OJL https://github.com/cubenlp/openai_api_call/tarball/master
Once you have a copy of the source, you can install it with:

@@ -47,5 +47,5 @@ Once you have a copy of the source, you can install it with:
$ python setup.py install
.. _Github repo: https://github.com/RexWzh/openai_api_call
.. _tarball: https://github.com/RexWzh/openai_api_call/tarball/master
.. _Github repo: https://github.com/cubenlp/openai_api_call
.. _tarball: https://github.com/cubenlp/openai_api_call/tarball/master
2 changes: 1 addition & 1 deletion openai_api_call/__init__.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

__author__ = """Rex Wang"""
__email__ = '1073853456@qq.com'
__version__ = '0.3.10'
__version__ = '0.4.0'

import os
from .chattool import Chat, Resp, chat_completion, usage_status
15 changes: 9 additions & 6 deletions openai_api_call/chattool.py
Original file line number Diff line number Diff line change
@@ -16,12 +16,12 @@ class Chat():
def __init__( self
, msg:Union[List[Dict], None, str]=None
, api_key:Union[None, str]=None) -> None:
"""Chat object
"""Initialize the chat log
Args:
msg (Union[List[Dict], None, str], optional): chat log. Defaults to None.
api_key (Union[None, str], optional): API key. Defaults to None.
Raises:
ValueError: msg should be a list of dict, a string or None
"""
@@ -144,10 +144,13 @@ def show_usage_status(self, thismonth:bool=True, recent:int=10, duration:int=99)
if thismonth:
duration = datetime.datetime.now().day - 1
storage, usage, rem, recent_usage = self.get_usage_status(recent=recent, duration=duration)
print(f"Total account: {storage:.4f}$")
print(f"Total usage(the last {len(recent_usage)} days): {usage:.4f}$")
print(f"Amount: {storage:.4f}$")
if thismonth:
print(f"Total remaining(this month): {rem:.4f}$")
print(f"Usage(this month): {usage:.4f}$")
print(f"Remaining(this month): {rem:.4f}$")
if len(recent_usage) > 0:
usage = sum(recent_usage.values())
print(f"Usage(the last {len(recent_usage)} days): {usage:.4f}$")
for date, cost in recent_usage.items():
print(f"{date}: {cost:.4f}$")

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
with open('README.md') as readme_file:
readme = readme_file.read()

VERSION = '0.3.10'
VERSION = '0.4.0'

requirements = ['Click>=7.0', 'requests>=2.20']

@@ -42,7 +42,7 @@
packages=find_packages(include=['openai_api_call', 'openai_api_call.*']),
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/RexWzh/openai_api_call',
url='https://github.com/cubenlp/openai_api_call',
version=VERSION,
zip_safe=False,
)

0 comments on commit 0692bcd

Please sign in to comment.