feat: display error on selection of invalid model (#594)
Up-to-date of #78 Fixes #32 addressed requested changes @tibo-openai :) made sense to me though, previous rationale with passing the state up was assuming there could be a future need to have a shared state with all available models being available to the parent
This commit is contained in:
@@ -31,6 +31,7 @@ import DiffOverlay from "../diff-overlay.js";
|
||||
import HelpOverlay from "../help-overlay.js";
|
||||
import HistoryOverlay from "../history-overlay.js";
|
||||
import ModelOverlay from "../model-overlay.js";
|
||||
import chalk from "chalk";
|
||||
import { Box, Text } from "ink";
|
||||
import { spawn } from "node:child_process";
|
||||
import OpenAI from "openai";
|
||||
@@ -575,7 +576,7 @@ export default function TerminalChat({
|
||||
providers={config.providers}
|
||||
currentProvider={provider}
|
||||
hasLastResponse={Boolean(lastResponseId)}
|
||||
onSelect={(newModel) => {
|
||||
onSelect={(allModels, newModel) => {
|
||||
log(
|
||||
"TerminalChat: interruptAgent invoked – calling agent.cancel()",
|
||||
);
|
||||
@@ -585,6 +586,20 @@ export default function TerminalChat({
|
||||
agent?.cancel();
|
||||
setLoading(false);
|
||||
|
||||
if (!allModels?.includes(newModel)) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(
|
||||
chalk.bold.red(
|
||||
`Model "${chalk.yellow(
|
||||
newModel,
|
||||
)}" is not available for provider "${chalk.yellow(
|
||||
provider,
|
||||
)}".`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setModel(newModel);
|
||||
setLastResponseId((prev) =>
|
||||
prev && newModel !== model ? null : prev,
|
||||
|
||||
Reference in New Issue
Block a user