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

feat: add workspace preferred model #217

Merged
merged 29 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
30428fb
feat(mux): wip model overrides workspace update
peppescg Jan 27, 2025
ad9b792
fetch providers from BE (currently mocked)
kantord Jan 27, 2025
548f25a
render multiple overrides
kantord Jan 27, 2025
e4d278d
fix form submit
kantord Jan 27, 2025
8e37995
feat: add/remove model ovveride row
peppescg Jan 28, 2025
19bb04f
add sorting feature
kantord Jan 28, 2025
e55e4c8
fix sortable partially
kantord Jan 28, 2025
338b55e
fix sorting
kantord Jan 28, 2025
a890f17
.
kantord Jan 28, 2025
1b8f319
fix scrolling
kantord Jan 28, 2025
9b30025
actually save filter to zustand store
kantord Jan 28, 2025
181a409
fix label
kantord Jan 28, 2025
f384ac9
fix label layout
kantord Jan 28, 2025
b896606
remove console logs
kantord Jan 28, 2025
3223141
remove unnecessary div
kantord Jan 28, 2025
b9d197b
extract <SortableArea />
kantord Jan 28, 2025
e1e5be5
use renderprop in <SortableArea />
kantord Jan 28, 2025
b3ebd85
simplify drag behavior
kantord Jan 28, 2025
8e49ea7
simplify folder structure
kantord Jan 28, 2025
7b4c0b8
fix: add key to array item
peppescg Jan 28, 2025
ce61b94
test: add workspace model override
peppescg Jan 28, 2025
f3315ca
fix: type
peppescg Jan 28, 2025
8788be5
fix: mock types
peppescg Jan 28, 2025
071baa3
chore: update api
peppescg Jan 29, 2025
efaea94
feat: add discard button
peppescg Jan 29, 2025
693c689
refactor: configure preferred model
peppescg Jan 29, 2025
fd8f2fa
hide preferred model section
peppescg Jan 29, 2025
0540f34
chore: update api
peppescg Jan 29, 2025
88588e7
refactor: notification message
peppescg Jan 29, 2025
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
Prev Previous commit
Next Next commit
chore: update api
peppescg committed Jan 29, 2025
commit 0540f34b8a2478c1ce1fdc26823c2a1dc8b74d5c
24 changes: 24 additions & 0 deletions src/api/generated/@tanstack/react-query.gen.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import {
v1GetProviderEndpoint,
v1UpdateProviderEndpoint,
v1DeleteProviderEndpoint,
v1ConfigureAuthMaterial,
v1ListWorkspaces,
v1CreateWorkspace,
v1ListActiveWorkspaces,
@@ -44,6 +45,9 @@ import type {
V1DeleteProviderEndpointData,
V1DeleteProviderEndpointError,
V1DeleteProviderEndpointResponse,
V1ConfigureAuthMaterialData,
V1ConfigureAuthMaterialError,
V1ConfigureAuthMaterialResponse,
V1CreateWorkspaceData,
V1CreateWorkspaceError,
V1CreateWorkspaceResponse,
@@ -293,6 +297,26 @@ export const v1DeleteProviderEndpointMutation = (
return mutationOptions;
};

export const v1ConfigureAuthMaterialMutation = (
options?: Partial<OptionsLegacyParser<V1ConfigureAuthMaterialData>>,
) => {
const mutationOptions: UseMutationOptions<
V1ConfigureAuthMaterialResponse,
V1ConfigureAuthMaterialError,
OptionsLegacyParser<V1ConfigureAuthMaterialData>
> = {
mutationFn: async (localOptions) => {
const { data } = await v1ConfigureAuthMaterial({
...options,
...localOptions,
throwOnError: true,
});
return data;
},
};
return mutationOptions;
};

export const v1ListWorkspacesQueryKey = (options?: OptionsLegacyParser) => [
createQueryKey("v1ListWorkspaces", options),
];
20 changes: 20 additions & 0 deletions src/api/generated/sdk.gen.ts
Original file line number Diff line number Diff line change
@@ -28,6 +28,9 @@ import type {
V1DeleteProviderEndpointData,
V1DeleteProviderEndpointError,
V1DeleteProviderEndpointResponse,
V1ConfigureAuthMaterialData,
V1ConfigureAuthMaterialError,
V1ConfigureAuthMaterialResponse,
V1ListWorkspacesError,
V1ListWorkspacesResponse,
V1CreateWorkspaceData,
@@ -218,6 +221,23 @@ export const v1DeleteProviderEndpoint = <ThrowOnError extends boolean = false>(
});
};

/**
* Configure Auth Material
* Configure auth material for a provider.
*/
export const v1ConfigureAuthMaterial = <ThrowOnError extends boolean = false>(
options: OptionsLegacyParser<V1ConfigureAuthMaterialData, ThrowOnError>,
) => {
return (options?.client ?? client).put<
V1ConfigureAuthMaterialResponse,
V1ConfigureAuthMaterialError,
ThrowOnError
>({
...options,
url: "/api/v1/provider-endpoints/{provider_id}/auth-material",
});
};

/**
* List Workspaces
* List all workspaces.
25 changes: 22 additions & 3 deletions src/api/generated/types.gen.ts
Original file line number Diff line number Diff line change
@@ -44,6 +44,14 @@ export type CodeSnippet = {
libraries?: Array<string>;
};

/**
* Represents a request to configure auth material for a provider.
*/
export type ConfigureAuthMaterial = {
auth_type: ProviderAuthType;
api_key?: string | null;
};

/**
* Represents a conversation.
*/
@@ -100,10 +108,10 @@ export enum MuxMatcherType {
* Represents a mux rule for a provider.
*/
export type MuxRule = {
provider: string;
provider_id: string;
model: string;
matcher_type: MuxMatcherType;
matcher: string | null;
matcher?: string | null;
};

/**
@@ -126,7 +134,7 @@ export type ProviderEndpoint = {
description?: string;
provider_type: ProviderType;
endpoint: string;
auth_type: ProviderAuthType;
auth_type?: ProviderAuthType | null;
};

/**
@@ -263,6 +271,17 @@ export type V1DeleteProviderEndpointResponse = unknown;

export type V1DeleteProviderEndpointError = HTTPValidationError;

export type V1ConfigureAuthMaterialData = {
body: ConfigureAuthMaterial;
path: {
provider_id: string;
};
};

export type V1ConfigureAuthMaterialResponse = void;

export type V1ConfigureAuthMaterialError = HTTPValidationError;

export type V1ListWorkspacesResponse = ListWorkspacesResponse;

export type V1ListWorkspacesError = unknown;
94 changes: 86 additions & 8 deletions src/api/openapi.json
Original file line number Diff line number Diff line change
@@ -336,6 +336,54 @@
}
}
},
"/api/v1/provider-endpoints/{provider_id}/auth-material": {
"put": {
"tags": [
"CodeGate API",
"Providers"
],
"summary": "Configure Auth Material",
"description": "Configure auth material for a provider.",
"operationId": "v1_configure_auth_material",
"parameters": [
{
"name": "provider_id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"title": "Provider Id"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ConfigureAuthMaterial"
}
}
}
},
"responses": {
"204": {
"description": "Successful Response"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/v1/workspaces": {
"get": {
"tags": [
@@ -1201,6 +1249,30 @@
],
"title": "CodeSnippet"
},
"ConfigureAuthMaterial": {
"properties": {
"auth_type": {
"$ref": "#/components/schemas/ProviderAuthType"
},
"api_key": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Api Key"
}
},
"type": "object",
"required": [
"auth_type"
],
"title": "ConfigureAuthMaterial",
"description": "Represents a request to configure auth material for a provider."
},
"Conversation": {
"properties": {
"question_answers": {
@@ -1373,9 +1445,9 @@
},
"MuxRule": {
"properties": {
"provider": {
"provider_id": {
"type": "string",
"title": "Provider"
"title": "Provider Id"
},
"model": {
"type": "string",
@@ -1398,10 +1470,9 @@
},
"type": "object",
"required": [
"provider",
"provider_id",
"model",
"matcher_type",
"matcher"
"matcher_type"
],
"title": "MuxRule",
"description": "Represents a mux rule for a provider."
@@ -1447,15 +1518,22 @@
"title": "Endpoint"
},
"auth_type": {
"$ref": "#/components/schemas/ProviderAuthType"
"anyOf": [
{
"$ref": "#/components/schemas/ProviderAuthType"
},
{
"type": "null"
}
],
"default": "none"
}
},
"type": "object",
"required": [
"name",
"provider_type",
"endpoint",
"auth_type"
"endpoint"
],
"title": "ProviderEndpoint",
"description": "Represents a provider's endpoint configuration. This\nallows us to persist the configuration for each provider,\nso we can use this for muxing messages."
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ export function WorkspacePreferredModel({
const { preferredModel, setPreferredModel } = usePreferredModelWorkspace();
const { mutateAsync } = useMutationPreferredModelWorkspace();
const { data: providerModels = [] } = useModelsData();
const { model, provider } = preferredModel;
const { model, provider_id } = preferredModel;

const handleSubmit = (event: FormEvent) => {
event.preventDefault();
@@ -35,7 +35,7 @@ export function WorkspacePreferredModel({
body: [
{
matcher: "",
provider,
provider_id,
model,
matcher_type: MuxMatcherType.CATCH_ALL,
},
@@ -69,7 +69,7 @@ export function WorkspacePreferredModel({
if (preferredModelProvider) {
setPreferredModel({
model: preferredModelProvider.name,
provider: preferredModelProvider.provider_id,
provider_id: preferredModelProvider.provider_id,
});
}
}}
6 changes: 3 additions & 3 deletions src/features/workspace/hooks/use-preferred-preferred-model.ts
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ type State = {

export const usePreferredModelWorkspace = create<State>((set) => ({
preferredModel: {
provider: "",
provider_id: "",
model: "",
},
setPreferredModel: ({ model, provider }: ModelRule) => {
set({ preferredModel: { provider, model } });
setPreferredModel: ({ model, provider_id }: ModelRule) => {
set({ preferredModel: { provider_id, model } });
},
}));
4 changes: 2 additions & 2 deletions src/mocks/msw/handlers.ts
Original file line number Diff line number Diff line change
@@ -96,13 +96,13 @@ export const handlers = [
http.get("*/api/v1/workspaces/:workspace_name/muxes", () =>
HttpResponse.json([
{
provider: "openai",
provider_id: "openai",
model: "gpt-3.5-turbo",
matcher_type: "file_regex",
matcher: ".*\\.txt",
},
{
provider: "anthropic",
provider_id: "anthropic",
model: "davinci",
matcher_type: "catch_all",
},

Unchanged files with check annotations Beta

ChatBubbleAvatar,
ChatBubbleMessage,
ChatBubbleTimestamp,
chatBubbleVariant,

Check warning on line 199 in src/components/ui/chat/chat-bubble.tsx

GitHub Actions / Static Checks / ESLint Check

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
chatBubbleMessageVariants,

Check warning on line 200 in src/components/ui/chat/chat-bubble.tsx

GitHub Actions / Static Checks / ESLint Check

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
ChatBubbleAction,
ChatBubbleActionWrapper,
};
SidebarMenuSkeleton,
SidebarProvider,
SidebarTrigger,
useSidebar,

Check warning on line 551 in src/components/ui/sidebar.tsx

GitHub Actions / Static Checks / ESLint Check

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
};
confirm: (message: ReactNode, config: Config) => Promise<boolean>;
};
export const ConfirmContext = createContext<ConfirmContextType | null>(null);

Check warning on line 37 in src/context/confirm-context.tsx

GitHub Actions / Static Checks / ESLint Check

Fast refresh only works when a file only exports components. Move your React context(s) to a separate file
export function ConfirmProvider({ children }: { children: ReactNode }) {
const [activeQuestion, setActiveQuestion] = useState<Question | null>(null);
</TestQueryClientProvider>,
);
export * from "@testing-library/react";

Check warning on line 67 in src/lib/test-utils.tsx

GitHub Actions / Static Checks / ESLint Check

This rule can't verify that `export *` only exports components
export { renderWithProviders as render };

Check warning on line 69 in src/lib/test-utils.tsx

GitHub Actions / Static Checks / ESLint Check

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components