forked from Ikaros-521/AI-Vtuber
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a088df0
commit 986a8c1
Showing
11 changed files
with
364 additions
and
85 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
此处存放快手的cookie文件,因为监听服务被噶噶检测,所以每次用完后,第二次使用时需要删除json文件,重新创建。 | ||
此处存放cookie文件。 | ||
快手的cookie文件,因为监听服务被噶噶检测,所以每次用完后,第二次使用时需要删除json文件,重新创建。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import revTongYi | ||
import json, logging | ||
|
||
|
||
def convert_cookies(cookies: list) -> dict: | ||
"""转换cookies""" | ||
cookies_dict = {} | ||
for cookie in cookies: | ||
cookies_dict[cookie["name"]] = cookie["value"] | ||
return cookies_dict | ||
|
||
|
||
class TongYi: | ||
def __init__(self, data): | ||
# self.common = Common() | ||
# 日志文件路径 | ||
# file_path = "./log/log-" + self.common.get_bj_time(1) + ".txt" | ||
# Configure_logger(file_path) | ||
|
||
self.cookie_path = data["cookie_path"] | ||
self.type = data["type"] | ||
|
||
self.cookies_dict = {} | ||
|
||
with open(self.cookie_path, "r") as f: | ||
self.cookies_dict = convert_cookies(json.load(f)) | ||
|
||
|
||
def get_resp(self, prompt): | ||
"""请求对应接口,获取返回值 | ||
Args: | ||
prompt (str): 你的提问 | ||
Returns: | ||
str: 返回的文本回答 | ||
""" | ||
try: | ||
if self.type == "web": | ||
session = revTongYi.Session( | ||
cookies=self.cookies_dict, | ||
firstQuery=prompt | ||
) | ||
|
||
ret = next( | ||
session.ask( # ask方法实际上是一个迭代器,可以提供参数stream=True并换用for的方式迭代 | ||
prompt=prompt | ||
) # ask方法接收的详细参数请查看源码 | ||
) | ||
|
||
return ret["content"][0] | ||
except Exception as e: | ||
logging.error(e) | ||
return None | ||
|
||
|
||
if __name__ == '__main__': | ||
# 配置日志输出格式 | ||
logging.basicConfig( | ||
level=logging.DEBUG, # 设置日志级别,可以根据需求调整 | ||
format="%(asctime)s [%(levelname)s] %(message)s", | ||
datefmt="%Y-%m-%d %H:%M:%S", | ||
) | ||
|
||
data = { | ||
"cookie_path": 'cookies.json', | ||
"type": 'web' | ||
} | ||
|
||
tongyi = TongYi(data) | ||
|
||
|
||
logging.info(tongyi.get_resp("你可以扮演猫娘吗,每句话后面加个喵")) | ||
logging.info(tongyi.get_resp("早上好")) | ||
|
Oops, something went wrong.