fix: text to speech python code
This commit is contained in:
+1
-2
@@ -14,7 +14,7 @@ const isProduction = env === 'production';
|
|||||||
const t = Date.now();
|
const t = Date.now();
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
proxy: {
|
proxy: {
|
||||||
...proxy('http://192.168.50.4')
|
...proxy(process.env.PROXY_HOST)
|
||||||
},
|
},
|
||||||
history: {
|
history: {
|
||||||
type: 'hash'
|
type: 'hash'
|
||||||
@@ -23,7 +23,6 @@ export default defineConfig({
|
|||||||
analyzerMode: 'server',
|
analyzerMode: 'server',
|
||||||
analyzerPort: 8888,
|
analyzerPort: 8888,
|
||||||
openAnalyzer: true,
|
openAnalyzer: true,
|
||||||
// generate stats file while ANALYZE_DUMP exist
|
|
||||||
generateStatsFile: false,
|
generateStatsFile: false,
|
||||||
statsFilename: 'stats.json',
|
statsFilename: 'stats.json',
|
||||||
logLevel: 'info',
|
logLevel: 'info',
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export default {
|
|||||||
'playground.toolbar.compare6Model': '6 模型对比',
|
'playground.toolbar.compare6Model': '6 模型对比',
|
||||||
'playground.input.holder': '按 <kbd>/</kbd> 开始输入',
|
'playground.input.holder': '按 <kbd>/</kbd> 开始输入',
|
||||||
'playground.input.keyword.holder': '按 <kbd>/</kbd> 输入你的查询',
|
'playground.input.keyword.holder': '按 <kbd>/</kbd> 输入你的查询',
|
||||||
'playground.input.prompt.holder': '按 <kbd>/</kbd> 输入提示',
|
'playground.input.prompt.holder': '按 <kbd>/</kbd> 输入提示词',
|
||||||
'playground.input.text.holder': '按 <kbd>/</kbd> 输入文本',
|
'playground.input.text.holder': '按 <kbd>/</kbd> 输入文本',
|
||||||
'playground.compare.apply': '应用',
|
'playground.compare.apply': '应用',
|
||||||
'playground.compare.applytoall': '应用到所有模型',
|
'playground.compare.applytoall': '应用到所有模型',
|
||||||
@@ -76,7 +76,7 @@ export default {
|
|||||||
'playground.rerank.rank': '排序',
|
'playground.rerank.rank': '排序',
|
||||||
'playground.rerank.score': '分数',
|
'playground.rerank.score': '分数',
|
||||||
'playground.rerank.query.holder': '输入查询',
|
'playground.rerank.query.holder': '输入查询',
|
||||||
'playground.image.prompt': '输入提示',
|
'playground.image.prompt': '输入提示词',
|
||||||
'playground.audio.textinput': '输入文本',
|
'playground.audio.textinput': '输入文本',
|
||||||
'playground.audio.texttospeech': '文本转语音',
|
'playground.audio.texttospeech': '文本转语音',
|
||||||
'playground.audio.speechtotext': '语音转文本',
|
'playground.audio.speechtotext': '语音转文本',
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
''
|
''
|
||||||
);
|
);
|
||||||
const params = formatPyParams(payload);
|
const params = formatPyParams(payload);
|
||||||
const code = `from pathlib import Path\nfrom openai import OpenAI\n\nclient = OpenAI(\n base_url="${BaseURL}", \n api_key="YOUR_GPUSTACK_API_KEY"\n)\n\nouput_file_path = Path(__file__).parent\nresponse = client.${clientType}(\n${formattedParams}${params})\n${printLog}\nwith open(output_file_path, "wb") as f:
|
const code = `from pathlib import Path\nfrom openai import OpenAI\n\nclient = OpenAI(\n base_url="${BaseURL}", \n api_key="YOUR_GPUSTACK_API_KEY"\n)\n\noutput_file_path = Path(__file__).parent / "output.${parameters.response_format}"\nresponse = client.${clientType}(\n${formattedParams}${params})\n${printLog}\nwith open(output_file_path, "wb") as f:
|
||||||
for chunk in response.iter_bytes():
|
for chunk in response.iter_bytes():
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
const formatCurlArgs = (args: Record<string, any>, isFormdata?: boolean) => {
|
||||||
|
if (isFormdata) {
|
||||||
|
return _.keys(args).reduce((acc: string, key: string) => {
|
||||||
|
const value = args[key];
|
||||||
|
return acc + `-F ${key}="${value}" \\\n`;
|
||||||
|
}, '');
|
||||||
|
}
|
||||||
|
return `-d "${JSON.stringify(args)}" \\\n`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatPyParams = (params: Record<string, any>) => {};
|
||||||
|
|
||||||
|
export const speechToTextCode = ({
|
||||||
|
payload,
|
||||||
|
api,
|
||||||
|
parameters
|
||||||
|
}: Record<string, any>) => {
|
||||||
|
const host = window.location.origin;
|
||||||
|
const curlCode = `curl ${host}}${api} \
|
||||||
|
-H "Content-Type: multipart/form-data" \
|
||||||
|
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \
|
||||||
|
-F file="@/path/to/file/audio.mp3;type=audio/mpeg" \
|
||||||
|
-F model="${parameters.model}" \
|
||||||
|
-F language="${parameters.language}"`;
|
||||||
|
|
||||||
|
const pythonCode = `from openai import OpenAI
|
||||||
|
|
||||||
|
audio_file = open("audio.mp3", "rb")
|
||||||
|
client = OpenAI(
|
||||||
|
base_url="${host}/v1-openai",
|
||||||
|
api_key="YOUR_GPUSTACK_API_KEY"
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.audio.transcriptions.create(
|
||||||
|
model="${parameters.model}",
|
||||||
|
language="${parameters.language}",
|
||||||
|
file=audio_file
|
||||||
|
)
|
||||||
|
print('response:', response.text)`;
|
||||||
|
|
||||||
|
const nodeJsCode = `const fs = require("fs")
|
||||||
|
const OpenAI = require("openai");
|
||||||
|
|
||||||
|
const openai = new OpenAI({
|
||||||
|
"apiKey": "YOUR_GPUSTACK_API_KEY",
|
||||||
|
"baseURL": "${host}/v1-openai"
|
||||||
|
});
|
||||||
|
|
||||||
|
async function main(){
|
||||||
|
const params = {
|
||||||
|
"model": "faster-whisper-large-v3",
|
||||||
|
"language": "auto",
|
||||||
|
"file": fs.createReadStream("audio.mp3")
|
||||||
|
};
|
||||||
|
const response = await openai.audio.transcriptions.create(params);
|
||||||
|
console.log(response.text);
|
||||||
|
}
|
||||||
|
main();`;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user