我正在运行一个 LocalAI 服务器,它能够将语音翻译为文本。
使用这个curl命令,它可以正常工作:
curl http://localhost:8080/v1/audio/transcriptions -H "Content-Type: multipart/form-data" -F file="@/drive/test.ogg" -F model=ggml-small.bin
服务器输出是:
2:14PM DBG Request received: {"model":"ggml-small.bin","language":"","n":0,"top_p":0,"top_k":0,"temperature":0,"max_tokens":0,"echo":false,"batch":0,"f16":false,"ignore_eos":false,"repeat_penalty":0,"n_keep":0,"mirostat_eta":0,"mirostat_tau":0,"mirostat":0,"frequency_penalty":0,"tfz":0,"typical_p":0,"seed":0,"file":"","response_format":"","size":"","prompt":null,"instruction":"","input":null,"stop":null,"messages":null,"functions":null,"function_call":null,"stream":false,"mode":0,"step":0,"grammar":"","grammar_json_functions":null}
[127.0.0.1]:58298 200 - POST /v1/audio/transcriptions
所以我现在想做的是让我的基于 Qt 的程序发送相同的请求:
QHttpMultiPart *multiPart=new QHttpMultiPart(QHttpMultiPart::FormDataType);
multiPart->setBoundary("---------------------");
QNetworkRequest req(QUrl("http://localhost:8080/v1/audio/transcriptions"));
req.setHeader(QNetworkRequest::ContentTypeHeader,"multipart/form-data;boundary="+multiPart->boundary());
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=\"file\""));
filePart.setBody("\"@/drive/test.ogg\"");
QHttpPart modelPart;
modelPart.setHeader(QNetworkRequest::ContentDispositionHeader,QVariant("form-data;name=\"model\""));
modelPart.setBody("ggml-small.bin");
multiPart->append(filePart);
multiPart->append(modelPart);
QNetworkReply* r=context()->engine()->networkAccessManager()->post(req,multiPart);
...服务器回复:
2:20PM DBG Request received: {"model":"ggml-small.bin","language":"","n":0,"top_p":0,"top_k":0,"temperature":0,"max_tokens":0,"echo":false,"batch":0,"f16":false,"ignore_eos":false,"repeat_penalty":0,"n_keep":0,"mirostat_eta":0,"mirostat_tau":0,"mirostat":0,"frequency_penalty":0,"tfz":0,"typical_p":0,"seed":0,"file":"\"@/drive/test.ogg\"","response_format":"","size":"","prompt":null,"instruction":"","input":null,"stop":null,"messages":null,"functions":null,"function_call":null,"stream":false,"mode":0,"step":0,"grammar":"","grammar_json_functions":null}
[127.0.0.1]:57416 500 - POST /v1/audio/transcriptions
“Request returned”行中的唯一区别是在curl命令中回复“file:” 是一个空字符串(奇怪),但在 Qt 版本中它是
@/drive/test.ogg
..这就是它应该的样子。
LocalAI 需要 @ 符号才能工作,但我怀疑它是一个特殊字符,需要以某种方式进行翻译或转义。
我也不确定设置边界的确切作用,但如果没有它,服务器甚至不会打印任何输出。
有人可以帮忙吗?