-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
227 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
"landuse", | ||
"langchain", | ||
"Liban", | ||
"lightbrown", | ||
"lightgreen", | ||
"lightpink", | ||
"lightyellow", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { LocationContext } from "@/contexts/LocationContext"; | ||
import { DialogueElement } from "@/types/DialogueElement"; | ||
import { nextPostJsonWithCache } from "@/utils/nextPostJson"; | ||
import { useContext, useEffect, useState } from "react"; | ||
|
||
import styles from "./styles.module.scss"; | ||
|
||
export const InputPredict: React.FC<{ | ||
pastMessages?: any[]; | ||
onUpdateSuggestions?: () => void; | ||
onSelected?: (value: string) => void; | ||
}> = ({ pastMessages, onUpdateSuggestions, onSelected }) => { | ||
const locationInfo = useContext(LocationContext); | ||
const [requesting, setRequesting] = useState(false); | ||
const [suggests, setSuggests] = useState<string[] | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
if (!pastMessages) { | ||
return; | ||
} | ||
if (pastMessages.length === 0) { | ||
return; | ||
} | ||
if (requesting) { | ||
return; | ||
} | ||
const thisEffect = async () => { | ||
setRequesting(true); | ||
const resJson = await nextPostJsonWithCache("/api/ai/suggests", { | ||
lang: window.navigator.language, | ||
location: locationInfo.location, | ||
pastMessages: JSON.stringify(pastMessages), | ||
}); | ||
if (!resJson.suggests) { | ||
return; | ||
} | ||
const newSuggests = resJson.suggests.split("\n"); | ||
setSuggests(newSuggests); | ||
onUpdateSuggestions && onUpdateSuggestions(); | ||
setRequesting(false); | ||
}; | ||
thisEffect(); | ||
}, [locationInfo, onUpdateSuggestions, pastMessages, requesting]); | ||
|
||
return ( | ||
<> | ||
<div className={styles.suggestListWrap}> | ||
{suggests?.map((suggest) => { | ||
return ( | ||
<button | ||
className={styles.suggestListItem} | ||
key={suggest} | ||
onClick={() => { | ||
onSelected && onSelected(suggest); | ||
}} | ||
> | ||
{suggest} | ||
</button> | ||
); | ||
})} | ||
</div> | ||
</> | ||
); | ||
}; |
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,12 @@ | ||
.suggestListWrap { | ||
display: flex; | ||
flex-direction: column; | ||
flex-wrap: no-wrap; | ||
gap: 2%; | ||
} | ||
|
||
.suggestListItem { | ||
font-size: 0.8em; | ||
margin-top: 12px; | ||
padding: 6px; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { createContext } from "react"; | ||
|
||
export type LocationInfo = { | ||
location: string | undefined; | ||
}; | ||
|
||
export const LocationContext = createContext<LocationInfo>({ | ||
location: undefined, | ||
}); | ||
|
||
export const LocationProvider = ({ | ||
locationInfo, | ||
children, | ||
}: { | ||
locationInfo: LocationInfo; | ||
children: React.ReactNode; | ||
}) => { | ||
return ( | ||
<LocationContext.Provider value={locationInfo}> | ||
{children} | ||
</LocationContext.Provider> | ||
); | ||
}; | ||
|
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
Oops, something went wrong.
dc1c79e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
trident – ./
trident-seven.vercel.app
trident-yuiseki-s-team.vercel.app
trident.yuiseki.net
trident-git-main-yuiseki-s-team.vercel.app