From 5cf750149986cf084d2d86a948b689ff21fd8d29 Mon Sep 17 00:00:00 2001 From: RankKCodeTalker <1073931273@qq.com> Date: Sun, 8 Oct 2023 00:20:15 +0800 Subject: [PATCH] update a lot --- myutils/gpt.py | 12 ++++++++++++ myutils/net.py | 11 +++++++++++ setup.py | 5 +++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 myutils/gpt.py create mode 100644 myutils/net.py diff --git a/myutils/gpt.py b/myutils/gpt.py new file mode 100644 index 0000000..a766f23 --- /dev/null +++ b/myutils/gpt.py @@ -0,0 +1,12 @@ +import openai +from typing import Literal + + +optional_models = Literal['gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-4', 'gpt-4-32k'] +def call_gpt(prompt: str, api_key: str, model: optional_models='gpt-3.5-turbo') -> str: + openai.api_key = api_key + completion = openai.ChatCompletion.create( + model=model, + messages=[{"role": "user", "content": prompt}] + ) + return completion.choices[0].message.content diff --git a/myutils/net.py b/myutils/net.py new file mode 100644 index 0000000..b20374f --- /dev/null +++ b/myutils/net.py @@ -0,0 +1,11 @@ +import os + + +def set_proxy(port: int=7890): + os.environ["http_proxy"] = f"http://127.0.0.1:{port}" + os.environ["https_proxy"] = f"http://127.0.0.1:{port}" + +def unset_proxy(): + os.environ.pop("http_proxy") + os.environ.pop("https_proxy") + diff --git a/setup.py b/setup.py index c1b6a03..3f70092 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="myutils", - version="1.0", + version="1.0.1.dev", author="Vichayturen", author_email="vichayturen@gmail.com", description="", @@ -11,7 +11,8 @@ url="", # 表明当前模块依赖哪些包,若环境中没有,则会从pypi中下载安装 install_requires=[ - 'pandas' + 'pandas', + 'openai' ], # 你要安装的包,通过 setuptools.find_packages 找到当前目录下有哪些包 packages=find_packages()