-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from dwhiffing/settings-modal
Moved Settings to modal
- Loading branch information
Showing
6 changed files
with
316 additions
and
240 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use client"; | ||
|
||
import { createContext, useContext, useState } from "react"; | ||
import { UseChatHelpers, UseChatOptions, useChat as useAiChat } from "ai/react"; | ||
import { MODELS } from "@/constants"; | ||
import { useContracts } from "@/utils/useContracts"; | ||
import { toast } from "sonner"; | ||
|
||
export const ChatContext = createContext< | ||
Pick< | ||
UseChatOptions & UseChatHelpers, | ||
"messages" | "handleInputChange" | "handleSubmit" | "isLoading" | "input" | ||
> & { | ||
modelName: string; | ||
clearOnChange: boolean; | ||
onClearMessages: () => void; | ||
setModelName: (name: string) => void; | ||
setClearOnChange: (v: boolean) => void; | ||
} | ||
>({ | ||
messages: [], | ||
handleInputChange: () => {}, | ||
handleSubmit: () => {}, | ||
isLoading: false, | ||
input: "", | ||
modelName: "", | ||
clearOnChange: false, | ||
onClearMessages: () => {}, | ||
setModelName: () => {}, | ||
setClearOnChange: () => {}, | ||
}); | ||
|
||
export const useChat = () => useContext(ChatContext); | ||
|
||
const ChatProvider = ({ children }: any) => { | ||
const { disabledKeys } = useContracts(); | ||
const [modelName, setModelName] = useState(MODELS["openai"][0]); | ||
const [clearOnChange, setClearOnChange] = useState(false); | ||
|
||
const chatContext = useAiChat({ | ||
api: "api/chat", | ||
body: { disabledContractKeys: disabledKeys, modelName }, | ||
streamProtocol: "text", | ||
onError: (e) => { | ||
toast(e.message); | ||
}, | ||
}); | ||
|
||
const onClearMessages = () => { | ||
chatContext.setMessages([]); | ||
}; | ||
|
||
return ( | ||
<ChatContext.Provider | ||
value={{ | ||
...chatContext, | ||
modelName, | ||
setModelName, | ||
clearOnChange, | ||
setClearOnChange, | ||
onClearMessages, | ||
}} | ||
> | ||
{children} | ||
</ChatContext.Provider> | ||
); | ||
}; | ||
|
||
export default ChatProvider; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.