Skip to content

Commit 4804478

Browse files
authored
Added Chatbot (#857)
<!-- Explain the changes introduced in your PR --> ## Pull Request approval You will need to get your PR approved by at least one member of the Sourcegraph team. For reviews of docs formatting, styles, and component usage, please tag the docs team via the #docs Slack channel.
1 parent d3af603 commit 4804478

File tree

7 files changed

+2011
-489
lines changed

7 files changed

+2011
-489
lines changed

baseai/memory/docs/index.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import { MemoryI } from '@baseai/core';
2-
import path from 'path';
32

43
const memoryDocs = (): MemoryI => ({
54
name: 'docs',
65
description: 'Docs folder of sourcegraph docs repository as an auto-synced memory',
7-
config: {
8-
useGitRepo: true,
9-
dirToTrack: path.posix.join('.', 'docs'),
10-
extToTrack: [".md", ".mdx"]
11-
}
6+
git: {
7+
enabled: true,
8+
include: ['**/*'],
9+
gitignore: true,
10+
deployedAt: '',
11+
embeddedAt: '',
12+
},
13+
documents: {
14+
meta: doc => {
15+
const url = `https://sourcegraph.com/docs/${doc.path}`;
16+
return {
17+
url,
18+
name: doc.name,
19+
};
20+
},
21+
},
1222
});
1323

1424
export default memoryDocs;

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"dependencies": {
1414
"@algolia/autocomplete-core": "^1.9.2",
1515
"@algolia/client-search": "^4.22.1",
16-
"@baseai/core": "^0.9.8",
16+
"@baseai/core": "^0.9.40",
1717
"@docsearch/react": "3",
1818
"@headlessui/react": "^1.7.13",
1919
"@heroicons/react": "^2.0.18",
20+
"@langbase/components": "^0.1.5",
2021
"@mdx-js/mdx": "^3.0.1",
2122
"@next/third-parties": "^14.1.4",
2223
"@radix-ui/react-hover-card": "^1.1.1",
@@ -39,6 +40,7 @@
3940
"github-slugger": "^2.0.0",
4041
"js-yaml": "^4.1.0",
4142
"kbar": "^0.1.0-beta.44",
43+
"langbase": "^1.1.11",
4244
"lucide-react": "^0.372.0",
4345
"mdx": "^0.3.1",
4446
"next": "^14.2.3",
@@ -63,7 +65,7 @@
6365
"unist-util-visit": "^5.0.0"
6466
},
6567
"devDependencies": {
66-
"baseai": "^0.9.8",
68+
"baseai": "^0.9.40",
6769
"eslint": "8.45.0",
6870
"eslint-config-next": "13.4.16",
6971
"prettier": "^3.0.1",

pnpm-lock.yaml

Lines changed: 1838 additions & 479 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/api/chat/route.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { NextRequest } from 'next/server';
2+
import { Langbase } from 'langbase';
3+
4+
const langbase = new Langbase({
5+
apiKey: process.env.LANGBASE_API_KEY!
6+
});
7+
8+
export async function POST(req: NextRequest) {
9+
const options = await req.json();
10+
const { stream, threadId } = await langbase.pipe.run({
11+
...options,
12+
name: 'docs-agent-cody-api'
13+
});
14+
15+
return new Response(stream, {
16+
status: 200,
17+
headers: {
18+
'lb-thread-id': threadId ?? ''
19+
}
20+
});
21+
}

src/app/layout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import config from 'docs.config';
66
import { type Metadata } from 'next';
77
import { Inter } from 'next/font/google';
88
import localFont from 'next/font/local';
9+
import Chatbot from '@/components/ChatBot';
910

10-
11-
11+
import '@langbase/components/styles'
1212
import '@/styles/tailwind.css';
1313

1414
const inter = Inter({
@@ -68,6 +68,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
6868
className="flex min-h-full bg-light-bg dark:bg-dark-bg"
6969
>
7070
<Providers>
71+
{/* <Chatbot /> */}
7172
<Layout>{children}</Layout>
7273
</Providers>
7374
</body>

src/components/ChatBot/index.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use client';
2+
3+
import { Chatbot } from '@langbase/components';
4+
5+
import './styles.css'
6+
7+
export default function App() {
8+
9+
return (
10+
<Chatbot
11+
badge='Experimental'
12+
apiRoute="/docs/api/chat"
13+
openingMessage='Find precise answers to any question about Sourcegraph documentation with our AI chatbot.'
14+
suggestions={[
15+
{
16+
title: `Explain how to get started in easy steps`,
17+
prompt: `Explain how to get started in easy steps?`,
18+
},
19+
{
20+
title: `How do I create an API key?`,
21+
prompt: `How do I create an API key?`,
22+
},
23+
{
24+
title: `What are the supported providers?`,
25+
prompt: `What are the supported providers?`,
26+
},
27+
{
28+
title: `How do I reset my password?`,
29+
prompt: `How do I reset my password?`,
30+
},
31+
]}
32+
customStyles={{
33+
chatBtn: {
34+
foregroundColor: '#14171F',
35+
},
36+
}}
37+
/>
38+
);
39+
}

src/components/ChatBot/styles.css

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.lb-bg-background {
2+
background-color: #F9FAFB;
3+
}
4+
5+
.lb-bg-muted {
6+
background-color: #f4f4f5;
7+
}
8+
9+
.lb-text-primary-foreground {
10+
color: #0F172A;
11+
background-color: #ffffff;
12+
border-width: 1;
13+
border-color: rgb(219 226 240);
14+
}
15+
16+
.light button.hover\:lb-bg-foreground:hover {
17+
background-color: #F9FAFB;
18+
color: #0F172A !important
19+
}
20+
21+
button.lb-text-primary-foreground {
22+
background-color: #ffffff;
23+
}
24+
25+
.light .lb-border-muted-foreground\/40 {
26+
border-color: rgb(219 226 240) !important;
27+
}
28+
29+
.light .lb-text-primary-foreground:hover {
30+
background-color: #ffffff;
31+
}
32+
33+
.lb-text-inherit {
34+
color: #334155;
35+
}
36+
37+
.lb-line-clamp-2 {
38+
color: #334155 !important;
39+
}
40+
.dark .lb-border-border {
41+
border-color: rgb(38 43 56);
42+
}
43+
44+
.dark .lb-text-primary-foreground {
45+
color: #F9FAFB;
46+
background-color: rgb(29 33 47);
47+
border-width: 1;
48+
border-color: rgb(38 43 56);
49+
}
50+
51+
.dark .lb-border-muted-foreground {
52+
border-color: rgb(38 43 56);
53+
}
54+
55+
.dark .lb-bg-background {
56+
background-color: #14171F;
57+
}
58+
59+
.dark .lb-bg-muted {
60+
background-color: #171B26;
61+
}
62+
63+
.dark .lb-bg-border {
64+
border-color: rgb(38 43 56);
65+
background-color: rgb(38 43 56);
66+
}
67+
68+
.dark .sm\:lb-border-border {
69+
border-color: rgb(38 43 56);
70+
}
71+
72+
.dark .lb-text-inherit {
73+
color: #94A3B8;
74+
}
75+
76+
.dark .lb-line-clamp-2 {
77+
color: #94A3B8 !important;
78+
}
79+
80+
.dark button.hover\:lb-bg-foreground:hover {
81+
color: #F9FAFB !important
82+
}
83+
84+
.dark .hover\:lb-bg-secondary\/60:hover {
85+
background-color: #171B26;
86+
}
87+
88+
.dark .hover\:lb-bg-accent:hover {
89+
background-color: #171B26;
90+
}

0 commit comments

Comments
 (0)