-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new files and functions for chat history and chat completion usin…
…g the OpenAI model
- Loading branch information
1 parent
a75dc03
commit a48fbb3
Showing
7 changed files
with
437 additions
and
268 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,5 @@ | ||
const historyMenu = () => { | ||
|
||
} | ||
|
||
export default historyMenu; |
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,33 @@ | ||
import { AvailableModels, Mode } from "../config/settings" | ||
import { ChatOpenAI } from "langchain/chat_models/openai" | ||
import { useStorage } from "./useStorage" | ||
|
||
interface UseChatCompletionProps { | ||
model: AvailableModels | ||
apiKey: string | ||
mode: Mode | ||
systemPrompt: string | ||
} | ||
|
||
|
||
type Role = "user" | "assistant" | "system" | ||
|
||
type Message = { | ||
role: Role | ||
message: string | ||
timestamp: number | ||
} | ||
|
||
export const useChatCompletion = ({ | ||
model, | ||
apiKey, | ||
mode, | ||
systemPrompt, | ||
}: UseChatCompletionProps) => { | ||
const chat = new ChatOpenAI({ | ||
streaming: true, | ||
}); | ||
|
||
const [messages, setMessages] = useStorage() | ||
|
||
} |
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,39 @@ | ||
import { randomUUID } from "crypto" | ||
import { useStorage } from "./useStorage" | ||
|
||
interface ChatHistory { | ||
id: string | ||
name: string | ||
createdAt: string | ||
updatedAt: string | ||
} | ||
|
||
export const useHistory = () => { | ||
const [history, setHistory] = useStorage<ChatHistory[]>("HISTORY", []) | ||
|
||
const createChatHistory = () => { | ||
const newId = randomUUID() | ||
|
||
setHistory(prev => [...prev, { | ||
id: newId, | ||
name: "", | ||
createdAt: new Date().toISOString(), | ||
updatedAt: new Date().toISOString(), | ||
}]) | ||
|
||
return newId | ||
} | ||
const deleteChatHistory = (id: string) => { | ||
setHistory(prev => prev.filter(h => h.id !== id)) | ||
} | ||
const getChatHistory = (id: string) => { | ||
return history.find(h => h.id === id) | ||
} | ||
|
||
return { | ||
createChatHistory, | ||
deleteChatHistory, | ||
getChatHistory, | ||
history, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.