Skip to content

Commit

Permalink
refactor model selection
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Oct 1, 2024
1 parent c71f656 commit 6f762c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/aipane/AIPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ export interface AIPrompt {
user: string;
summary: string;
}

export interface AIModel {
id: string;
name: string;
default: boolean;
}
18 changes: 11 additions & 7 deletions src/aipane/components/HeroModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import * as React from "react";
import { Dropdown, Label, makeStyles, Option, useId } from "@fluentui/react-components";
import { useState, useEffect } from "react";
import config from "../../config.json"; // Assurez-vous que le chemin est correct
import type { AIModel } from "../AIPrompt";

interface HeroModelsProps {
onChange: (selectedValue: string) => void;
//readValue: () => string;
}

function getDefaultModel(): AIModel {
return config.models.filter((model: AIModel) => model.default)[0];
}
const useStyles = makeStyles({
root: {
// Stack the label above the field
Expand All @@ -31,11 +35,11 @@ const useStyles = makeStyles({
const HeroModels: React.FC<HeroModelsProps> = ({ onChange }) => {
const styles = useStyles();
const selectId = useId("select");
const [selectedValue, setSelectedValue] = useState<string>(config.models[0]);
const [selectedValue, setSelectedValue] = useState<string>(getDefaultModel().id);

const handleChange = (event: React.FormEvent<HTMLButtonElement>, option?: any) => {
event.preventDefault();
const newValue = option.nextOption?.text || config.models[0];
const newValue = option.nextOption?.value || getDefaultModel().id;
setSelectedValue(newValue);
onChange(newValue);
};
Expand All @@ -52,14 +56,14 @@ const HeroModels: React.FC<HeroModelsProps> = ({ onChange }) => {
<Dropdown
className={styles.combobox}
id={selectId}
defaultSelectedOptions={[config.models[0]]}
defaultValue={config.models[0]}
defaultSelectedOptions={[getDefaultModel().id]}
defaultValue={getDefaultModel().name}
onActiveOptionChange={handleChange}
onChange={handleChange}
>
{config.models.map((option) => (
<Option value={option} key={option}>
{option}
{config.models.map((option:AIModel) => (
<Option value={option.id} key={option.id}>
{option.name}
</Option>
))}
</Dropdown>
Expand Down
18 changes: 15 additions & 3 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"models": [
"llama-3.1-8b-instant",
"llama-3.2-3b-preview",
"llama-3.2-90b-text-preview"
{
"id": "llama-3.1-8b-instant",
"name": "Llama 3.1 (8B) - Instant",
"default": false
},
{
"id": "llama-3.2-3b-preview",
"name": "Llama 3.2 (3B)",
"default": false
},
{
"id": "llama-3.2-90b-text-preview",
"name": "Llama 3.2 (90B)",
"default": true
}
],
"tests": [
{
Expand Down

0 comments on commit 6f762c0

Please sign in to comment.