diff --git a/README.md b/README.md index b51b29f..e514126 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ import { ReactChatbot } from "@vectara/react-chatbot"; { setChatWidget( ); diff --git a/docs/package-lock.json b/docs/package-lock.json index 6bb4675..fa37673 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -14,12 +14,12 @@ }, "..": { "name": "@vectara/react-chatbot", - "version": "2.0.0", + "version": "3.0.0", "license": "Apache-2.0", "dependencies": { "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", - "@vectara/stream-query-client": "^3.1.0", + "@vectara/stream-query-client": "^3.2.0", "classnames": "^2.3.2", "lodash": "^4.17.21", "prismjs": "^1.29.0", @@ -84,7 +84,7 @@ "@types/react-dom": "^17.0.0", "@typescript-eslint/eslint-plugin": "^5.50.0", "@typescript-eslint/parser": "^5.50.0", - "@vectara/stream-query-client": "^3.1.0", + "@vectara/stream-query-client": "^3.2.0", "chokidar": "^3.5.3", "classnames": "^2.3.2", "cross-fetch": "^4.0.0", diff --git a/docs/src/components/ConfigurationDrawer.tsx b/docs/src/components/ConfigurationDrawer.tsx index 094ae3b..f5b6b67 100644 --- a/docs/src/components/ConfigurationDrawer.tsx +++ b/docs/src/components/ConfigurationDrawer.tsx @@ -21,8 +21,8 @@ import { SUMMARY_LANGUAGES, RerankerId } from "../../../src/types"; type Props = { isOpen: boolean; onClose: () => void; - corpusKey: string; - onUpdateCorpusKey: (event: React.ChangeEvent) => void; + corpusKeys: string; + onUpdateCorpusKeys: (event: React.ChangeEvent) => void; customerId: string; onUpdateCustomerId: (event: React.ChangeEvent) => void; apiKey: string; @@ -56,8 +56,8 @@ type Props = { export const ConfigurationDrawer = ({ isOpen, onClose, - corpusKey, - onUpdateCorpusKey, + corpusKeys, + onUpdateCorpusKeys, customerId, onUpdateCustomerId, apiKey, @@ -121,7 +121,7 @@ export const ConfigurationDrawer = ({ - + diff --git a/docs/src/index.tsx b/docs/src/index.tsx index a3e300c..2dd8080 100644 --- a/docs/src/index.tsx +++ b/docs/src/index.tsx @@ -34,7 +34,7 @@ const formatStringProp = (value?: string) => { const generateCodeSnippet = ( customerId?: string, - corpusKey?: string, + corpusKeys?: string, apiKey?: string, title?: string, placeholder?: string, @@ -49,7 +49,7 @@ const generateCodeSnippet = ( ) => { const props = [ `customerId="${customerId === "" ? "" : customerId}"`, - `corpusIds="${corpusKey === "" ? "" : corpusKey}"`, + `corpusKeys="${corpusKeys === "" ? "" : corpusKeys}"`, `apiKey="${apiKey === "" ? "" : apiKey}"` ]; @@ -108,7 +108,7 @@ const DEFAULT_PLACEHOLDER = 'Try "What is Vectara?" or "How does RAG work?"'; const App = () => { const [isConfigurationDrawerOpen, setIsConfigurationDrawerOpen] = useState(false); const [isChatbotForcedOpen, setIsChatbotForcedOpen] = useState(true); - const [corpusKey, setCorpusKey] = useState(""); + const [corpusKeys, setCorpusKeys] = useState(""); const [customerId, setCustomerId] = useState(""); const [apiKey, setApiKey] = useState(""); const [title, setTitle] = useState(DEFAULT_TITLE); @@ -124,8 +124,8 @@ const App = () => { const [rerankerId, setRerankerId] = useState(DEFAULT_RERANKER_ID); const [lambda, setLambda] = useState(DEFAULT_LAMBDA_VALUE); - const onUpdateCorpusKey = useCallback((e: ChangeEvent) => { - setCorpusKey(e.target.value); + const onUpdateCorpusKeys = useCallback((e: ChangeEvent) => { + setCorpusKeys(e.target.value); }, []); const onUpdateCustomerId = useCallback((e: ChangeEvent) => { @@ -212,7 +212,7 @@ const App = () => { * This ensures that we don't voluntarily display the docs corpus details in the text fields. */} { {generateCodeSnippet( customerId, - corpusKey, + corpusKeys, apiKey, title, placeholder, @@ -305,7 +305,7 @@ export const App = () => { startNewConversation } = useChat({ customerId: DEFAULT_CUSTOMER_ID, - corpusKey: DEFAULT_CORPUS_KEY, + corpusKeys: DEFAULT_CORPUS_KEY, apiKey: DEFAULT_API_KEY, enableStreaming: true, // Enable streaming, false otherwise. Defaults to true. numberOfSearchResults: 15, // Number of search results to use for summary. @@ -348,8 +348,8 @@ export const App = () => { setIsConfigurationDrawerOpen(false)} - corpusKey={corpusKey} - onUpdateCorpusKey={onUpdateCorpusKey} + corpusKeys={corpusKeys} + onUpdateCorpusKeys={onUpdateCorpusKeys} customerId={customerId} onUpdateCustomerId={onUpdateCustomerId} apiKey={apiKey} diff --git a/package-lock.json b/package-lock.json index 3cd840f..80ed6ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,17 @@ { "name": "@vectara/react-chatbot", - "version": "2.0.0", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@vectara/react-chatbot", - "version": "2.0.0", + "version": "3.0.0", "license": "Apache-2.0", "dependencies": { "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", - "@vectara/stream-query-client": "^3.1.0", + "@vectara/stream-query-client": "^3.2.0", "classnames": "^2.3.2", "lodash": "^4.17.21", "prismjs": "^1.29.0", @@ -2526,9 +2526,9 @@ "dev": true }, "node_modules/@vectara/stream-query-client": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@vectara/stream-query-client/-/stream-query-client-3.1.0.tgz", - "integrity": "sha512-Eo7FbMuVCOz/riN7XwoJbY5PwZkzrOzEAuPWBVv9t3NXwGpha/mzqE3GwiICfGOuvZx48SOmIn8KEYYzCCo8Iw==" + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@vectara/stream-query-client/-/stream-query-client-3.2.0.tgz", + "integrity": "sha512-OPUik3bIVOKPc3ytvpFTyGbrEHDicbn9nFWiG5ztgAovaDlRL4bu6d0sXOAQLFYgylVMSML+xV4iIsql25P9yg==" }, "node_modules/abab": { "version": "2.0.6", diff --git a/package.json b/package.json index e09f905..895c480 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vectara/react-chatbot", - "version": "2.0.0", + "version": "3.0.0", "description": "A Vectara-powered Chatbot component", "main": "lib/index.js", "module": "lib/index.js", @@ -32,7 +32,7 @@ "dependencies": { "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", - "@vectara/stream-query-client": "^3.1.0", + "@vectara/stream-query-client": "^3.2.0", "classnames": "^2.3.2", "lodash": "^4.17.21", "prismjs": "^1.29.0", diff --git a/src/components/ChatReferences.tsx b/src/components/ChatReferences.tsx index 347cf5c..1038cb8 100644 --- a/src/components/ChatReferences.tsx +++ b/src/components/ChatReferences.tsx @@ -1,4 +1,4 @@ -import {VuiFlexContainer, VuiFlexItem, VuiText, VuiAccordion, VuiSpacer, VuiLink} from "../vui"; +import {VuiFlexContainer, VuiFlexItem, VuiText, VuiAccordion, VuiSpacer} from "../vui"; import { SearchResultWithSnippet } from "../types"; type Props = { @@ -44,9 +44,9 @@ const ChatReference = ({ result, position }: { result: SearchResultWithSnippet;

{url ? ( - - {text} - + + {text} + ) : ( text )} diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx index f87a505..447312f 100644 --- a/src/components/ChatView.tsx +++ b/src/components/ChatView.tsx @@ -21,8 +21,8 @@ export interface Props { // Vectara API key apiKey: string; - // Vectara corpus IDs - corpusKey: string; + // Vectara corpus keys + corpusKeys: string; // Title to be shown in the UI header title?: string; @@ -75,7 +75,7 @@ export interface Props { */ export const ChatView = ({ customerId, - corpusKey, + corpusKeys, apiKey, title = "My Chatbot", placeholder = "Chat with your AI Assistant", @@ -97,7 +97,7 @@ export const ChatView = ({ const { sendMessage, startNewConversation, messageHistory, isLoading, hasError, activeMessage, isStreamingResponse } = useChat({ customerId, - corpusKey, + corpusKeys, apiKey, numberOfSearchResults, language, diff --git a/src/components/FactualConsistencyBadge.tsx b/src/components/FactualConsistencyBadge.tsx index 7894cac..b6b0cfd 100644 --- a/src/components/FactualConsistencyBadge.tsx +++ b/src/components/FactualConsistencyBadge.tsx @@ -20,28 +20,28 @@ export const FactualConsistencyBadge = ({ score }: Props) => { } badge = ( - - Factual Consistency Score: {sanitizedScore} - + + Factual Consistency Score: {sanitizedScore} + ); } return ( - - {score === undefined && } - - {badge} - - -

- - What's this? - -

-
- + + {score === undefined && } + + {badge} + + +

+ + What's this? + +

+
+
); }; \ No newline at end of file diff --git a/src/index.test.tsx b/src/index.test.tsx index b5529ad..94d14f1 100644 --- a/src/index.test.tsx +++ b/src/index.test.tsx @@ -6,7 +6,7 @@ import * as useChatInterface from "./useChat"; const MIN_PROPS = { customerId: "mock-customer-id", - corpusKey: "1", + corpusKeys: "1", apiKey: "mock-api-key" }; diff --git a/src/index.tsx b/src/index.tsx index af9ef7e..b3ba92c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -19,7 +19,7 @@ class ReactChatbotWebComponent extends HTMLElement { static get observedAttributes() { return [ "customerid", - "corpuskey", + "corpuskeys", "apikey", "title", "placeholder", @@ -69,7 +69,7 @@ class ReactChatbotWebComponent extends HTMLElement { public connectedCallback() { const customerId = this.getAttribute("customerId") ?? ""; - const corpusKey = (this.getAttribute("corpuskey") ?? ""); + const corpusKeys = (this.getAttribute("corpuskey") ?? ""); const apiKey = this.getAttribute("apiKey") ?? ""; const title = this.getAttribute("title") ?? undefined; const placeholder = this.getAttribute("placeholder") ?? undefined; @@ -92,7 +92,7 @@ class ReactChatbotWebComponent extends HTMLElement {
{ describe("streaming", () => { it("should send messages and update hook values", async () => { const { result } = renderHook(() => - useChat({ customerId: "mock-customer-id", corpusKey: "1", apiKey: "mock-api-key" }) + useChat({ customerId: "mock-customer-id", corpusKeys: "1", apiKey: "mock-api-key" }) ); streamQuerySpy.mockImplementation(async ({onStreamEvent}) => { @@ -85,7 +85,7 @@ describe("useChat", () => { describe("non-streaming", () => { it("should send messages and update message history", async () => { const { result } = renderHook(() => - useChat({ customerId: "mock-customer-id", corpusKey: "1", apiKey: "mock-api-key", enableStreaming: false }) + useChat({ customerId: "mock-customer-id", corpusKeys: "1", apiKey: "mock-api-key", enableStreaming: false }) ); sendSearchRequestSpy.mockImplementation(() => Promise.resolve(MOCK_API_RESPONSE)); @@ -105,7 +105,7 @@ describe("useChat", () => { it("should reflect error state", async () => { const { result } = renderHook(() => - useChat({ customerId: "mock-customer-id", corpusKey: "1", apiKey: "mock-api-key", enableStreaming: false }) + useChat({ customerId: "mock-customer-id", corpusKeys: "1", apiKey: "mock-api-key", enableStreaming: false }) ); sendSearchRequestSpy.mockImplementation(() => { throw "error"; @@ -120,7 +120,7 @@ describe("useChat", () => { it("should reflect loading state", async () => { const { result } = renderHook(() => - useChat({ customerId: "mock-customer-id", corpusKey: "1", apiKey: "mock-api-key" }) + useChat({ customerId: "mock-customer-id", corpusKeys: "1", apiKey: "mock-api-key" }) ); sendSearchRequestSpy.mockImplementation(() => { return new Promise(() => {}); @@ -136,7 +136,7 @@ describe("useChat", () => { it("should be able to reset the conversation", async () => { const { result } = renderHook(() => - useChat({ customerId: "mock-customer-id", corpusKey: "1", apiKey: "mock-api-key", enableStreaming: false }) + useChat({ customerId: "mock-customer-id", corpusKeys: "1", apiKey: "mock-api-key", enableStreaming: false }) ); sendSearchRequestSpy.mockImplementation(() => Promise.resolve(MOCK_API_RESPONSE)); diff --git a/src/useChat.ts b/src/useChat.ts index d317b3d..448387c 100644 --- a/src/useChat.ts +++ b/src/useChat.ts @@ -29,7 +29,7 @@ export const DEFAULT_LAMBDA_VALUE = 0.005 type UseChatConfig = { customerId: string; - corpusKey: string; + corpusKeys: string; apiKey: string; numberOfSearchResults?: number; language?: SummaryLanguage; @@ -42,7 +42,7 @@ type UseChatConfig = { export const useChat = ({ customerId, - corpusKey, + corpusKeys, apiKey, numberOfSearchResults = 10, language = "eng", @@ -157,7 +157,7 @@ export const useChat = ({ apiKey: apiKey!, customerId: customerId!, query: query, - corpusKey: corpusKey!, + corpusKey: corpusKeys!, search: { offset: 0, metadataFilter: "", @@ -203,7 +203,7 @@ export const useChat = ({ apiKey: apiKey!, customerId: customerId!, query: query, - corpusKey: corpusKey!, + corpusKeys: corpusKeys!, search: { offset: 0, metadataFilter: "", diff --git a/src/utils/sendSearchRequest.ts b/src/utils/sendSearchRequest.ts index 92b58ed..9520d76 100644 --- a/src/utils/sendSearchRequest.ts +++ b/src/utils/sendSearchRequest.ts @@ -27,7 +27,7 @@ type Config = { authToken?: string; domain?: string; query: string; - corpusKey: string; + corpusKeys: string; search: { metadataFilter: string; lexicalInterpolation?: number; @@ -108,7 +108,7 @@ const convertCitations = (citations?: GenerationConfig["citations"]) => { */ export const sendSearchRequest = async ({ customerId, - corpusKey, + corpusKeys, apiKey, query, domain, @@ -130,7 +130,7 @@ export const sendSearchRequest = async ({ const body: ChatQueryBody = { query, search: { - corpora: corpusKey.split(",").map((key) => ( + corpora: corpusKeys.split(",").map((key) => ( { corpus_key: key, metadata_filter: metadataFilter,