hive-intelligence 0.1.0
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/.env,example +1 -0
- package/README.md +77 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +52 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +15 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.js +2 -0
- package/example.ts +35 -0
- package/jest.config.js +7 -0
- package/package.json +23 -0
- package/src/client.js +52 -0
- package/src/client.ts +42 -0
- package/src/errors.js +15 -0
- package/src/errors.ts +11 -0
- package/src/index.js +20 -0
- package/src/index.ts +5 -0
- package/src/types.js +2 -0
- package/src/types.ts +21 -0
- package/tests/client.test.js +28 -0
- package/tests/client.test.ts +18 -0
- package/tests/hive.test.js +69 -0
- package/tests/hive.test.ts +63 -0
- package/tsconfig.json +117 -0
package/.env,example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
HIVE_API_KEY=
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# ๐ง Hive Intelligence TypeScript SDK
|
|
2
|
+
|
|
3
|
+
The Hive Intelligence SDK lets you integrate real-time crypto and Web3 intelligence into your JavaScript or TypeScript apps using simple prompt or chat-style inputs.
|
|
4
|
+
|
|
5
|
+
## ๐ Installation
|
|
6
|
+
|
|
7
|
+
Using npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install hive-intelligence
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or using yarn:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add hive-intelligence
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## ๐ Setup
|
|
20
|
+
Set your Hive API key as an environment variable:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
export HIVE_API_KEY=your_api_key_here
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## ๐งช Example Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { HiveSearchClient } from 'hive-intelligence';
|
|
30
|
+
import { HiveSearchRequest, HiveSearchMessage, HiveSearchResponse} from 'hive-intelligence/types';
|
|
31
|
+
|
|
32
|
+
// Get API key from env
|
|
33
|
+
const apiKey = process.env.HIVE_API_KEY;
|
|
34
|
+
if (!apiKey) {
|
|
35
|
+
throw new Error('Please set the HIVE_API_KEY environment variable');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Initialize client
|
|
39
|
+
const client = new HiveSearchClient(apiKey);
|
|
40
|
+
|
|
41
|
+
// ๐ก Example 1: Prompt-based query
|
|
42
|
+
const promptRequest: HiveSearchRequest = {
|
|
43
|
+
prompt: 'What is the current price of Ethereum?'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
client.search(promptRequest).then((response: HiveSearchResponse) => {
|
|
47
|
+
console.log('Prompt Response:', response);
|
|
48
|
+
}).catch(console.error);
|
|
49
|
+
|
|
50
|
+
// ๐ข Example 2: Chat-style query
|
|
51
|
+
const chatRequest: HiveSearchRequest = {
|
|
52
|
+
messages: [
|
|
53
|
+
{ role: 'user', content: 'Price of' },
|
|
54
|
+
{ role: 'assistant', content: 'Price of what?' },
|
|
55
|
+
{ role: 'user', content: 'BTC' }
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
client.search(chatRequest).then((response: HiveSearchResponse) => {
|
|
60
|
+
console.log('Chat Response:', response);
|
|
61
|
+
}).catch(console.error);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## ๐ Request Options
|
|
65
|
+
* `prompt`: Plaintext question or query
|
|
66
|
+
* `messages`: Array of `{ role, content }` for chat
|
|
67
|
+
* Optional parameters:
|
|
68
|
+
* `temperature`: (e.g. 0.7) randomness of response
|
|
69
|
+
* `top_k`: max tokens considered
|
|
70
|
+
* `top_p`: nucleus sampling
|
|
71
|
+
* `include_data_sources`: show source info
|
|
72
|
+
|
|
73
|
+
## โ Error Handling
|
|
74
|
+
On error, the SDK throws `HiveSearchAPIError` with:
|
|
75
|
+
* `status`: HTTP status code
|
|
76
|
+
* `statusText`: status message
|
|
77
|
+
* `body`: full API response
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/client.ts
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.HiveSearchClient = void 0;
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const errors_1 = require("./errors");
|
|
19
|
+
class HiveSearchClient {
|
|
20
|
+
constructor(apiKey) {
|
|
21
|
+
this.baseUrl = 'https://api.hiveintelligence.xyz/v1/search';
|
|
22
|
+
this.apiKey = apiKey;
|
|
23
|
+
}
|
|
24
|
+
search(params) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
const response = yield axios_1.default.post(this.baseUrl, params, {
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return response.data;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.response) {
|
|
37
|
+
// Extracting error details from the API response
|
|
38
|
+
const errorMessage = error.response.data.error || error.response.data.message || 'Unknown error';
|
|
39
|
+
// Throwing the custom error with the extracted message
|
|
40
|
+
throw new errors_1.HiveSearchAPIError(error.response.status, error.response.statusText, error.response.data, // Body of the response
|
|
41
|
+
errorMessage // Message from the response
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// If no response was received, throw a general error
|
|
46
|
+
throw new Error('Unknown error occurred while calling HiveSearch API');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.HiveSearchClient = HiveSearchClient;
|
package/dist/errors.d.ts
ADDED
package/dist/errors.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HiveSearchAPIError = void 0;
|
|
4
|
+
class HiveSearchAPIError extends Error {
|
|
5
|
+
constructor(status, statusText, body, message // Add message to hold the specific error details
|
|
6
|
+
) {
|
|
7
|
+
super(`HiveSearch API Error: ${status} ${statusText} - ${message}`);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.statusText = statusText;
|
|
10
|
+
this.body = body;
|
|
11
|
+
this.message = message;
|
|
12
|
+
this.name = 'HiveSearchAPIError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.HiveSearchAPIError = HiveSearchAPIError;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/index.ts
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./client"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./errors"), exports);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface HiveSearchMessage {
|
|
2
|
+
role: 'user' | 'assistant';
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface HiveSearchRequest {
|
|
6
|
+
prompt?: string;
|
|
7
|
+
messages?: HiveSearchMessage[];
|
|
8
|
+
temperature?: number;
|
|
9
|
+
top_k?: number;
|
|
10
|
+
top_p?: number;
|
|
11
|
+
include_data_sources?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface HiveSearchResponse {
|
|
14
|
+
response: {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
};
|
|
17
|
+
isAdditionalDataRequired: [] | null;
|
|
18
|
+
data_sources?: string[];
|
|
19
|
+
}
|
package/dist/types.js
ADDED
package/example.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HiveSearchClient } from './dist/client'
|
|
2
|
+
import { HiveSearchRequest, HiveSearchMessage, HiveSearchResponse } from './dist/types'
|
|
3
|
+
import { config } from 'dotenv';
|
|
4
|
+
config();
|
|
5
|
+
|
|
6
|
+
// Get API key from env
|
|
7
|
+
const apiKey = process.env.HIVE_API_KEY;
|
|
8
|
+
if (!apiKey) {
|
|
9
|
+
throw new Error('Please set the HIVE_API_KEY environment variable');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Initialize client
|
|
13
|
+
const client = new HiveSearchClient(apiKey);
|
|
14
|
+
|
|
15
|
+
// ๐ก Example 1: Prompt-based query
|
|
16
|
+
const promptRequest: HiveSearchRequest = {
|
|
17
|
+
prompt: 'What is the current price of Ethereum?'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
client.search(promptRequest).then((response: HiveSearchResponse) => {
|
|
21
|
+
console.log('Prompt Response:', response);
|
|
22
|
+
}).catch(console.error);
|
|
23
|
+
|
|
24
|
+
// ๐ข Example 2: Chat-style query
|
|
25
|
+
const chatRequest: HiveSearchRequest = {
|
|
26
|
+
messages: [
|
|
27
|
+
{ role: 'user', content: 'Price of' },
|
|
28
|
+
{ role: 'assistant', content: 'Price of what?' },
|
|
29
|
+
{ role: 'user', content: 'BTC' }
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
client.search(chatRequest).then((response: HiveSearchResponse) => {
|
|
34
|
+
console.log('Chat Response:', response);
|
|
35
|
+
}).catch(console.error);
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hive-intelligence",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"test": "jest"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [],
|
|
11
|
+
"author": "",
|
|
12
|
+
"description": "",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"axios": "^1.8.4",
|
|
15
|
+
"dotenv": "^16.5.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jest": "^29.5.14",
|
|
19
|
+
"jest": "^29.7.0",
|
|
20
|
+
"ts-jest": "^29.3.1",
|
|
21
|
+
"typescript": "^5.8.3"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/client.ts
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.HiveSearchClient = void 0;
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const errors_1 = require("./errors");
|
|
19
|
+
class HiveSearchClient {
|
|
20
|
+
constructor(apiKey) {
|
|
21
|
+
this.baseUrl = 'https://api.hiveintelligence.xyz/v1/search';
|
|
22
|
+
this.apiKey = apiKey;
|
|
23
|
+
}
|
|
24
|
+
search(params) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
const response = yield axios_1.default.post(this.baseUrl, params, {
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return response.data;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.response) {
|
|
37
|
+
// Extracting error details from the API response
|
|
38
|
+
const errorMessage = error.response.data.error || error.response.data.message || 'Unknown error';
|
|
39
|
+
// Throwing the custom error with the extracted message
|
|
40
|
+
throw new errors_1.HiveSearchAPIError(error.response.status, error.response.statusText, error.response.data, // Body of the response
|
|
41
|
+
errorMessage // Message from the response
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// If no response was received, throw a general error
|
|
46
|
+
throw new Error('Unknown error occurred while calling HiveSearch API');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.HiveSearchClient = HiveSearchClient;
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import { HiveSearchRequest, HiveSearchResponse } from './types';
|
|
5
|
+
import { HiveSearchAPIError } from './errors';
|
|
6
|
+
|
|
7
|
+
export class HiveSearchClient {
|
|
8
|
+
private readonly apiKey: string;
|
|
9
|
+
private readonly baseUrl: string = 'https://api.hiveintelligence.xyz/v1/search';
|
|
10
|
+
|
|
11
|
+
constructor(apiKey: string) {
|
|
12
|
+
this.apiKey = apiKey;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async search(params: HiveSearchRequest): Promise<HiveSearchResponse> {
|
|
16
|
+
try {
|
|
17
|
+
const response = await axios.post(this.baseUrl, params, {
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
24
|
+
} catch (error: any) {
|
|
25
|
+
if (error.response) {
|
|
26
|
+
// Extracting error details from the API response
|
|
27
|
+
const errorMessage = error.response.data.error || error.response.data.message || 'Unknown error';
|
|
28
|
+
|
|
29
|
+
// Throwing the custom error with the extracted message
|
|
30
|
+
throw new HiveSearchAPIError(
|
|
31
|
+
error.response.status,
|
|
32
|
+
error.response.statusText,
|
|
33
|
+
error.response.data, // Body of the response
|
|
34
|
+
errorMessage // Message from the response
|
|
35
|
+
);
|
|
36
|
+
} else {
|
|
37
|
+
// If no response was received, throw a general error
|
|
38
|
+
throw new Error('Unknown error occurred while calling HiveSearch API');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HiveSearchAPIError = void 0;
|
|
4
|
+
class HiveSearchAPIError extends Error {
|
|
5
|
+
constructor(status, statusText, body, message // Add message to hold the specific error details
|
|
6
|
+
) {
|
|
7
|
+
super(`HiveSearch API Error: ${status} ${statusText} - ${message}`);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.statusText = statusText;
|
|
10
|
+
this.body = body;
|
|
11
|
+
this.message = message;
|
|
12
|
+
this.name = 'HiveSearchAPIError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.HiveSearchAPIError = HiveSearchAPIError;
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class HiveSearchAPIError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
public status: number,
|
|
4
|
+
public statusText: string,
|
|
5
|
+
public body: any,
|
|
6
|
+
public message: string // Add message to hold the specific error details
|
|
7
|
+
) {
|
|
8
|
+
super(`HiveSearch API Error: ${status} ${statusText} - ${message}`);
|
|
9
|
+
this.name = 'HiveSearchAPIError';
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/index.ts
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./client"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./errors"), exports);
|
package/src/index.ts
ADDED
package/src/types.js
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface HiveSearchMessage {
|
|
2
|
+
role: 'user' | 'assistant';
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface HiveSearchRequest {
|
|
7
|
+
prompt?: string;
|
|
8
|
+
messages?: HiveSearchMessage[];
|
|
9
|
+
temperature?: number;
|
|
10
|
+
top_k?: number;
|
|
11
|
+
top_p?: number;
|
|
12
|
+
include_data_sources?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface HiveSearchResponse {
|
|
16
|
+
response: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
isAdditionalDataRequired: [] | null;
|
|
20
|
+
data_sources?: string[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const client_1 = require("../src/client");
|
|
13
|
+
const dotenv_1 = require("dotenv");
|
|
14
|
+
(0, dotenv_1.config)();
|
|
15
|
+
jest.setTimeout(50000);
|
|
16
|
+
describe('HiveSearchAPIWrapper', () => {
|
|
17
|
+
it('should call the API and return a result', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
const client = new client_1.HiveSearchClient((_a = process.env.HIVE_API_KEY) !== null && _a !== void 0 ? _a : "");
|
|
20
|
+
const result = yield client.search({
|
|
21
|
+
prompt: 'price of ETH',
|
|
22
|
+
temperature: 0.7,
|
|
23
|
+
include_data_sources: true,
|
|
24
|
+
});
|
|
25
|
+
expect(result).toHaveProperty('response');
|
|
26
|
+
expect(result).toHaveProperty('data_sources');
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import { HiveSearchClient } from '../src/client';
|
|
3
|
+
import { config } from 'dotenv';
|
|
4
|
+
config();
|
|
5
|
+
jest.setTimeout(50000);
|
|
6
|
+
describe('HiveSearchAPIWrapper', () => {
|
|
7
|
+
it('should call the API and return a result', async () => {
|
|
8
|
+
const client = new HiveSearchClient(process.env.HIVE_API_KEY ?? "");
|
|
9
|
+
const result = await client.search({
|
|
10
|
+
prompt: 'price of ETH',
|
|
11
|
+
temperature: 0.7,
|
|
12
|
+
include_data_sources: true,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(result).toHaveProperty('response');
|
|
16
|
+
expect(result).toHaveProperty('data_sources');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const client_1 = require("../src/client"); // Import the HiveSearchClient
|
|
13
|
+
const errors_1 = require("../src/errors");
|
|
14
|
+
const dotenv_1 = require("dotenv");
|
|
15
|
+
(0, dotenv_1.config)();
|
|
16
|
+
jest.setTimeout(100000);
|
|
17
|
+
describe('HiveSearchClient', () => {
|
|
18
|
+
const apiKey = process.env.HIVE_API_KEY; // Make sure to set your API key in the environment variables
|
|
19
|
+
if (!apiKey) {
|
|
20
|
+
throw new Error('HIVE_API_KEY environment variable not set');
|
|
21
|
+
}
|
|
22
|
+
const client = new client_1.HiveSearchClient(apiKey);
|
|
23
|
+
// Define your search inputs (similar to the Python test cases)
|
|
24
|
+
const searchInputs = [
|
|
25
|
+
{ prompt: "What is current price of Eth?" },
|
|
26
|
+
{ prompt: "Token info of SAI", temperature: 0.3 },
|
|
27
|
+
{ prompt: "BTC token info", top_k: 5 },
|
|
28
|
+
{ prompt: "top 5 crypto gainer coins", top_p: 0.9 },
|
|
29
|
+
{ prompt: "BTC price", include_data_sources: true },
|
|
30
|
+
{
|
|
31
|
+
// Ensure the role values are 'user' and 'assistant'
|
|
32
|
+
messages: [
|
|
33
|
+
{ role: "user", content: "What is current price of Eth?" },
|
|
34
|
+
{ role: "assistant", content: "Who are you" },
|
|
35
|
+
], // Explicitly type this as HiveSearchMessage[]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
prompt: "top 5 crypto loser coins",
|
|
39
|
+
temperature: 0.6,
|
|
40
|
+
top_k: 10,
|
|
41
|
+
top_p: 0.95,
|
|
42
|
+
include_data_sources: false,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
// Parametrize test inputs and run through each
|
|
46
|
+
searchInputs.forEach((searchInput, index) => {
|
|
47
|
+
it(`should return a valid response for test case ${index + 1}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
try {
|
|
49
|
+
const response = yield client.search(searchInput);
|
|
50
|
+
// Check that the response is in the correct format
|
|
51
|
+
expect(response.response).toBeInstanceOf(Object);
|
|
52
|
+
expect(response).toHaveProperty('isAdditionalDataRequired');
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof errors_1.HiveSearchAPIError) {
|
|
56
|
+
// If it's an error, assert the error properties
|
|
57
|
+
expect(error.status).toBeDefined();
|
|
58
|
+
expect(error.statusText).toBeDefined();
|
|
59
|
+
expect(error.body).toBeDefined();
|
|
60
|
+
expect(error.message).toBeDefined();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// For other errors, fail the test
|
|
64
|
+
fail('Unexpected error occurred: ' + error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { HiveSearchClient } from '../src/client'; // Import the HiveSearchClient
|
|
2
|
+
import { HiveSearchRequest, HiveSearchMessage } from '../src/types'; // Import the necessary types
|
|
3
|
+
import { HiveSearchAPIError } from '../src/errors';
|
|
4
|
+
import { config } from 'dotenv';
|
|
5
|
+
config();
|
|
6
|
+
jest.setTimeout(100000);
|
|
7
|
+
|
|
8
|
+
describe('HiveSearchClient', () => {
|
|
9
|
+
const apiKey = process.env.HIVE_API_KEY; // Make sure to set your API key in the environment variables
|
|
10
|
+
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw new Error('HIVE_API_KEY environment variable not set');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const client = new HiveSearchClient(apiKey);
|
|
16
|
+
|
|
17
|
+
// Define your search inputs (similar to the Python test cases)
|
|
18
|
+
const searchInputs: Array<HiveSearchRequest> = [
|
|
19
|
+
{ prompt: "What is current price of Eth?" },
|
|
20
|
+
{ prompt: "Token info of SAI", temperature: 0.3 },
|
|
21
|
+
{ prompt: "BTC token info", top_k: 5 },
|
|
22
|
+
{ prompt: "top 5 crypto gainer coins", top_p: 0.9 },
|
|
23
|
+
{ prompt: "BTC price", include_data_sources: true },
|
|
24
|
+
{
|
|
25
|
+
// Ensure the role values are 'user' and 'assistant'
|
|
26
|
+
messages: [
|
|
27
|
+
{ role: "user", content: "What is current price of Eth?" },
|
|
28
|
+
{ role: "assistant", content: "Who are you" },
|
|
29
|
+
] as HiveSearchMessage[], // Explicitly type this as HiveSearchMessage[]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
prompt: "top 5 crypto loser coins",
|
|
33
|
+
temperature: 0.6,
|
|
34
|
+
top_k: 10,
|
|
35
|
+
top_p: 0.95,
|
|
36
|
+
include_data_sources: false,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// Parametrize test inputs and run through each
|
|
41
|
+
searchInputs.forEach((searchInput, index) => {
|
|
42
|
+
it(`should return a valid response for test case ${index + 1}`, async () => {
|
|
43
|
+
try {
|
|
44
|
+
const response = await client.search(searchInput);
|
|
45
|
+
|
|
46
|
+
// Check that the response is in the correct format
|
|
47
|
+
expect(response.response).toBeInstanceOf(Object);
|
|
48
|
+
expect(response).toHaveProperty('isAdditionalDataRequired');
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof HiveSearchAPIError) {
|
|
51
|
+
// If it's an error, assert the error properties
|
|
52
|
+
expect(error.status).toBeDefined();
|
|
53
|
+
expect(error.statusText).toBeDefined();
|
|
54
|
+
expect(error.body).toBeDefined();
|
|
55
|
+
expect(error.message).toBeDefined();
|
|
56
|
+
} else {
|
|
57
|
+
// For other errors, fail the test
|
|
58
|
+
fail('Unexpected error occurred: ' + error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./dist",
|
|
4
|
+
"rootDir": "./src",
|
|
5
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
6
|
+
|
|
7
|
+
/* Projects */
|
|
8
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
9
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
10
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
11
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
12
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
13
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
14
|
+
|
|
15
|
+
/* Language and Environment */
|
|
16
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
17
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
18
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
19
|
+
// "libReplacement": true, /* Enable lib replacement. */
|
|
20
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
21
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
22
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
23
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
24
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
25
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
26
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
27
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
28
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
29
|
+
|
|
30
|
+
/* Modules */
|
|
31
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
32
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
33
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
34
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
35
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
36
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
37
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
38
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
39
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
40
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
41
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
42
|
+
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
|
43
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
44
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
45
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
46
|
+
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
47
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
48
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
49
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
50
|
+
|
|
51
|
+
/* JavaScript Support */
|
|
52
|
+
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
53
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
54
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
55
|
+
|
|
56
|
+
/* Emit */
|
|
57
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
58
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
59
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
60
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
61
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
62
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
63
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
64
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
65
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
66
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
67
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
68
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
69
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
70
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
71
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
72
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
73
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
74
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
75
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
76
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
77
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
78
|
+
|
|
79
|
+
/* Interop Constraints */
|
|
80
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
81
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
82
|
+
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
83
|
+
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
|
84
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
85
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
86
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
87
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
88
|
+
|
|
89
|
+
/* Type Checking */
|
|
90
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
91
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
92
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
93
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
94
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
95
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
96
|
+
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
97
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
98
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
99
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
100
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
101
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
102
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
103
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
104
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
105
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
106
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
107
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
108
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
109
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
110
|
+
|
|
111
|
+
/* Completeness */
|
|
112
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
113
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
114
|
+
},
|
|
115
|
+
"include": ["src/**/*"], /* Include all files in the src folder */
|
|
116
|
+
"exclude": ["node_modules", "dist"] /* Exclude node_modules and dist from compilation */
|
|
117
|
+
}
|