tako-sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -38
- package/dist/index.cjs +17 -21
- package/dist/index.js +17 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,9 +25,7 @@ const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015'
|
|
|
25
25
|
console.log(results.outputs.knowledge_cards);
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
### Next.js API Route (App Router)
|
|
28
|
+
### Usage Example: Next.js API Route (App Router)
|
|
31
29
|
|
|
32
30
|
```typescript
|
|
33
31
|
// app/api/tako-search/route.ts
|
|
@@ -50,34 +48,9 @@ export async function POST(request: Request) {
|
|
|
50
48
|
}
|
|
51
49
|
```
|
|
52
50
|
|
|
53
|
-
### Edge API Route
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
// app/api/tako-edge/route.ts
|
|
57
|
-
import { createTakoClient } from 'tako-sdk';
|
|
58
|
-
import { NextResponse } from 'next/server';
|
|
59
|
-
|
|
60
|
-
export const runtime = 'edge';
|
|
61
|
-
|
|
62
|
-
export async function POST(request: Request) {
|
|
63
|
-
const { query, sourceIndexes } = await request.json();
|
|
64
|
-
const tako = createTakoClient(process.env.TAKO_API_KEY!);
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const results = await tako.knowledgeSearch(query, sourceIndexes);
|
|
68
|
-
return NextResponse.json(results);
|
|
69
|
-
} catch (error: any) {
|
|
70
|
-
return NextResponse.json(
|
|
71
|
-
{ error: error.message || 'An error occurred' },
|
|
72
|
-
{ status: error.status || 500 }
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
51
|
## API Reference
|
|
79
52
|
|
|
80
|
-
### `createTakoClient(apiKey
|
|
53
|
+
### `createTakoClient(apiKey)`
|
|
81
54
|
|
|
82
55
|
Creates a new Tako API client.
|
|
83
56
|
|
|
@@ -87,7 +60,6 @@ const tako = createTakoClient('your-api-key');
|
|
|
87
60
|
|
|
88
61
|
Parameters:
|
|
89
62
|
- `apiKey` (string): Your Tako API key
|
|
90
|
-
- `baseUrl` (string, optional): Override the default API base URL
|
|
91
63
|
|
|
92
64
|
### `takoClient.knowledgeSearch(text, sourceIndexes?)`
|
|
93
65
|
|
|
@@ -99,17 +71,10 @@ const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015'
|
|
|
99
71
|
|
|
100
72
|
Parameters:
|
|
101
73
|
- `text` (string): The natural language query text
|
|
102
|
-
- `sourceIndexes` (
|
|
74
|
+
- `sourceIndexes` (SourceIndex[], optional): Array of source indexes to search within. Available values: `SourceIndex.TAKO` or `SourceIndex.WEB`
|
|
103
75
|
|
|
104
76
|
Returns: `Promise<KnowledgeSearchResponse>`
|
|
105
77
|
|
|
106
|
-
## Examples
|
|
107
|
-
|
|
108
|
-
The SDK includes several examples in the `examples/` directory:
|
|
109
|
-
|
|
110
|
-
- `edge-api-route.ts` - Edge Runtime API route example
|
|
111
|
-
- `next-api-route.ts` - Standard Next.js API route example
|
|
112
|
-
|
|
113
78
|
## Error Handling
|
|
114
79
|
|
|
115
80
|
The SDK throws typed errors with status codes and messages:
|
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var TakoClient = class {
|
|
|
55
55
|
async request(path, method, body) {
|
|
56
56
|
const url = `${this.baseUrl}${path}`;
|
|
57
57
|
const headers = {
|
|
58
|
-
|
|
58
|
+
"X-API-Key": this.apiKey,
|
|
59
59
|
"Content-Type": "application/json"
|
|
60
60
|
};
|
|
61
61
|
const options = {
|
|
@@ -63,27 +63,16 @@ var TakoClient = class {
|
|
|
63
63
|
headers,
|
|
64
64
|
body: body ? JSON.stringify(body) : void 0
|
|
65
65
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const errorData = await response.json();
|
|
70
|
-
throw {
|
|
71
|
-
status: response.status,
|
|
72
|
-
message: errorData.message || response.statusText,
|
|
73
|
-
details: errorData
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return await response.json();
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (error.status) {
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
66
|
+
const response = await fetch(url, options);
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
const errorData = await response.json();
|
|
81
69
|
throw {
|
|
82
|
-
status:
|
|
83
|
-
message:
|
|
84
|
-
details:
|
|
70
|
+
status: response.status,
|
|
71
|
+
message: errorData.message || response.statusText,
|
|
72
|
+
details: errorData
|
|
85
73
|
};
|
|
86
74
|
}
|
|
75
|
+
return await response.json();
|
|
87
76
|
}
|
|
88
77
|
/**
|
|
89
78
|
* Search Tako Knowledge using natural language
|
|
@@ -98,10 +87,17 @@ var TakoClient = class {
|
|
|
98
87
|
const requestBody = {
|
|
99
88
|
inputs: {
|
|
100
89
|
text,
|
|
101
|
-
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : {}
|
|
90
|
+
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : { source_indexes: ["tako" /* TAKO */] }
|
|
102
91
|
}
|
|
103
92
|
};
|
|
104
|
-
|
|
93
|
+
try {
|
|
94
|
+
return await this.request("/knowledge_search", "POST", requestBody);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error.status === 404) {
|
|
97
|
+
return { outputs: { knowledge_cards: [] } };
|
|
98
|
+
}
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
105
101
|
}
|
|
106
102
|
};
|
|
107
103
|
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var TakoClient = class {
|
|
|
28
28
|
async request(path, method, body) {
|
|
29
29
|
const url = `${this.baseUrl}${path}`;
|
|
30
30
|
const headers = {
|
|
31
|
-
|
|
31
|
+
"X-API-Key": this.apiKey,
|
|
32
32
|
"Content-Type": "application/json"
|
|
33
33
|
};
|
|
34
34
|
const options = {
|
|
@@ -36,27 +36,16 @@ var TakoClient = class {
|
|
|
36
36
|
headers,
|
|
37
37
|
body: body ? JSON.stringify(body) : void 0
|
|
38
38
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const errorData = await response.json();
|
|
43
|
-
throw {
|
|
44
|
-
status: response.status,
|
|
45
|
-
message: errorData.message || response.statusText,
|
|
46
|
-
details: errorData
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return await response.json();
|
|
50
|
-
} catch (error) {
|
|
51
|
-
if (error.status) {
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
39
|
+
const response = await fetch(url, options);
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const errorData = await response.json();
|
|
54
42
|
throw {
|
|
55
|
-
status:
|
|
56
|
-
message:
|
|
57
|
-
details:
|
|
43
|
+
status: response.status,
|
|
44
|
+
message: errorData.message || response.statusText,
|
|
45
|
+
details: errorData
|
|
58
46
|
};
|
|
59
47
|
}
|
|
48
|
+
return await response.json();
|
|
60
49
|
}
|
|
61
50
|
/**
|
|
62
51
|
* Search Tako Knowledge using natural language
|
|
@@ -71,10 +60,17 @@ var TakoClient = class {
|
|
|
71
60
|
const requestBody = {
|
|
72
61
|
inputs: {
|
|
73
62
|
text,
|
|
74
|
-
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : {}
|
|
63
|
+
...sourceIndexes && sourceIndexes.length > 0 ? { source_indexes: sourceIndexes } : { source_indexes: ["tako" /* TAKO */] }
|
|
75
64
|
}
|
|
76
65
|
};
|
|
77
|
-
|
|
66
|
+
try {
|
|
67
|
+
return await this.request("/knowledge_search", "POST", requestBody);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error.status === 404) {
|
|
70
|
+
return { outputs: { knowledge_cards: [] } };
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
78
74
|
}
|
|
79
75
|
};
|
|
80
76
|
|