Skip to content

Commit

Permalink
Add new files and functions for chat history and chat completion usin…
Browse files Browse the repository at this point in the history
…g the OpenAI model
  • Loading branch information
Royal-lobster committed Sep 19, 2023
1 parent a75dc03 commit a48fbb3
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 268 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Alternatively, you can install Syncia manually by following these steps:
3. Open Google Chrome and go to the "Extensions" page by typing "chrome://extensions/" in the address bar.
4. Turn on "Developer mode" by toggling the switch in the top right corner of the page.
5. Click on the "Load unpacked" button in the top left corner of the page.
6. Select the `dist` folder.
6. Select the `dist` folder.

## 💫 Usage

Expand Down Expand Up @@ -75,7 +75,7 @@ You can also contribute to the project by creating a pull request. please follow

Checkout the [CONTRIBUTING.md](
https://github.com/Royal-lobster/Syncia/blob/main/CONTRIBUTING.md
) file for more information.
) file for more information.

## 🔎 Issues and Pull Requests

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"axios": "^1.3.5",
"dnd-kit-sortable-tree": "^0.1.58",
"endent": "^2.1.0",
"langchain": "^0.0.151",
"object-hash": "^3.0.0",
"publish-browser-extension": "^1.2.0",
"react": "^18.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/components/Settings/Elements/HistoryMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const historyMenu = () => {

}

export default historyMenu;
33 changes: 33 additions & 0 deletions src/hooks/useChatCompletion.tsx
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()

}
39 changes: 39 additions & 0 deletions src/hooks/useHistory.tsx
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,
}
}
265 changes: 0 additions & 265 deletions src/hooks/useOpenAI.tsx

This file was deleted.

Loading

0 comments on commit a48fbb3

Please sign in to comment.