Update package.json and code files
This commit is contained in:
parent
5958e10354
commit
a66d8a8418
22
package.json
22
package.json
@ -77,24 +77,8 @@
|
|||||||
"activeTab",
|
"activeTab",
|
||||||
"scripting",
|
"scripting",
|
||||||
"declarativeNetRequest",
|
"declarativeNetRequest",
|
||||||
"declarativeNetRequestFeedback"
|
"declarativeNetRequestFeedback",
|
||||||
],
|
"action"
|
||||||
"commands": {
|
]
|
||||||
"open-ai-sidebar": {
|
|
||||||
"suggested_key": {
|
|
||||||
"default": "Ctrl+Shift+0",
|
|
||||||
"mac": "Command+Shift+0"
|
|
||||||
},
|
|
||||||
"description": "Open AI Sidebar for Page Assist"
|
|
||||||
},
|
|
||||||
"_execute_action": {
|
|
||||||
"suggested_key": {
|
|
||||||
"windows": "Ctrl+Shift+0",
|
|
||||||
"mac": "Command+Shift+0",
|
|
||||||
"chromeos": "Ctrl+Shift+0",
|
|
||||||
"linux": "Ctrl+Shift+0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
export {}
|
export {}
|
||||||
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(async (message) => {
|
chrome.runtime.onMessage.addListener(async (message) => {
|
||||||
if (message.type === "sidepanel") {
|
if (message.type === "sidepanel") {
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
|
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
|
||||||
@ -11,3 +10,12 @@ chrome.runtime.onMessage.addListener(async (message) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
chrome.action.onClicked.addListener((tab) => {
|
||||||
|
chrome.tabs.create({url: chrome.runtime.getURL("options.html")});
|
||||||
|
});
|
||||||
|
|
||||||
|
// listen to commadns
|
||||||
|
chrome.commands.onCommand.addListener((command) => {
|
||||||
|
console.log('Command', command)
|
||||||
|
})
|
@ -14,12 +14,13 @@ import {
|
|||||||
RunnableMap,
|
RunnableMap,
|
||||||
RunnableSequence,
|
RunnableSequence,
|
||||||
} from "langchain/schema/runnable";
|
} from "langchain/schema/runnable";
|
||||||
|
import type { ChatHistory } from "~store";
|
||||||
type RetrievalChainInput = {
|
type RetrievalChainInput = {
|
||||||
chat_history: string;
|
chat_history: string;
|
||||||
question: string;
|
question: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function groupMessagesByConversation(messages: any[]) {
|
export function groupMessagesByConversation(messages: ChatHistory) {
|
||||||
if (messages.length % 2 !== 0) {
|
if (messages.length % 2 !== 0) {
|
||||||
messages.pop();
|
messages.pop();
|
||||||
}
|
}
|
||||||
|
33
src/components/Common/SaveButton.tsx
Normal file
33
src/components/Common/SaveButton.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { useState } from "react"
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
onClick: () => void
|
||||||
|
disabled?: boolean
|
||||||
|
className?: string
|
||||||
|
text?: string
|
||||||
|
textOnSave?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SaveButton = ({
|
||||||
|
onClick,
|
||||||
|
disabled,
|
||||||
|
className,
|
||||||
|
text = "Save",
|
||||||
|
textOnSave = "Saved"
|
||||||
|
}: Props) => {
|
||||||
|
const [clickedSave, setClickedSave] = useState(false)
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
setClickedSave(true)
|
||||||
|
onClick()
|
||||||
|
setTimeout(() => {
|
||||||
|
setClickedSave(false)
|
||||||
|
}, 1000)
|
||||||
|
}}
|
||||||
|
disabled={disabled}
|
||||||
|
className={`bg-pink-500 text-r mt-4 hover:bg-pink-600 text-white px-4 py-2 rounded-md dark:bg-pink-600 dark:hover:bg-pink-700 ${className}`}>
|
||||||
|
{clickedSave ? textOnSave : text}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
@ -11,6 +11,7 @@ import {
|
|||||||
|
|
||||||
import { Skeleton, Radio } from "antd"
|
import { Skeleton, Radio } from "antd"
|
||||||
import { useDarkMode } from "~hooks/useDarkmode"
|
import { useDarkMode } from "~hooks/useDarkmode"
|
||||||
|
import { SaveButton } from "~components/Common/SaveButton"
|
||||||
|
|
||||||
export const SettingsBody = () => {
|
export const SettingsBody = () => {
|
||||||
const [ollamaURL, setOllamaURL] = React.useState<string>("")
|
const [ollamaURL, setOllamaURL] = React.useState<string>("")
|
||||||
@ -78,13 +79,11 @@ export const SettingsBody = () => {
|
|||||||
placeholder="Enter Ollama URL here"
|
placeholder="Enter Ollama URL here"
|
||||||
/>
|
/>
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<button
|
<SaveButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
saveOllamaURL(ollamaURL)
|
saveOllamaURL(ollamaURL)
|
||||||
}}
|
}}
|
||||||
className="bg-pink-500 text-r mt-4 hover:bg-pink-600 text-white px-4 py-2 rounded-md dark:bg-pink-600 dark:hover:bg-pink-700">
|
/>
|
||||||
Save
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="border border-gray-300 dark:border-gray-700 rounded p-4">
|
<div className="border border-gray-300 dark:border-gray-700 rounded p-4">
|
||||||
@ -109,13 +108,11 @@ export const SettingsBody = () => {
|
|||||||
onChange={(e) => setSystemPrompt(e.target.value)}
|
onChange={(e) => setSystemPrompt(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<button
|
<SaveButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSystemPromptForNonRag(systemPrompt)
|
setSystemPromptForNonRag(systemPrompt)
|
||||||
}}
|
}}
|
||||||
className="bg-pink-500 text-r mt-4 hover:bg-pink-600 text-white px-4 py-2 rounded-md dark:bg-pink-600 dark:hover:bg-pink-700">
|
/>
|
||||||
Save
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -144,13 +141,11 @@ export const SettingsBody = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<button
|
<SaveButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPromptForRag(ragPrompt, ragQuestionPrompt)
|
setPromptForRag(ragPrompt, ragQuestionPrompt)
|
||||||
}}
|
}}
|
||||||
className="bg-pink-500 hover:bg-pink-600 text-white px-4 py-2 rounded-md dark:bg-pink-600 dark:hover:bg-pink-700">
|
/>
|
||||||
Save
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -17,7 +17,7 @@ import { getHtmlOfCurrentTab } from "~libs/get-html"
|
|||||||
import { PageAssistHtmlLoader } from "~loader/html"
|
import { PageAssistHtmlLoader } from "~loader/html"
|
||||||
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter"
|
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter"
|
||||||
import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama"
|
import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama"
|
||||||
import { createChatWithWebsiteChain } from "~chain/chat-with-website"
|
import { createChatWithWebsiteChain, groupMessagesByConversation } from "~chain/chat-with-website"
|
||||||
import { MemoryVectorStore } from "langchain/vectorstores/memory"
|
import { MemoryVectorStore } from "langchain/vectorstores/memory"
|
||||||
|
|
||||||
export type BotResponse = {
|
export type BotResponse = {
|
||||||
@ -205,7 +205,8 @@ export const useMessage = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const chunks = await chain.stream({
|
const chunks = await chain.stream({
|
||||||
question: sanitizedQuestion
|
question: sanitizedQuestion,
|
||||||
|
chat_history: groupMessagesByConversation(history),
|
||||||
})
|
})
|
||||||
let count = 0
|
let count = 0
|
||||||
for await (const chunk of chunks) {
|
for await (const chunk of chunks) {
|
||||||
|
@ -2,8 +2,13 @@ import { Route, Routes } from "react-router-dom"
|
|||||||
import { SidepanelChat } from "./sidepanel-chat"
|
import { SidepanelChat } from "./sidepanel-chat"
|
||||||
import { useDarkMode } from "~hooks/useDarkmode"
|
import { useDarkMode } from "~hooks/useDarkmode"
|
||||||
import { SidepanelSettings } from "./sidepanel-settings"
|
import { SidepanelSettings } from "./sidepanel-settings"
|
||||||
|
import { OptionIndex } from "./option-index"
|
||||||
|
|
||||||
export const Routing = () => <Routes></Routes>
|
export const OptionRouting = () => (
|
||||||
|
<Routes>
|
||||||
|
<Route path="/" element={<OptionIndex />} />
|
||||||
|
</Routes>
|
||||||
|
)
|
||||||
|
|
||||||
export const SidepanelRouting = () => {
|
export const SidepanelRouting = () => {
|
||||||
const { mode } = useDarkMode()
|
const { mode } = useDarkMode()
|
||||||
|
10
src/routes/option-index.tsx
Normal file
10
src/routes/option-index.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { SettingsBody } from "~components/Sidepanel/Settings/body"
|
||||||
|
import { SidepanelSettingsHeader } from "~components/Sidepanel/Settings/header"
|
||||||
|
|
||||||
|
export const OptionIndex = () => {
|
||||||
|
return (
|
||||||
|
<div className="flex bg-white dark:bg-black flex-col min-h-screen mx-auto max-w-7xl">
|
||||||
|
hey
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user