chore: generic_prox ux
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { GPUSTACK_API, OPENAI_COMPATIBLE } from '../apis';
|
||||
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
|
||||
|
||||
export const speechToTextCode = ({
|
||||
export const generateSpeechToTextCurlCode = ({
|
||||
api: url,
|
||||
modelProxy,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
@@ -13,12 +14,26 @@ export const speechToTextCode = ({
|
||||
const curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: multipart/form-data" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||
-F file="@/path/to/file/audio.mp3;type=audio/mpeg" \\
|
||||
${formatCurlArgs(parameters, true)}`
|
||||
.trim()
|
||||
.replace(/\\$/g, '');
|
||||
|
||||
return curlCode;
|
||||
};
|
||||
|
||||
export const speechToTextCode = ({
|
||||
api: url,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
// replace url OPENAI_COMPATIBLE with GPUSTACK
|
||||
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
|
||||
|
||||
// ========================= Curl =========================
|
||||
const curlCode = generateSpeechToTextCurlCode({ api: url, parameters });
|
||||
|
||||
// ========================= Python =========================
|
||||
const pythonCode = `
|
||||
from openai import OpenAI\n
|
||||
@@ -67,8 +82,9 @@ main();`.trim();
|
||||
};
|
||||
};
|
||||
|
||||
export const TextToSpeechCode = ({
|
||||
export const generateTextToSpeechCurlCode = ({
|
||||
api: url,
|
||||
modelProxy,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
@@ -78,9 +94,22 @@ export const TextToSpeechCode = ({
|
||||
const curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||
${formatCurlArgs(parameters, false)} \\\n--output output.${parameters.response_format}`.trim();
|
||||
|
||||
return curlCode;
|
||||
};
|
||||
|
||||
export const TextToSpeechCode = ({
|
||||
api: url,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
|
||||
|
||||
// ========================= Curl =========================
|
||||
const curlCode = generateTextToSpeechCurlCode({ api: url, parameters });
|
||||
|
||||
// ========================= Python =========================
|
||||
const pythonCode = `
|
||||
from pathlib import Path
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { GPUSTACK_API, OPENAI_COMPATIBLE } from '../apis';
|
||||
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
|
||||
|
||||
export const generateEmbeddingCode = ({
|
||||
export const generateEmbeddingCurlCode = ({
|
||||
api: url,
|
||||
modelProxy,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
@@ -12,9 +13,22 @@ export const generateEmbeddingCode = ({
|
||||
const curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||
${formatCurlArgs(parameters, false)}`.trim();
|
||||
|
||||
return curlCode;
|
||||
};
|
||||
|
||||
export const generateEmbeddingCode = ({
|
||||
api: url,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
|
||||
|
||||
// ========================= Curl =========================
|
||||
const curlCode = generateEmbeddingCurlCode({ api: url, parameters });
|
||||
|
||||
// ========================= Python =========================
|
||||
const pythonCode = `
|
||||
from openai import OpenAI\n
|
||||
|
||||
@@ -2,6 +2,38 @@ import _ from 'lodash';
|
||||
import { GPUSTACK_API, OPENAI_COMPATIBLE } from '../apis';
|
||||
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
|
||||
|
||||
export const generateImageCurlCode = ({
|
||||
api: url,
|
||||
parameters,
|
||||
modelProxy,
|
||||
isFormdata = false,
|
||||
edit = false
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
|
||||
|
||||
// ========================= Curl =========================
|
||||
let curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||
${formatCurlArgs(parameters, isFormdata)}`.trim();
|
||||
|
||||
if (edit) {
|
||||
curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: multipart/form-data" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||
-F image="@image.png" \\
|
||||
-F mask="@mask.png" \\
|
||||
${formatCurlArgs(_.omit(parameters, ['mask', 'image']), isFormdata)}`
|
||||
.trim()
|
||||
.replace(/\\$/, '');
|
||||
}
|
||||
|
||||
return curlCode;
|
||||
};
|
||||
|
||||
export const generateImageCode = ({
|
||||
api: url,
|
||||
parameters,
|
||||
@@ -12,23 +44,12 @@ export const generateImageCode = ({
|
||||
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
|
||||
|
||||
// ========================= Curl =========================
|
||||
let curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
|
||||
${formatCurlArgs(parameters, isFormdata)}`.trim();
|
||||
|
||||
if (edit) {
|
||||
curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: multipart/form-data" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
|
||||
-F image="@image.png" \\
|
||||
-F mask="@mask.png" \\
|
||||
${formatCurlArgs(_.omit(parameters, ['mask', 'image']), isFormdata)}`
|
||||
.trim()
|
||||
.replace(/\\$/, '');
|
||||
}
|
||||
let curlCode = generateImageCurlCode({
|
||||
api: url,
|
||||
parameters,
|
||||
isFormdata,
|
||||
edit
|
||||
});
|
||||
|
||||
// ========================= Python =========================
|
||||
const pythonCode = `
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { GPUSTACK_API, OPENAI_COMPATIBLE } from '../apis';
|
||||
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
|
||||
|
||||
export const generateLLMCode = ({
|
||||
export const generateLLmCurlCode = ({
|
||||
api: url,
|
||||
modelProxy,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
@@ -12,9 +13,22 @@ export const generateLLMCode = ({
|
||||
const curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||
${formatCurlArgs(parameters, false)}`.trim();
|
||||
|
||||
return curlCode;
|
||||
};
|
||||
|
||||
export const generateLLMCode = ({
|
||||
api: url,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
|
||||
|
||||
// ========================= Curl =========================
|
||||
const curlCode = generateLLmCurlCode({ api: url, parameters });
|
||||
|
||||
// ========================= Python =========================
|
||||
const pythonCode = `
|
||||
from openai import OpenAI\n
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { formatCurlArgs } from './utils';
|
||||
|
||||
export const generateRerankCode = ({
|
||||
export const generateRerankCurlCode = ({
|
||||
api,
|
||||
modelProxy,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
@@ -10,9 +11,21 @@ export const generateRerankCode = ({
|
||||
const curlCode = `
|
||||
curl ${host}${api} \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\
|
||||
-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\${modelProxy ? `\n-H "X-GPUStack-Model: ${parameters.model}" \\` : ''}
|
||||
${formatCurlArgs(parameters, false)}`.trim();
|
||||
|
||||
return curlCode;
|
||||
};
|
||||
|
||||
export const generateRerankCode = ({
|
||||
api,
|
||||
parameters
|
||||
}: Record<string, any>) => {
|
||||
const host = window.location.origin;
|
||||
|
||||
// ========================= Curl =========================
|
||||
const curlCode = generateRerankCurlCode({ api, parameters });
|
||||
|
||||
// ========================= Python =========================
|
||||
const pythonCode = `
|
||||
import requests\n
|
||||
|
||||
Reference in New Issue
Block a user