Skip to content

Commit

Permalink
Refactor [Model] [LLM Api] Chaining Model
Browse files Browse the repository at this point in the history
- [+] refactor(model.ts): change forEach loop to arrow function for readability and consistency
- [+] fix(model.ts): mark 'provider' property as optional in modelTable type
- [+] fix(model.ts): use optional chaining when assigning provider property in modelTable
  • Loading branch information
H0llyW00dzZ committed Dec 24, 2023
1 parent 8ca525d commit e9def2c
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,39 @@ export function collectModelTable(
available: boolean;
name: string;
displayName: string;
provider: LLMModel["provider"];
provider?: LLMModel["provider"]; // Marked as optional
}
> = {};

// default models
models.forEach(
(m) =>
(modelTable[m.name] = {
...m,
displayName: m.name,
}),
);
models.forEach((m) => {
modelTable[m.name] = {
...m,
displayName: m.name, // 'provider' is copied over if it exists
};
});

// server custom models
customModels
.split(",")
.filter((v) => !!v && v.length > 0)
.map((m) => {
.forEach((m) => {
const available = !m.startsWith("-");
const nameConfig =
m.startsWith("+") || m.startsWith("-") ? m.slice(1) : m;
const [name, displayName] = nameConfig.split("=");

// enable or disable all models
if (name === "all") {
Object.values(modelTable).forEach((m) => (m.available = available));
Object.values(modelTable).forEach((model) => (model.available = available));
} else {
modelTable[name] = {
name,
displayName: displayName || name,
available,
provider: modelTable[name]?.provider, // Use optional chaining
};
}

modelTable[name] = {
name,
displayName: displayName || name,
available,
provider: modelTable[name].provider,
};
});
return modelTable;
}
Expand Down

0 comments on commit e9def2c

Please sign in to comment.