优化
This commit is contained in:
parent
2af0637d09
commit
66d149675e
@ -1,10 +1,12 @@
|
|||||||
|
import json
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from dashscope.audio.asr import Transcription
|
from dashscope.audio.asr import Transcription
|
||||||
import dashscope
|
import dashscope
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
|
from openai import OpenAI
|
||||||
|
|
||||||
dashscope.api_key = os.getenv("ENVIRONMENT", "DASHSCOPE_API_KEY")
|
dashscope.api_key = os.getenv("DASHSCOPE_API_KEY","*****")
|
||||||
|
|
||||||
|
|
||||||
def music_analysis(music_url):
|
def music_analysis(music_url):
|
||||||
@ -38,5 +40,33 @@ def music_analysis(music_url):
|
|||||||
print(f"请求失败,状态码:{response.status_code}")
|
print(f"请求失败,状态码:{response.status_code}")
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def chat_analysis(video_url):
|
||||||
|
text=''
|
||||||
|
client = OpenAI(
|
||||||
|
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
|
||||||
|
api_key=os.getenv("DASHSCOPE_API_KEY","*****"),
|
||||||
|
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||||||
|
)
|
||||||
|
completion = client.chat.completions.create(
|
||||||
|
model="qwen-plus",
|
||||||
|
# 此处以qwen-plus为例,可按需更换模型名称。模型列表:https://help.aliyun.com/zh/model-studio/getting-started/models
|
||||||
|
messages=[
|
||||||
|
{
|
||||||
|
'role': 'system',
|
||||||
|
'content': """
|
||||||
|
将文本的链接提取出来,只留链接的有效信息
|
||||||
|
# 输出
|
||||||
|
只输出链接不需要分析过程
|
||||||
|
"""
|
||||||
|
},
|
||||||
|
{'role': 'user', 'content': video_url}],
|
||||||
|
)
|
||||||
|
|
||||||
|
print(completion.model_dump())
|
||||||
|
for choices in completion.model_dump()['choices']:
|
||||||
|
text+=choices['message']['content']
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
music_analysis('https://lf26-music-east.douyinstatic.com/obj/ies-music-hj/7494207652008839996.mp3')
|
# music_analysis('https://lf26-music-east.douyinstatic.com/obj/ies-music-hj/7494207652008839996.mp3')
|
||||||
|
chat_analysis('4.17 复制打开抖音,看看【三维地球科普的作品】河南省最奇怪的城市——信阳市 # 信阳市 # 河南... https://v.douyin.com/RBU9atEeafc/ AGI:/ i@p.QX 11/14 ')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user