Skip to content

Commit

Permalink
Merge pull request #703 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
新增 自定义命令板块,实现API调用解析获取数据,能动性很高,所以也会有点安全风险
  • Loading branch information
Ikaros-521 committed Mar 18, 2024
2 parents 643748c + fb4e802 commit 9d7b7ae
Show file tree
Hide file tree
Showing 7 changed files with 525 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

`Luna AI` 是一款结合了最先进技术的虚拟AI主播。它的核心是一系列高效的人工智能模型,包括 `ChatterBot、GPT、Claude、langchain、chatglm、text-generation-webui、讯飞星火、智谱AI、谷歌Bard、文心一言、通义星尘、通义千问、千帆大模型、Gemini、Kimi Chat、QAnything、koboldcpp、FastGPT`。这些模型既可以在本地运行,也可以通过云端服务提供支持。当然,为了让对话照进现实,还结合了多模态模型,包括 `Gemini` 的图像识别能力,获取电脑画面进行分析讲解。

`Luna AI` 的外观由 `Live2D、Vtube Studio、xuniren、UE5 结合 Audio2Face、EasyAIVtuber、数字人视频播放器(Easy-Wav2Lip)` 技术打造,为用户提供了一个生动、互动的虚拟形象。这使得 `Luna AI` 能够在各大直播平台,如 `Bilibili、抖音、快手、微信视频号、斗鱼、YouTube、Twitch 和 TikTok`,进行实时互动直播。当然,它也可以在本地环境中与您进行个性化对话。
`Luna AI` 的外观由 `Live2D、Vtube Studio、xuniren、UE5 结合 Audio2Face、EasyAIVtuber、数字人视频播放器(Easy-Wav2Lip、Sadtalker、GeneFace++` 技术打造,为用户提供了一个生动、互动的虚拟形象。这使得 `Luna AI` 能够在各大直播平台,如 `Bilibili、抖音、快手、微信视频号、斗鱼、YouTube、Twitch 和 TikTok`,进行实时互动直播。当然,它也可以在本地环境中与您进行个性化对话。

为了使交流更加自然,`Luna AI` 使用了先进的自然语言处理技术,结合文本转语音系统,如 `Edge-TTS、VITS-Fast、elevenlabs、bark-gui、VALL-E-X、睿声AI、genshinvoice.top、tts.ai-lab.top、OpenVoice、GPT_SoVITS、clone-voice、Azure TTS、fish-speech`。这不仅让它能够生成流畅的回答,还可以通过 `so-vits-svc 和 DDSP-SVC` 实现声音的变化,以适应不同的场景和角色。

