main
黄海 5 months ago
parent 06de3f0f74
commit 261cbaed8b

@ -1,47 +0,0 @@
# coding=utf-8
import requests
import json
from pathlib import Path
if __name__ == '__main__':
url = "https://infer-modelarts-cn-southwest-2.modelarts-infer.com/v1/infers/fd53915b-8935-48fe-be70-449d76c0fc87/v1/chat/completions"
API_KEY = 'WooxVHbV5-5nEuFJtMxaktMVo07Ic3iKbq_y4wHsjRvmSgbCehcGW62RmWLPvi_WoLzwpoNbCGmrksjSAlykGg'
# 读取文本文件内容
file_path = Path(r"D:\dsWork\QingLong\音频文本.txt")
if file_path.exists():
# 自动处理文件编码默认utf-8读取内容
content = file_path.read_text(encoding='utf-8')
else:
print(f"文件 {file_path} 不存在")
exit(0)
# Send request.
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer '+API_KEY
}
data = {
"model": "DeepSeek-V3",
"max_tokens": 20,
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "整理下面的JSON文件内容输出这段话共分几部分都是哪个时间开始的"+content}
],
# 是否开启流式推理, 默认为False, 表示不开启流式推理
"stream": False,
# 在流式输出时是否展示使用的token数目。只有当stream为True时改参数才会生效。
# "stream_options": { "include_usage": True },
# 控制采样随机性的浮点数,值较低时模型更具确定性,值较高时模型更具创造性。"0"表示贪婪取样。默认为1.0。
"temperature": 1.0
}
resp = requests.post(url, headers=headers, data=json.dumps(data), verify=False)
# Print result.
print(resp.status_code)
print(resp.text)

@ -1,20 +0,0 @@
import json
# 从外部文件读取 JSON 数据
file_path = r'D:\dsWork\QingLong\音频文本.txt' # 替换为你的文件路径
with open(file_path, 'r', encoding='utf-8') as file:
json_data = file.read()
# 解析 JSON 数据
data = json.loads(json_data)
# 提取 Text 属性并组装成文稿
text_content = [item['Text'] for item in data]
manuscript = ' '.join(text_content) # 将文本拼接成一个完整的文稿
# 输出或保存文稿
print(manuscript) # 打印到控制台
# 如果需要保存到文件
with open('文稿.txt', 'w', encoding='utf-8') as output_file:
output_file.write(manuscript)

@ -1,37 +0,0 @@
import os
from pathlib import Path
from openai import OpenAI
# pip install -U openai
API_KEY = "sk-01d13a39e09844038322108ecdbd1bbc"
client = OpenAI(
api_key=API_KEY, # 如果您没有配置环境变量请在此处替换您的API-KEY
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1", # 填写DashScope服务base_url
)
# 修改文件路径为原始字符串注意路径前的r
file_object = client.files.create(file=Path(r"D:\dsWork\QingLong\音频文本.txt"), purpose="file-extract")
print(file_object.id)
file_id = file_object.id
# 初始化messages列表
completion = client.chat.completions.create(
model="qwen-long",
messages=[
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'system', 'content': 'fileid://' + file_id},
{'role': 'user', 'content': '不要使用markdown格式输出只输出原文文字你的任务是按语义进行分段。'}
],
stream=True,
stream_options={"include_usage": True}
)
full_content = ""
for chunk in completion:
if chunk.choices and chunk.choices[0].delta.content:
# 拼接输出内容
full_content += chunk.choices[0].delta.content
#print(chunk.model_dump())
# 修改最后的打印语句(去掉大括号)
print(full_content)
Loading…
Cancel
Save