-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: `resetChatHistory` function on a `LlamaChatSession` * feat: copy model response in the example Electron app template
- Loading branch information
Showing
10 changed files
with
211 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...t-react/src/App/components/ChatHistory/components/MessageCopyButton/MessageCopyButton.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.appChatHistory > .buttons { | ||
> .copyButton { | ||
display: grid; | ||
grid-template-areas: "icon"; | ||
padding: 6px; | ||
border: none; | ||
|
||
transition: background-color 0.1s ease-in-out; | ||
|
||
&:not(:hover, :focus-visible) { | ||
background-color: transparent; | ||
} | ||
|
||
&.copied { | ||
> .icon.copy { | ||
opacity: 0; | ||
transition-delay: 0s; | ||
} | ||
|
||
> .icon.check { | ||
opacity: 1; | ||
transition-delay: 0.1s; | ||
} | ||
} | ||
|
||
> .icon { | ||
grid-area: icon; | ||
width: 18px; | ||
height: 18px; | ||
|
||
transition: opacity 0.3s ease-in-out; | ||
|
||
&.copy { | ||
opacity: 1; | ||
transition-delay: 0.1s; | ||
} | ||
&.check { | ||
opacity: 0; | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...t-react/src/App/components/ChatHistory/components/MessageCopyButton/MessageCopyButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import classNames from "classnames"; | ||
import {useCallback, useState} from "react"; | ||
import {CopyIconSVG} from "../../../../../icons/CopyIconSVG.js"; | ||
import {CheckIconSVG} from "../../../../../icons/CheckIconSVG.js"; | ||
|
||
import "./MessageCopyButton.css"; | ||
|
||
const showCopiedTime = 1000 * 2; | ||
|
||
export function MessageCopyButton({text}: MessageCopyButtonProps) { | ||
const [copies, setCopies] = useState(0); | ||
|
||
const onClick = useCallback(() => { | ||
navigator.clipboard.writeText(text) | ||
.then(() => { | ||
setCopies(copies + 1); | ||
|
||
setTimeout(() => { | ||
setCopies(copies - 1); | ||
}, showCopiedTime); | ||
}) | ||
.catch((error) => { | ||
console.error("Failed to copy text to clipboard", error); | ||
}); | ||
}, [text]); | ||
|
||
return <button | ||
onClick={onClick} | ||
className={classNames("copyButton", copies > 0 && "copied")} | ||
> | ||
<CopyIconSVG className="icon copy" /> | ||
<CheckIconSVG className="icon check" /> | ||
</button>; | ||
} | ||
|
||
type MessageCopyButtonProps = { | ||
text: string | ||
}; |
7 changes: 7 additions & 0 deletions
7
templates/electron-typescript-react/src/icons/CheckIconSVG.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {SVGProps} from "react"; | ||
|
||
export function CheckIconSVG(props: SVGProps<SVGSVGElement>) { | ||
return <svg height="24px" viewBox="0 -960 960 960" width="24px" {...props}> | ||
<path d="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z"/> | ||
</svg>; | ||
} |
7 changes: 7 additions & 0 deletions
7
templates/electron-typescript-react/src/icons/CopyIconSVG.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {SVGProps} from "react"; | ||
|
||
export function CopyIconSVG(props: SVGProps<SVGSVGElement>) { | ||
return <svg height="24px" viewBox="0 -960 960 960" width="24px" {...props}> | ||
<path d="M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z"/> | ||
</svg>; | ||
} |