Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit 6171aed

Browse files
authored
Update static methods for namespace and serviceurl (#13)
* wip * update static methods for namespace and serviceurl, update tests * remove test.only
1 parent 1994ba2 commit 6171aed

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "getindexify",
3-
"version": "0.0.19",
3+
"version": "0.0.20",
44
"description": "This is the TypeScript client for interacting with the Indexify service.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

packages/langchain/tests/langchain.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ jest.setTimeout(30000);
1515

1616
test("Langchain Rag", async () => {
1717
// setup client
18-
const client = await IndexifyClient.createNamespace("testlangchain");
18+
const client = await IndexifyClient.createNamespace({
19+
namespace: "testlangchain",
20+
});
1921
client.addExtractionPolicy({
2022
extractor: "tensorlake/minilm-l6",
2123
name: "minilml6",

src/client.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,24 @@ class IndexifyClient {
101101
return this.request("GET", endpoint);
102102
}
103103

104-
static async namespaces(): Promise<INamespace[]> {
105-
const response = await axios.get(`${DEFAULT_SERVICE_URL}/namespaces`);
104+
static async namespaces({
105+
serviceUrl = DEFAULT_SERVICE_URL,
106+
}: {
107+
serviceUrl?: string;
108+
} = {}): Promise<INamespace[]> {
109+
const response = await axios.get(`${serviceUrl}/namespaces`);
106110
return response.data.namespaces;
107111
}
108112

109-
static async createNamespace(
110-
namespace: string,
111-
extraction_policies?: IExtractionPolicy[],
112-
labels?: Record<string, string>
113-
) {
113+
static async createNamespace({
114+
namespace,
115+
extraction_policies,
116+
labels,
117+
}: {
118+
namespace: string;
119+
extraction_policies?: IExtractionPolicy[];
120+
labels?: Record<string, string>;
121+
}) {
114122
await axios.post(`${DEFAULT_SERVICE_URL}/namespaces`, {
115123
name: namespace,
116124
extraction_policies: extraction_policies ?? [],
@@ -126,7 +134,7 @@ class IndexifyClient {
126134
}
127135

128136
async extractors(): Promise<Extractor[]> {
129-
const response = await axios.get(`${DEFAULT_SERVICE_URL}/extractors`);
137+
const response = await axios.get(`${this.serviceUrl}/extractors`);
130138
const extractorsData = response.data.extractors as IExtractor[];
131139
return extractorsData.map((data) => new Extractor(data));
132140
}

tests/client.test.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ test("Create Client", async () => {
99
});
1010

1111
test("Create Namespace", async () => {
12-
const client = await IndexifyClient.createNamespace("testnamespace", [
13-
{
14-
extractor: "tensorlake/minilm-l6",
15-
name: "testpolicy",
16-
},
17-
]);
12+
const client = await IndexifyClient.createNamespace({
13+
namespace: "testnamespace",
14+
extraction_policies: [
15+
{
16+
extractor: "tensorlake/minilm-l6",
17+
name: "testpolicy",
18+
},
19+
],
20+
});
1821

1922
expect(client.namespace).toBe("testnamespace");
2023
// test get namespaces
@@ -31,11 +34,9 @@ test("Get Extractors", async () => {
3134
});
3235

3336
test("Add Documents", async () => {
34-
const client = await IndexifyClient.createNamespace(
35-
"test.adddocuments",
36-
[],
37-
{}
38-
);
37+
const client = await IndexifyClient.createNamespace({
38+
namespace: "test.adddocuments",
39+
});
3940

4041
// add single documents
4142
await client.addDocuments({ text: "This is a test", labels: {} });
@@ -74,7 +75,10 @@ test("Search", async () => {
7475
labels_eq: "source:test",
7576
};
7677

77-
const client = await IndexifyClient.createNamespace("testsearch");
78+
const client = await IndexifyClient.createNamespace({
79+
namespace: "testsearch",
80+
});
81+
console.log('got namespace?', client.namespace)
7882
const resp = await client.addExtractionPolicy(policy);
7983
expect(resp.index_names.length).toBe(1);
8084

@@ -85,7 +89,7 @@ test("Search", async () => {
8589
{ text: "This is a test2", labels: { source: "test" } },
8690
]);
8791

88-
await new Promise((r) => setTimeout(r, 10000));
92+
await new Promise((r) => setTimeout(r, 15000));
8993

9094
const searchResult = await client.searchIndex(indexName, "test", 3);
9195
expect(searchResult.length).toBe(2);
@@ -99,14 +103,18 @@ test("Upload file", async () => {
99103
input_params: {},
100104
};
101105

102-
const client = await IndexifyClient.createNamespace("testuploadfile");
106+
const client = await IndexifyClient.createNamespace({
107+
namespace: "testuploadfile",
108+
});
103109
client.addExtractionPolicy(policy);
104110
await client.uploadFile(`${__dirname}/files/test.txt`);
105111
console.log("done");
106112
});
107113

108114
test("Get content", async () => {
109-
const client = await IndexifyClient.createNamespace("testgetcontent");
115+
const client = await IndexifyClient.createNamespace({
116+
namespace: "testgetcontent",
117+
});
110118
await client.addDocuments([
111119
{ text: "This is a test1", labels: { source: "test" } },
112120
{ text: "This is a test2", labels: { source: "test" } },
@@ -126,7 +134,9 @@ test("Get content", async () => {
126134
});
127135

128136
test("Download content", async () => {
129-
const client = await IndexifyClient.createNamespace("testgetcontent");
137+
const client = await IndexifyClient.createNamespace({
138+
namespace: "testgetcontent",
139+
});
130140
await client.addDocuments([
131141
{ text: "This is a download", labels: { source: "testdownload" } },
132142
]);
@@ -139,7 +149,9 @@ test("Download content", async () => {
139149
});
140150

141151
test("Get Extraction Policies", async () => {
142-
const client = await IndexifyClient.createNamespace("testgetpolicies");
152+
const client = await IndexifyClient.createNamespace({
153+
namespace: "testgetpolicies",
154+
});
143155

144156
await client.addExtractionPolicy({
145157
extractor: "tensorlake/minilm-l6",

0 commit comments

Comments
 (0)