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

fix: provider endpoint and mux section #275

Merged
merged 14 commits into from
Feb 7, 2025
Merged
32 changes: 30 additions & 2 deletions src/api/generated/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,28 @@ export type AddProviderEndpointRequest = {
description?: string;
provider_type: ProviderType;
endpoint?: string;
auth_type?: ProviderAuthType | null;
auth_type?: ProviderAuthType;
api_key?: string | null;
};

/**
* Represents an alert.
*/
export type Alert = {
id: string;
prompt_id: string;
code_snippet: CodeSnippet | null;
trigger_string:
| string
| {
[key: string]: unknown;
}
| null;
trigger_type: string;
trigger_category: string | null;
timestamp: string;
};

/**
* Represents an alert with it's respective conversation.
*/
Expand Down Expand Up @@ -50,11 +68,19 @@ export type ChatMessage = {
message_id: string;
};

/**
* Represents a code snippet with its programming language.
*
* Args:
* language: The programming language identifier (e.g., 'python', 'javascript')
* code: The actual code content
*/
export type CodeSnippet = {
code: string;
language: string | null;
filepath: string | null;
libraries?: Array<string>;
file_extension?: string | null;
};

/**
Expand All @@ -75,6 +101,7 @@ export type Conversation = {
chat_id: string;
conversation_timestamp: string;
token_usage_agg: TokenUsageAggregate | null;
alerts?: Array<Alert>;
};

export type CreateOrRenameWorkspaceRequest = {
Expand Down Expand Up @@ -146,7 +173,7 @@ export type ProviderEndpoint = {
description?: string;
provider_type: ProviderType;
endpoint?: string;
auth_type?: ProviderAuthType | null;
auth_type?: ProviderAuthType;
};

/**
Expand All @@ -159,6 +186,7 @@ export enum ProviderType {
OLLAMA = "ollama",
LM_STUDIO = "lm_studio",
LLAMACPP = "llamacpp",
OPENROUTER = "openrouter",
}

/**
Expand Down
114 changes: 95 additions & 19 deletions src/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1145,14 +1145,7 @@
"default": ""
},
"auth_type": {
"anyOf": [
{
"$ref": "#/components/schemas/ProviderAuthType"
},
{
"type": "null"
}
],
"$ref": "#/components/schemas/ProviderAuthType",
"default": "none"
},
"api_key": {
Expand All @@ -1175,6 +1168,74 @@
"title": "AddProviderEndpointRequest",
"description": "Represents a request to add a provider endpoint."
},
"Alert": {
"properties": {
"id": {
"type": "string",
"title": "Id"
},
"prompt_id": {
"type": "string",
"title": "Prompt Id"
},
"code_snippet": {
"anyOf": [
{
"$ref": "#/components/schemas/CodeSnippet"
},
{
"type": "null"
}
]
},
"trigger_string": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
},
{
"type": "null"
}
],
"title": "Trigger String"
},
"trigger_type": {
"type": "string",
"title": "Trigger Type"
},
"trigger_category": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Trigger Category"
},
"timestamp": {
"type": "string",
"format": "date-time",
"title": "Timestamp"
}
},
"type": "object",
"required": [
"id",
"prompt_id",
"code_snippet",
"trigger_string",
"trigger_type",
"trigger_category",
"timestamp"
],
"title": "Alert",
"description": "Represents an alert."
},
"AlertConversation": {
"properties": {
"conversation": {
Expand Down Expand Up @@ -1300,7 +1361,19 @@
"type": "string"
},
"type": "array",
"title": "Libraries"
"title": "Libraries",
"default": []
},
"file_extension": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "File Extension"
}
},
"type": "object",
Expand All @@ -1309,7 +1382,8 @@
"language",
"filepath"
],
"title": "CodeSnippet"
"title": "CodeSnippet",
"description": "Represents a code snippet with its programming language.\n\nArgs:\n language: The programming language identifier (e.g., 'python', 'javascript')\n code: The actual code content"
},
"ConfigureAuthMaterial": {
"properties": {
Expand Down Expand Up @@ -1376,6 +1450,14 @@
"type": "null"
}
]
},
"alerts": {
"items": {
"$ref": "#/components/schemas/Alert"
},
"type": "array",
"title": "Alerts",
"default": []
}
},
"type": "object",
Expand Down Expand Up @@ -1580,14 +1662,7 @@
"default": ""
},
"auth_type": {
"anyOf": [
{
"$ref": "#/components/schemas/ProviderAuthType"
},
{
"type": "null"
}
],
"$ref": "#/components/schemas/ProviderAuthType",
"default": "none"
}
},
Expand All @@ -1607,7 +1682,8 @@
"vllm",
"ollama",
"lm_studio",
"llamacpp"
"llamacpp",
"openrouter"
],
"title": "ProviderType",
"description": "Represents the different types of providers we support."
Expand Down
25 changes: 20 additions & 5 deletions src/features/providers/components/provider-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from "@stacklok/ui-kit";
import {
getAuthTypeOptions,
getProviderAuthByType,
getProviderEndpointByAuthType,
getProviderType,
isProviderAuthType,
isProviderType,
Expand All @@ -19,6 +21,19 @@ interface Props {
}

export function ProviderForm({ provider, setProvider }: Props) {
const providerAuthType =
provider.auth_type || getProviderAuthByType(provider.provider_type);
const providerEndpoint =
provider.endpoint || getProviderEndpointByAuthType(provider.provider_type);

const handleProviderType = (provider: AddProviderEndpointRequest) => {
setProvider({
...provider,
auth_type: getProviderAuthByType(provider.provider_type),
endpoint: getProviderEndpointByAuthType(provider.provider_type),
});
};

return (
<div className="w-full">
<div className="">
Expand All @@ -45,7 +60,7 @@ export function ProviderForm({ provider, setProvider }: Props) {
items={getProviderType()}
onSelectionChange={(provider_type) => {
if (isProviderType(provider_type)) {
setProvider({
handleProviderType({
...provider,
provider_type,
});
Expand Down Expand Up @@ -78,15 +93,15 @@ export function ProviderForm({ provider, setProvider }: Props) {
onChange={(endpoint) => setProvider({ ...provider, endpoint })}
>
<Label>Endpoint</Label>
<Input placeholder="Provider endpoint" value={provider.endpoint} />
<Input placeholder="Provider endpoint" value={providerEndpoint} />
</TextField>
</div>
<div className="py-3">
<Label id="provider-authentication">Authentication</Label>
<Select
aria-labelledby="provider auth type"
name="auth_type"
selectedKey={provider.auth_type}
selectedKey={providerAuthType}
isRequired
className="w-full"
placeholder="Select the authentication type"
Expand All @@ -101,7 +116,7 @@ export function ProviderForm({ provider, setProvider }: Props) {
</Select>
</div>

{provider.auth_type === ProviderAuthType.API_KEY && (
{providerAuthType === ProviderAuthType.API_KEY && (
<div className="pt-4">
<TextField
aria-label="Provider API key"
Expand All @@ -111,7 +126,7 @@ export function ProviderForm({ provider, setProvider }: Props) {
isRequired
onChange={(api_key) => setProvider({ ...provider, api_key })}
>
<Label>Api key</Label>
<Label>API key</Label>
<Input
placeholder={
provider.api_key === undefined
Expand Down
53 changes: 0 additions & 53 deletions src/features/providers/components/table-actions.tsx

This file was deleted.

Loading
Loading