Skip to content

Commit 95e0539

Browse files
committed
x
remove
1 parent 1d94cf6 commit 95e0539

File tree

4 files changed

+198
-99
lines changed

4 files changed

+198
-99
lines changed

ai/ai-react-app/src/components/Common/PromptInput.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface PromptInputProps {
2525
currentParams?: ModelParams;
2626
currentImagenParams?: ImagenModelParams;
2727
selectedFile: File | null;
28+
onCancel?: () => void; // New prop for cancellation
2829
}
2930

3031
const PromptInput: React.FC<PromptInputProps> = ({
@@ -39,6 +40,7 @@ const PromptInput: React.FC<PromptInputProps> = ({
3940
aiInstance,
4041
currentParams,
4142
selectedFile,
43+
onCancel,
4244
}) => {
4345
const [tokenCount, setTokenCount] = useState<CountTokensResponse | null>(
4446
null,
@@ -47,7 +49,6 @@ const PromptInput: React.FC<PromptInputProps> = ({
4749
const [tokenCountError, setTokenCountError] = useState<string | null>(null);
4850

4951
const handleCountTokensClick = useCallback(async () => {
50-
// Prevent counting if main action is loading or already counting
5152
if (isLoading || isCountingTokens) return;
5253

5354
setIsCountingTokens(true);
@@ -57,12 +58,10 @@ const PromptInput: React.FC<PromptInputProps> = ({
5758
const currentPromptText = prompt.trim();
5859
const parts: Part[] = [];
5960

60-
// Add text part if present
6161
if (currentPromptText) {
6262
parts.push({ text: currentPromptText });
6363
}
6464

65-
// Add file part if present
6665
if (selectedFile) {
6766
try {
6867
const filePart = await fileToGenerativePart(selectedFile);
@@ -75,7 +74,6 @@ const PromptInput: React.FC<PromptInputProps> = ({
7574
}
7675
}
7776

78-
// Don't count if there's nothing to count
7977
if (parts.length === 0) {
8078
setTokenCountError("Nothing to count tokens for (no text or file).");
8179
setIsCountingTokens(false);
@@ -104,7 +102,7 @@ const PromptInput: React.FC<PromptInputProps> = ({
104102
} catch (err: unknown) {
105103
console.error("Error counting tokens:", err);
106104
setTokenCountError(`Token count failed`);
107-
setTokenCount(null); // Clear previous count on error
105+
setTokenCount(null);
108106
} finally {
109107
setIsCountingTokens(false);
110108
}
@@ -117,6 +115,14 @@ const PromptInput: React.FC<PromptInputProps> = ({
117115
isCountingTokens,
118116
]);
119117

118+
const handlePrimaryAction = () => {
119+
if (isLoading && onCancel) {
120+
onCancel();
121+
} else {
122+
onSubmit();
123+
}
124+
};
125+
120126
return (
121127
<div className={styles.promptContainer}>
122128
{/* Suggestions */}
@@ -127,7 +133,7 @@ const PromptInput: React.FC<PromptInputProps> = ({
127133
key={index}
128134
className={styles.suggestionButton}
129135
onClick={() => onSuggestionClick(suggestion)}
130-
disabled={isLoading} // Disable buttons while loading
136+
disabled={isLoading || isCountingTokens}
131137
>
132138
{suggestion}
133139
</button>
@@ -142,17 +148,21 @@ const PromptInput: React.FC<PromptInputProps> = ({
142148
value={prompt}
143149
onChange={(e) => onPromptChange(e.target.value)}
144150
placeholder={placeholder}
145-
disabled={isLoading || isCountingTokens} // Disable if main loading OR counting
151+
disabled={isLoading || isCountingTokens}
146152
rows={3}
147153
aria-label="Prompt input"
148154
/>
149155
<button
150156
className={styles.runButton}
151-
onClick={onSubmit}
152-
disabled={isLoading || isCountingTokens || !prompt.trim()} // Disable if loading, counting, or empty
153-
aria-label="Submit prompt"
157+
onClick={handlePrimaryAction}
158+
disabled={
159+
isLoading
160+
? false // Cancel button is always enabled when loading
161+
: isCountingTokens || (!prompt.trim() && !selectedFile)
162+
}
163+
aria-label={isLoading ? "Cancel prompt" : "Submit prompt"}
154164
>
155-
{isLoading ? "Running..." : "Run ➤"}
165+
{isLoading ? "Cancel ✕" : "Run ➤"}
156166
</button>
157167
</div>
158168

ai/ai-react-app/src/components/Specific/ChatMessage.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
146146
return null;
147147
}
148148

149+
<<<<<<< HEAD
150+
<<<<<<< HEAD
151+
||||||| parent of 733cb1a (x)
152+
=======
153+
// Determine content to render
154+
>>>>>>> 733cb1a (x)
149155
let messageContentNodes: React.ReactNode[];
150156
if (
151157
isModel &&
@@ -161,6 +167,25 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
161167
messageContentNodes = [text];
162168
}
163169

170+
||||||| parent of 22637ef (abort)
171+
// Determine content to render
172+
let messageContentNodes: React.ReactNode[];
173+
if (
174+
isModel &&
175+
groundingMetadata?.groundingSupports &&
176+
groundingMetadata?.groundingChunks
177+
) {
178+
messageContentNodes = renderTextWithInlineHighlighting(
179+
text,
180+
groundingMetadata.groundingSupports,
181+
groundingMetadata.groundingChunks,
182+
);
183+
} else {
184+
messageContentNodes = [text];
185+
}
186+
187+
=======
188+
>>>>>>> 22637ef (abort)
164189
return (
165190
<div
166191
className={`${styles.messageContainer} ${isUser ? styles.user : styles.model}`}

0 commit comments

Comments
 (0)