这里主要讲解如何单独使用肥牛api的方式
需要肥牛API KEY 也就是需要你去顶部栏里面的 肥牛API密钥获取 API KEY
bert调用方式
# python
import requests
API_KEY = "sk-your-api-key-here" # 替换成你的肥牛API Key
GATEWAY_URL = "http://ominifn.natapp1.cc"
# 调用BERT
response = requests.post(
f"{GATEWAY_URL}/api/v1/bert/classify",
headers={"X-API-Key": API_KEY},
json={"text": "你看看我的屏幕"}
)
print(response.json())
TTS调用方式
# python
import requests
API_KEY = "sk-your-api-key-here"
GATEWAY_URL = "http://ominifn.natapp1.cc"
# 正确方式:GET请求 + 参数
response = requests.get(
f"{GATEWAY_URL}/api/v1/tts/synthesize",
headers={"X-API-Key": API_KEY},
params={
"text": "你好,这是要合成的文字。",
"text_language": "zh", # 中文
# 可选参数:
# "text_split_method": "cut5",
# "batch_size": 1,
# "speed_factor": 1.0,
# "top_k": 5,
# "top_p": 1,
# "temperature": 1
}
)
# 保存音频
with open("output.wav", "wb") as f:
f.write(response.content)
print("音频已保存!")
ASR调用方式
# python
import requests
API_KEY = "sk-your-api-key-here"
GATEWAY_URL = "http://ominifn.natapp1.cc"
# 上传音频文件识别
with open("audio.wav", "rb") as f:
response = requests.post(
f"{GATEWAY_URL}/api/v1/asr/upload_audio",
headers={"X-API-Key": API_KEY},
files={"file": f}
)
print(response.json())
实时识别
#python
import websockets
import asyncio
API_KEY = "sk-your-api-key-here"
async def asr_realtime():
uri = f"ws://ominifn.natapp1.cc/api/v1/asr/vad/ws?X-API-Key={API_KEY}"
async with websockets.connect(uri) as ws:
# 发送音频数据
with open("audio.wav", "rb") as f:
audio_data = f.read()
await ws.send(audio_data)
# 接收识别结果
result = await ws.recv()
print(result)
asyncio.run(asr_realtime())
RAG调用方式
# python
import requests
API_KEY = "sk-your-api-key-here"
GATEWAY_URL = "http://ominifn.natapp1.cc"
# 1. 文本编码
response = requests.post(
f"{GATEWAY_URL}/api/v1/rag/encode",
headers={"X-API-Key": API_KEY},
json={"text": "要编码的文本"}
)
print(response.json())
# 2. 相似度计算
response = requests.post(
f"{GATEWAY_URL}/api/v1/rag/similarity",
headers={"X-API-Key": API_KEY},
json={
"text1": "第一段文本",
"text2": "第二段文本"
}
)
print(response.json())
# 3. RAG问答 (最常用)
response = requests.post(
f"{GATEWAY_URL}/api/v1/rag/ask",
headers={"X-API-Key": API_KEY},
json={"question": "你的问题"}
)
print(response.json())
# 4. 健康检查
response = requests.get(
f"{GATEWAY_URL}/api/v1/rag/health",
headers={"X-API-Key": API_KEY}
)
print(response.json())