Expand Down
109 changes: 109 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"api_ip_port": "http://127.0.0.1:7888"
},
"digital_human_video_player": {
"type": "easy_wav2lip",
"api_ip_port": "http://127.0.0.1:8091"
},
"play_audio": {
Expand Down Expand Up @@ -1147,6 +1148,113 @@
}
]
},
"custom_cmd": {
"enable": false,
"type": "弹幕",
"config": [
{
"keywords": [
"天蝎座今日运势",
"天蝎座运势",
"天蝎运势"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/horoscope?type=scorpio&time=today",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['data']['fortunetext']['all']",
"resp_template": "{keyword}:{data}"
},
{
"keywords": [
"随机笑话",
"讲个笑话",
"来个笑话"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/joke",
"api_type": "GET",
"resp_data_type": "content",
"data_analysis": "resp",
"resp_template": "{data}"
},
{
"keywords": [
"随机情话",
"讲个情话",
"情话"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/love",
"api_type": "GET",
"resp_data_type": "content",
"data_analysis": "resp",
"resp_template": "{data}"
},
{
"keywords": [
"随机骚话",
"讲个骚话",
"骚话"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/sao",
"api_type": "GET",
"resp_data_type": "content",
"data_analysis": "resp",
"resp_template": "{data}"
},
{
"keywords": [
"疯狂星期四",
"星期四",
"KFC",
"kfc"
],
"similarity": 1.0,
"api_url": "https://api.shadiao.pro/kfc",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['data']['text']",
"resp_template": "{data}"
},
{
"keywords": [
"狗屁不通",
"gpbt"
],
"similarity": 1.0,
"api_url": "https://oiapi.net/API/Bullshit/?title=oiapi&length=200",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['message']",
"resp_template": "{data}"
},
{
"keywords": [
"网易热评",
"网易云热评"
],
"similarity": 1.0,
"api_url": "https://oiapi.net/API/NeteaseHotReviews",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['data']['content']",
"resp_template": "{data}"
},
{
"keywords": [
"发病"
],
"similarity": 1.0,
"api_url": "https://oiapi.net/API/SickL/",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['message']",
"resp_template": "{data}"
}
]
},
"translate": {
"enable": false,
"type": "baidu",
Expand Down Expand Up @@ -1334,6 +1442,7 @@
"play_audio": true,
"web_captions_printer": true,
"key_mapping": true,
"custom_cmd": true,
"trends_config": true,
"abnormal_alarm": true
},
Expand Down
109 changes: 109 additions & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"api_ip_port": "http://127.0.0.1:7888"
},
"digital_human_video_player": {
"type": "easy_wav2lip",
"api_ip_port": "http://127.0.0.1:8091"
},
"play_audio": {
Expand Down Expand Up @@ -1147,6 +1148,113 @@
}
]
},
"custom_cmd": {
"enable": false,
"type": "弹幕",
"config": [
{
"keywords": [
"天蝎座今日运势",
"天蝎座运势",
"天蝎运势"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/horoscope?type=scorpio&time=today",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['data']['fortunetext']['all']",
"resp_template": "{keyword}:{data}"
},
{
"keywords": [
"随机笑话",
"讲个笑话",
"来个笑话"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/joke",
"api_type": "GET",
"resp_data_type": "content",
"data_analysis": "resp",
"resp_template": "{data}"
},
{
"keywords": [
"随机情话",
"讲个情话",
"情话"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/love",
"api_type": "GET",
"resp_data_type": "content",
"data_analysis": "resp",
"resp_template": "{data}"
},
{
"keywords": [
"随机骚话",
"讲个骚话",
"骚话"
],
"similarity": 1.0,
"api_url": "https://api.vvhan.com/api/sao",
"api_type": "GET",
"resp_data_type": "content",
"data_analysis": "resp",
"resp_template": "{data}"
},
{
"keywords": [
"疯狂星期四",
"星期四",
"KFC",
"kfc"
],
"similarity": 1.0,
"api_url": "https://api.shadiao.pro/kfc",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['data']['text']",
"resp_template": "{data}"
},
{
"keywords": [
"狗屁不通",
"gpbt"
],
"similarity": 1.0,
"api_url": "https://oiapi.net/API/Bullshit/?title=oiapi&length=200",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['message']",
"resp_template": "{data}"
},
{
"keywords": [
"网易热评",
"网易云热评"
],
"similarity": 1.0,
"api_url": "https://oiapi.net/API/NeteaseHotReviews",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['data']['content']",
"resp_template": "{data}"
},
{
"keywords": [
"发病"
],
"similarity": 1.0,
"api_url": "https://oiapi.net/API/SickL/",
"api_type": "GET",
"resp_data_type": "json",
"data_analysis": "resp['message']",
"resp_template": "{data}"
}
]
},
"translate": {
"enable": false,
"type": "baidu",
Expand Down Expand Up @@ -1334,6 +1442,7 @@
"play_audio": true,
"web_captions_printer": true,
"key_mapping": true,
"custom_cmd": true,
"trends_config": true,
"abnormal_alarm": true
},
Expand Down
1 change: 1 addition & 0 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ async def digital_human_video_player_api(self, audio_path=""):
url = urljoin(self.config.get('digital_human_video_player', 'api_ip_port'), "/show")

data = {
"type": self.config.get('digital_human_video_player', 'type'),
"audio_path": os.path.abspath(audio_path),
"insert_index": -1
}
Expand Down
58 changes: 56 additions & 2 deletions utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,9 @@ def send_request(self, url, method='GET', json_data=None, resp_data_type="json",
headers = {'Content-Type': 'application/json'}

try:
if method == 'GET':
if method in ['GET', 'get']:
response = requests.get(url, headers=headers, timeout=timeout)
elif method == 'POST':
elif method in ['POST', 'post']:
response = requests.post(url, headers=headers, data=json.dumps(json_data), timeout=timeout)
else:
raise ValueError('无效 method. 支持的 methods 为 GET 和 POST.')
Expand All @@ -920,6 +920,8 @@ def send_request(self, url, method='GET', json_data=None, resp_data_type="json",
result = response.json()
else:
result = response.content
# 使用 'utf-8' 编码来解码字节串
result = result.decode('utf-8')

return result

Expand All @@ -928,6 +930,58 @@ def send_request(self, url, method='GET', json_data=None, resp_data_type="json",
logging.error(f"请求出错: {e}")
return None

async def send_async_request(self, url, method='GET', json_data=None, resp_data_type="json", timeout=60):
"""
发送异步 HTTP 请求并返回结果
Parameters:
url (str): 请求的 URL
method (str): 请求方法,'GET' 或 'POST'
json_data (dict): JSON 数据,用于 POST 请求
resp_data_type (str): 返回数据的类型(json | content)
timeout (int): 请求超时时间
Returns:
dict|str: 包含响应的 JSON数据 | 字符串数据
"""
import aiohttp

headers = {'Content-Type': 'application/json'}

try:
# 创建 aiohttp.ClientSession
async with aiohttp.ClientSession() as session:
if method in ['GET', 'get']:
async with session.get(url, headers=headers, timeout=timeout) as response:
# 检查请求是否成功
response.raise_for_status()

if resp_data_type == "json":
# 解析响应的 JSON 数据
result = await response.json()
else:
result = await response.read()

elif method in ['POST', 'post']:
async with session.post(url, headers=headers, data=json.dumps(json_data), timeout=timeout) as response:
# 检查请求是否成功
response.raise_for_status()

if resp_data_type == "json":
# 解析响应的 JSON 数据
result = await response.json()
else:
result = await response.read()

else:
raise ValueError('无效 method. 支持的 methods 为 GET 和 POST.')

return result

except aiohttp.ClientError as e:
logging.error("请求出错: %s", e)
return None

# 请求web字幕打印机
def send_to_web_captions_printer(self, api_ip_port, data):
"""请求web字幕打印机
Expand Down
Loading

0 comments on commit 9d7b7ae

Please sign in to comment.