Skip to content

Commit

Permalink
(EAI-155) [UI] Make serverBaseUrl required (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlarew authored Sep 30, 2024
1 parent ffb2ccb commit 51fe839
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/docs/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The `<Chatbot />` component is effectively a React context provider that wraps y
| `name` | `string?` | The name of the chatbot. Used as the default in text throughout the UI. | If unspecified, the chatbot is anonymous. |
| `onClose` | `(() => void)?` | A callback that is invoked whenever the chatbot view closes | |
| `onOpen` | `(() => void)?` | A callback that is invoked whenever the chatbot view opens | |
| `serverBaseUrl` | `string?` | The base URL for the Chatbot API. | `https://knowledge.mongodb.com/api/v1` |
| `serverBaseUrl` | `string` | The base URL for the Chatbot API. | `https://knowledge.mongodb.com/api/v1` |
| `shouldStream` | `boolean?` | If `true`, responses are streamed with SSE. Otherwise the entire response is awaited. | If the browser supports SSE, `true`, else `false`. |
| `tck` | `string?` | An analytics identifier to add to the end of all hyperlinks. | `"docs_chatbot"` |
| `user` | `{ name: string; }?` | An object with information about the current user (if there is one). | `undefined` |
Expand Down
5 changes: 5 additions & 0 deletions packages/mongodb-chatbot-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const SUGGESTED_PROMPTS = [
"Why should I use Atlas Search?",
];

const serverBaseUrl =
import.meta.env.VITE_SERVER_BASE_URL ?? "http://localhost:3000/api/v1";

const initialMessageReferences = [
{
url: "https://docs.mongodb.com/",
Expand Down Expand Up @@ -62,6 +65,7 @@ function App() {
<div className={styles.main_content}>
<Chatbot
name="MongoDB AI (Docs)"
serverBaseUrl={serverBaseUrl}
shouldStream={shouldStream}
darkMode={darkMode}
fetchOptions={{ credentials: "include" }}
Expand All @@ -78,6 +82,7 @@ function App() {
</Chatbot>
<Chatbot
name="MongoDB AI (Dev Center)"
serverBaseUrl={serverBaseUrl}
shouldStream={shouldStream}
darkMode={darkMode}
fetchOptions={{ credentials: "include" }}
Expand Down
6 changes: 3 additions & 3 deletions packages/mongodb-chatbot-ui/src/useConversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,16 @@ function conversationReducer(
}

export type UseConversationParams = {
serverBaseUrl?: string;
serverBaseUrl: string;
shouldStream?: boolean;
sortMessageReferences?: SortReferences;
fetchOptions?: ConversationFetchOptions;
};

export function useConversation(params: UseConversationParams = {}) {
export function useConversation(params: UseConversationParams) {
const conversationService = useMemo(() => {
return new ConversationService({
serverUrl: params.serverBaseUrl ?? import.meta.env.VITE_SERVER_BASE_URL,
serverUrl: params.serverBaseUrl,
fetchOptions: params.fetchOptions,
});
}, [params.serverBaseUrl, params.fetchOptions]);
Expand Down

0 comments on commit 51fe839

Please sign in to comment.