Skip to content

Commit

Permalink
feat: 支持提示词
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Aug 28, 2023
1 parent 8ae04ef commit 28d3347
Show file tree
Hide file tree
Showing 24 changed files with 1,421 additions and 101 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bingo",
"version": "0.5.0",
"version": "0.6.0",
"private": true,
"scripts": {
"dev": "cross-env DEBUG=bingo* next dev --hostname 0.0.0.0",
Expand Down Expand Up @@ -54,6 +54,7 @@
"react-hot-toast": "^2.4.1",
"react-intersection-observer": "^9.5.2",
"react-markdown": "^8.0.7",
"react-spinners": "^0.13.8",
"react-syntax-highlighter": "^15.5.0",
"react-textarea-autosize": "^8.5.0",
"react-viewport-list": "^7.1.1",
Expand Down
654 changes: 654 additions & 0 deletions public/prompts/en-US.json

Large diffs are not rendered by default.

238 changes: 238 additions & 0 deletions public/prompts/zh-CN.json

Large diffs are not rendered by default.

67 changes: 59 additions & 8 deletions src/app/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

:root {
--cib-comp-thread-name-border-radius: 3px;
--arrow-start-offset: 16px;
--cib-color-foreground-accent-primary: #75306C;
--cib-color-foreground-accent-secondary: #692B61;
--cib-color-foreground-accent-tertiary: #5E2656;
Expand Down Expand Up @@ -302,7 +303,9 @@
--button-compose-collapsed-width: 48px;
--button-compose-expanded-width: 116px;
--cib-comp-feedback-host-border-radius: 8px;
--cib-comp-feedback-button-border-radius: 6px;
font-family: var(--cib-font-text);
--primary-border: var(--cib-color-stroke-accent-primary);
}

.precise {
Expand Down Expand Up @@ -349,6 +352,12 @@
background: var(--cib-color-background-surface-app-primary);
}

.bg-primary {
--tw-bg-opacity: 1;
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
color: var(--cib-color-foreground-on-accent-primary);
}

body {
background: var(--cib-color-background-surface-app-primary);
}
Expand Down Expand Up @@ -387,7 +396,7 @@ body {

.scroll-button {
bottom: 4rem;
z-index: 100;
z-index: 50;

@media (max-width: 767px) {
bottom: 8rem;
Expand Down Expand Up @@ -624,7 +633,7 @@ body {
position: absolute;
top: -36px;
inset-inline-end: 0px;
z-index: 1001;
z-index: 51;
display: flex;
flex-direction: row;
will-change: transform;
Expand Down Expand Up @@ -1083,6 +1092,15 @@ button {
padding-inline-end: 84px;
}

.action-button {
padding: 8px;
outline: transparent solid 1px;
border-radius: var(--cib-comp-feedback-button-border-radius);
&:hover {
background: var(--cib-color-fill-subtle-secondary);
}
}

.main-container {
display: flex;
flex-direction: column;
Expand All @@ -1094,8 +1112,7 @@ button {
height: 100%;
min-height: 48px;
box-sizing: border-box;
padding-block: 13px 11px;
padding-inline: 16px;
padding: 13px 16px;
z-index: 1;
background: var(--cib-color-background-surface-solid-quaternary);
border-radius: var(--cib-action-bar-search-border-radius);
Expand Down Expand Up @@ -1137,6 +1154,7 @@ button {
flex-direction: row;
width: 100%;
gap: 16px;
padding-bottom: 24px;
justify-content: space-between;
align-items: flex-start;
}
Expand Down Expand Up @@ -1263,7 +1281,7 @@ button {
position: absolute;
bottom: 42px;
width: 380px;
inset-inline-end: -50px;
inset-inline-start: calc(0px - var(--arrow-start-offset));
display: flex;
flex-direction: column;
align-items: flex-start;
Expand Down Expand Up @@ -1386,7 +1404,6 @@ button {
&::after {
content: "";
position: absolute;
inset-inline-end: 50px;
top: 100%;
inset-inline-start: var(--arrow-start-offset);
border-top-width: 10px;
Expand Down Expand Up @@ -1606,8 +1623,7 @@ button {
bottom: 4px;
inset-inline: 0px;
box-sizing: border-box;
padding-block: 0px;
padding-inline: 16px 8px;
padding: 8px;
opacity: 0;
transition-property: opacity;
transition-duration: var(--cib-motion-duration-faster);
Expand Down Expand Up @@ -1893,3 +1909,38 @@ button {
background-color: var(--cib-color-foreground-accent-primary);
}
}

.dialog {
z-index: 101;
}

.prompt-container {
border-radius: var(--cib-border-radius-large);
max-height: max(324px, 60%);
height: min-content;
overflow-y: auto;
.surface {
display: flex;
flex-direction: column;
max-height: max(324px, 60%);
height: min-content;
overflow-y: auto;
color: var(--cib-color-foreground-accent-primary);
border-radius: var(--cib-border-radius-large);
background: var(--cib-color-background-surface-app-primary);
box-shadow: var(--cib-shadow-card);

.row {
flex-direction: row;
width: 100%;
position: relative;
border-radius: var(--cib-comp-thread-host-border-radius);
cursor: pointer;
padding-block: 9px;
padding-inline: 12px;
display: flex;
flex-direction: column;
gap: 5px;
}
}
}
3 changes: 3 additions & 0 deletions src/assets/images/new-topic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/images/send-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/assets/images/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/chat-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function ConversationThead({ conversation, onRename, onDelete, onUpdate,
<div className="primary-row flex w-full">
<div className="description flex-1">
{!isEdit ? (
<h3 className="name" onClick={() => onUpdate(conversation)}>{name}</h3>
<h3 className="name" title={name} onClick={() => onUpdate(conversation)}>{name}</h3>
) : (<input className="input-name" defaultValue={name} onChange={(event) => setName(event.target.value)} />)}
</div>
{!isEdit && (<h4 className="time">{formatDate(conversation.updateTimeUtc)}</h4>)}
Expand Down
56 changes: 29 additions & 27 deletions src/components/chat-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
ClipboardEvent,
MouseEventHandler,
useRef,
KeyboardEvent
KeyboardEvent,
FormEvent
} from "react"
import { toast } from "react-hot-toast"
import { SVG } from "./ui/svg"
Expand All @@ -26,13 +27,16 @@ const preventDefault: MouseEventHandler<HTMLDivElement> = (event) => {
export function ChatImage({ children, uploadImage }: React.PropsWithChildren<ChatImageProps>) {
const videoRef = useRef<HTMLVideoElement>(null)
const canvasRef = useRef<HTMLCanvasElement>(null)
const fileRef = useRef<HTMLInputElement>(null)
const mediaStream = useRef<MediaStream>()
const [panel, setPanel] = useState('none')
const [inputUrl, setInputUrl] = useState('')

const upload = useCallback((url: string) => {
if (url) {
uploadImage(url)
if (fileRef.current) {
fileRef.current.value = ''
}
}
setPanel('none')
}, [panel])
Expand All @@ -52,17 +56,19 @@ export function ChatImage({ children, uploadImage }: React.PropsWithChildren<Cha
upload(pasteUrl)
}, [])

const onEnter = useCallback((event: KeyboardEvent<HTMLInputElement>) => {
// @ts-ignore
const onEnter = useCallback((event: FormEvent<HTMLFormElement>) => {
event.preventDefault()
// @ts-ignore
event.stopPropagation()
if (/^https?:\/\/.+/.test(inputUrl)) {
upload(inputUrl)
} else {
toast.error('请输入有效的图片链接')
// @ts-ignore
const inputUrl = event.target?.elements?.image?.value?.trim?.()
if (inputUrl) {
if (/^https?:\/\/.+/.test(inputUrl)) {
upload(inputUrl)
} else {
toast.error('请输入有效的图片链接')
}
}
}, [inputUrl])
}, [])

const openVideo: MouseEventHandler<HTMLButtonElement> = async (event) => {
event.stopPropagation()
Expand Down Expand Up @@ -121,27 +127,23 @@ export function ChatImage({ children, uploadImage }: React.PropsWithChildren<Cha
</div>
<div className="paste">
<SVG alt="paste" src={PasteIcon} width={24} />
<input
className="paste-input"
id="sb_imgpst"
type="text"
name="image"
placeholder="粘贴图像 URL"
aria-label="粘贴图像 URL"
onPaste={onPaste}
onChange={(event) => setInputUrl(event.target.value.trim())}
onKeyDownCapture={event => {
if (event.key === 'Enter') {
onEnter(event)
}
}}
onClickCapture={(e) => e.stopPropagation()}
/>
<form onSubmitCapture={onEnter}>
<input
className="paste-input"
id="sb_imgpst"
type="text"
name="image"
placeholder="粘贴图像 URL"
aria-label="粘贴图像 URL"
onPaste={onPaste}
onClickCapture={(e) => e.stopPropagation()}
/>
</form>
</div>
<div className="buttons">
<button type="button" aria-label="从此设备上传">
<input
id="vs_fileinput"
ref={fileRef}
className="fileinput"
type="file"
accept="image/gif, image/jpeg, image/png, image/webp"
Expand Down
Loading

0 comments on commit 28d3347

Please sign in to comment.