Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support request headers template #4418

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/types/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type Engines = {

export type EngineMetadata = {
get_models_url?: string
api_key_template?: string
header_template?: string
transform_req?: {
chat_completions?: {
url?: string
Expand Down
2 changes: 1 addition & 1 deletion web/containers/ModelDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const ModelDropdown = ({
.filter((e) => {
if (searchFilter === 'local') {
return (
engineList.find((t) => t.engine.engine === e.engine)?.type ===
engineList.find((t) => t.engine?.engine === e.engine)?.type ===
'local'
)
}
Expand Down
40 changes: 20 additions & 20 deletions web/screens/Settings/Engines/ModalAddRemoteEngine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const engineSchema = z.object({
engineName: z.string().min(1, 'Engine name is required'),
apiUrl: z.string().url('Enter a valid API URL'),
modelListUrl: z.string().url('Enter a valid Model List URL'),
apiKeyTemplate: z.string().optional(),
headerTemplate: z.string().optional(),
apiKey: z.string().optional(),
requestFormat: z.string().optional(),
responseFormat: z.string().optional(),
Expand All @@ -32,7 +32,7 @@ const ModalAddRemoteEngine = () => {
engineName: '',
apiUrl: '',
modelListUrl: '',
apiKeyTemplate: '',
headerTemplate: '',
apiKey: '',
requestFormat: '',
responseFormat: '',
Expand All @@ -46,7 +46,7 @@ const ModalAddRemoteEngine = () => {
engine: data.engineName,
api_key: data.apiKey,
metadata: {
api_key_template: data.apiKeyTemplate,
header_template: data.headerTemplate,
get_models_url: data.modelListUrl,
transform_req: {
chat_completions: {
Expand Down Expand Up @@ -148,37 +148,37 @@ const ModalAddRemoteEngine = () => {
</div>

<div className="space-y-2">
<label htmlFor="apiKeyTemplate" className="font-semibold">
<label htmlFor="apiKey" className="font-semibold">
{renderLabel(
'API Key Template',
'API Key',
false,
`Template for authorization header format.`
`Enter your authentication key to activate this engine.`
)}
</label>
<Input
placeholder="Enter API key template"
{...register('apiKeyTemplate')}
placeholder="Enter API Key"
type="password"
{...register('apiKey')}
/>
{errors.apiKeyTemplate && (
<p className="text-sm text-red-500">
{errors.apiKeyTemplate.message}
</p>
)}
</div>

<div className="space-y-2">
<label htmlFor="apiKey" className="font-semibold">
<label htmlFor="headerTemplate" className="font-semibold">
{renderLabel(
'API Key',
'Request Headers Template',
false,
`Enter your authentication key to activate this engine.`
`Template for request headers format.`
)}
</label>
<Input
placeholder="Enter API Key"
type="password"
{...register('apiKey')}
<TextArea
placeholder="Enter conversion function"
{...register('headerTemplate')}
/>
{errors.headerTemplate && (
<p className="text-sm text-red-500">
{errors.headerTemplate.message}
</p>
)}
</div>

<div className="space-y-2">
Expand Down
12 changes: 6 additions & 6 deletions web/screens/Settings/Engines/RemoteEngineSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,19 @@ const RemoteEngineSettings = ({
<div className="flex items-start justify-between gap-x-2">
<div className="w-full sm:w-3/4">
<h6 className="line-clamp-1 font-semibold">
API Key Template
Request Headers Template
</h6>
<p className="mt-1 text-[hsla(var(--text-secondary))]">
Template for authorization header format.
Template for request headers format.
</p>
</div>
<div className="w-full">
<Input
placeholder="Enter API key template"
value={engine?.metadata?.api_key_template}
<TextArea
placeholder="Enter headers template"
value={engine?.metadata?.header_template}
onChange={(e) =>
handleChange(
'metadata.api_key_template',
'metadata.header_template',
e.target.value
)
}
Expand Down
Loading