Skip to content

Commit 43b69d2

Browse files
SaraVieiracdxker
authored andcommitted
feat: add TS instructions tab to get started code
1 parent 95eccf5 commit 43b69d2

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

frontends/dashboard/src/components/CodeExamples.tsx

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import { BiRegularInfoCircle } from "solid-icons/bi";
22
import { Codeblock } from "./Codeblock";
33
import {
44
createChunkRequest,
5+
createChunkRequestTS,
56
hybridSearchRequest,
7+
hybridSearchRequestTS,
68
} from "../utils/createCodeSnippets";
79
import { DatasetContext } from "../contexts/DatasetContext";
8-
import { useContext } from "solid-js";
10+
import { createSignal, useContext } from "solid-js";
11+
import { Button } from "terracotta";
912

1013
export const CodeExamples = () => {
1114
const { datasetId } = useContext(DatasetContext);
@@ -18,7 +21,7 @@ export const CodeExamples = () => {
1821
Initial Request Examples
1922
</h2>
2023
<div class="flex flex-col space-y-4">
21-
<p>1. Add a searchable chunk</p>
24+
<p class="font-medium">1. Add a searchable chunk</p>
2225
<div class="flex w-fit space-x-4 rounded-md border border-blue-600/20 bg-blue-50 px-4 py-4">
2326
<div class="flex">
2427
<div class="flex-shrink-0">
@@ -44,10 +47,13 @@ export const CodeExamples = () => {
4447
</div>
4548
</div>
4649
</div>
47-
<Codeblock content={createChunkRequest(datasetId())} />
50+
<CodeExample
51+
fetchContent={createChunkRequest(datasetId())}
52+
tsContent={createChunkRequestTS(datasetId())}
53+
/>
4854
</div>
4955
<div class="flex flex-col space-y-4">
50-
<p class="mt-3">2. Start Searching</p>
56+
<p class="mt-3 font-medium">2. Start Searching</p>
5157
<div class="flex w-fit space-x-4 rounded-md border border-blue-600/20 bg-blue-50 px-4 py-4">
5258
<div class="flex">
5359
<div class="flex-shrink-0">
@@ -71,8 +77,43 @@ export const CodeExamples = () => {
7177
</div>
7278
</div>
7379
</div>
74-
<Codeblock content={hybridSearchRequest(datasetId())} />
80+
<CodeExample
81+
fetchContent={hybridSearchRequest(datasetId())}
82+
tsContent={hybridSearchRequestTS(datasetId())}
83+
/>
7584
</div>
7685
</section>
7786
);
7887
};
88+
89+
const CodeExample = (props: { tsContent: string; fetchContent: string }) => {
90+
const [selectedTab, setSelectedTab] = createSignal("fetch");
91+
92+
return (
93+
<div>
94+
<div class="mb-4 flex gap-4 border-b pb-1">
95+
<Button
96+
classList={{
97+
"font-medium": true,
98+
"text-fuchsia-800": selectedTab() === "fetch",
99+
}}
100+
onClick={() => setSelectedTab("fetch")}
101+
>
102+
Using Fetch
103+
</Button>
104+
<Button
105+
classList={{
106+
"font-medium": true,
107+
"text-fuchsia-800": selectedTab() === "ts",
108+
}}
109+
onClick={() => setSelectedTab("ts")}
110+
>
111+
Using the TS SDK
112+
</Button>
113+
</div>
114+
<Codeblock
115+
content={selectedTab() === "ts" ? props.tsContent : props.fetchContent}
116+
/>
117+
</div>
118+
);
119+
};

frontends/dashboard/src/utils/createCodeSnippets.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ export const createChunkRequest = (
1717
`;
1818
};
1919

20+
export const createChunkRequestTS = (
21+
dataset: string,
22+
) => `import { TrieveSDK } from "trieve-ts-sdk";
23+
24+
export const trieve = new TrieveSDK({
25+
apiKey: "tr-********************************",
26+
datasetId: "${dataset}",
27+
});
28+
29+
const data = await trieve.createChunk({
30+
chunk_html:
31+
"If the rise of an all-powerful artificial intelligence is inevitable, well it stands to reason that when they take power, our digital overlords will punish those of us who did not help them get there. Ergo, I would like to be a helpful idiot. Like yourself.",
32+
link: "https://www.hbo.com/silicon-valley",
33+
});
34+
`;
35+
2036
export const hybridSearchRequest = (
2137
dataset: string = "********-****-****-****-************",
2238
) => {
@@ -34,3 +50,18 @@ export const hybridSearchRequest = (
3450
});
3551
`;
3652
};
53+
54+
export const hybridSearchRequestTS = (
55+
dataset: string,
56+
) => `import { TrieveSDK } from "trieve-ts-sdk";
57+
58+
export const trieve = new TrieveSDK({
59+
apiKey: "tr-********************************",
60+
datasetId: "${dataset}",
61+
});
62+
63+
const data = await trieve.search({
64+
query: "AI will take over and maybe reward those who aided its rise",
65+
search_type: "hybrid",
66+
});
67+
`;

0 commit comments

Comments
 (0)