macrocosmos 1.2.12 → 1.2.14
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 +19 -1
- package/dist/README.md +19 -1
- package/dist/__tests__/apex/client-chat.test.js +20 -45
- package/dist/__tests__/apex/client-deep-researcher.test.d.ts +1 -0
- package/dist/__tests__/apex/client-deep-researcher.test.js +83 -0
- package/dist/lib/apex/Client.d.ts +25 -5
- package/dist/lib/apex/Client.js +59 -31
- package/dist/lib/apex/DeepResearch.d.ts +28 -0
- package/dist/lib/apex/DeepResearch.js +41 -0
- package/dist/lib/apex/Stream.d.ts +3 -0
- package/dist/lib/apex/index.d.ts +1 -0
- package/dist/lib/apex/index.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ npm install macrocosmos
|
|
|
15
15
|
The Apex client provides an interface for accessing the Apex API for chat completions and web search.
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import { ApexClient } from 'macrocosmos';
|
|
18
|
+
import { ApexClient, DeepResearch } from 'macrocosmos';
|
|
19
19
|
|
|
20
20
|
// Initialize the client
|
|
21
21
|
const client = new ApexClient({ apiKey: 'your-api-key' });
|
|
@@ -33,6 +33,24 @@ const response = await client.chat.completions.create({
|
|
|
33
33
|
const webResults = await client.webRetrieval({
|
|
34
34
|
query: 'latest news about AI'
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
// Deep Researcher
|
|
38
|
+
|
|
39
|
+
// Create DeepResearch instance
|
|
40
|
+
const deepResearch = new DeepResearch(client);
|
|
41
|
+
|
|
42
|
+
// Submit a deep research job
|
|
43
|
+
const submittedResponse = await deepResearch.createJob({
|
|
44
|
+
messages: [
|
|
45
|
+
{ role: "user",
|
|
46
|
+
content: `Can you propose a mechanism by which a decentralized network
|
|
47
|
+
of AI agents could achieve provable alignment on abstract ethical principles
|
|
48
|
+
without relying on human-defined ontologies or centralized arbitration?`},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Get the results of a deep research job
|
|
53
|
+
const polledResponse = await deepResearch.getJobResults(submittedResponse.jobId);
|
|
36
54
|
```
|
|
37
55
|
|
|
38
56
|
### Gravity Client
|
package/dist/README.md
CHANGED
|
@@ -15,7 +15,7 @@ npm install macrocosmos
|
|
|
15
15
|
The Apex client provides an interface for accessing the Apex API for chat completions and web search.
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
|
-
import { ApexClient } from 'macrocosmos';
|
|
18
|
+
import { ApexClient, DeepResearch } from 'macrocosmos';
|
|
19
19
|
|
|
20
20
|
// Initialize the client
|
|
21
21
|
const client = new ApexClient({ apiKey: 'your-api-key' });
|
|
@@ -33,6 +33,24 @@ const response = await client.chat.completions.create({
|
|
|
33
33
|
const webResults = await client.webRetrieval({
|
|
34
34
|
query: 'latest news about AI'
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
// Deep Researcher
|
|
38
|
+
|
|
39
|
+
// Create DeepResearch instance
|
|
40
|
+
const deepResearch = new DeepResearch(client);
|
|
41
|
+
|
|
42
|
+
// Submit a deep research job
|
|
43
|
+
const submittedResponse = await deepResearch.createJob({
|
|
44
|
+
messages: [
|
|
45
|
+
{ role: "user",
|
|
46
|
+
content: `Can you propose a mechanism by which a decentralized network
|
|
47
|
+
of AI agents could achieve provable alignment on abstract ethical principles
|
|
48
|
+
without relying on human-defined ontologies or centralized arbitration?`},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Get the results of a deep research job
|
|
53
|
+
const polledResponse = await deepResearch.getJobResults(submittedResponse.jobId);
|
|
36
54
|
```
|
|
37
55
|
|
|
38
56
|
### Gravity Client
|
|
@@ -6,34 +6,32 @@ describe("ApexClient", () => {
|
|
|
6
6
|
if (!API_KEY) {
|
|
7
7
|
throw new Error("MACROCOSMOS_API_KEY environment variable is required");
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const messages = [
|
|
10
|
+
{
|
|
11
|
+
role: "user",
|
|
12
|
+
content: "What is the capital of France?",
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
const samplingParameters = {
|
|
16
|
+
temperature: 0.7,
|
|
17
|
+
topP: 0.9,
|
|
18
|
+
maxNewTokens: 100,
|
|
19
|
+
doSample: true,
|
|
20
|
+
};
|
|
21
|
+
let client;
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
client = new macrocosmos_1.ApexClient({
|
|
12
24
|
apiKey: API_KEY,
|
|
13
25
|
appName: "apex-client.test.ts",
|
|
14
26
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
role: "user",
|
|
19
|
-
content: "What is the capital of France?",
|
|
20
|
-
},
|
|
21
|
-
];
|
|
27
|
+
});
|
|
28
|
+
it("should make a streaming chat completion call", async () => {
|
|
22
29
|
// Create streaming completion
|
|
23
30
|
const result = await client.chat.completions.create({
|
|
24
31
|
messages,
|
|
25
32
|
stream: true,
|
|
26
|
-
samplingParameters
|
|
27
|
-
temperature: 0.7,
|
|
28
|
-
topP: 0.9,
|
|
29
|
-
maxNewTokens: 100,
|
|
30
|
-
doSample: true,
|
|
31
|
-
},
|
|
33
|
+
samplingParameters,
|
|
32
34
|
});
|
|
33
|
-
// Check if it's a Stream
|
|
34
|
-
if (!(result instanceof macrocosmos_1.ApexStream)) {
|
|
35
|
-
throw new Error("Expected a Stream but got a regular response");
|
|
36
|
-
}
|
|
37
35
|
// Handle streaming response
|
|
38
36
|
let fullResponse = "";
|
|
39
37
|
const stream = result;
|
|
@@ -48,35 +46,12 @@ describe("ApexClient", () => {
|
|
|
48
46
|
expect(fullResponse.toLowerCase()).toContain("paris");
|
|
49
47
|
}, 30000); // Increase timeout to 30 seconds for streaming
|
|
50
48
|
it("should make a non-streaming chat completion call", async () => {
|
|
51
|
-
// Create ApexClient
|
|
52
|
-
const client = new macrocosmos_1.ApexClient({
|
|
53
|
-
apiKey: API_KEY,
|
|
54
|
-
appName: "apex-client.test.ts",
|
|
55
|
-
});
|
|
56
|
-
// Create request with the proper message type
|
|
57
|
-
const messages = [
|
|
58
|
-
{
|
|
59
|
-
role: "user",
|
|
60
|
-
content: "What is the capital of France?",
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
49
|
// Create non-streaming completion
|
|
64
|
-
const
|
|
50
|
+
const response = await client.chat.completions.create({
|
|
65
51
|
messages,
|
|
66
52
|
stream: false,
|
|
67
|
-
samplingParameters
|
|
68
|
-
temperature: 0.7,
|
|
69
|
-
topP: 0.9,
|
|
70
|
-
maxNewTokens: 100,
|
|
71
|
-
doSample: true,
|
|
72
|
-
},
|
|
53
|
+
samplingParameters,
|
|
73
54
|
});
|
|
74
|
-
// Check if it's a regular response
|
|
75
|
-
if (result instanceof macrocosmos_1.ApexStream) {
|
|
76
|
-
throw new Error("Expected a regular response but got a Stream");
|
|
77
|
-
}
|
|
78
|
-
// Cast to the correct type
|
|
79
|
-
const response = result;
|
|
80
55
|
console.log("Response:", response.choices?.[0]?.message?.content);
|
|
81
56
|
expect(response.choices?.[0]?.message?.content).toBeTruthy();
|
|
82
57
|
expect(response.choices?.[0]?.message?.content?.toLowerCase()).toContain("paris");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Client_1 = require("../../lib/apex/Client");
|
|
4
|
+
const DeepResearch_1 = require("../../lib/apex/DeepResearch");
|
|
5
|
+
describe("DeepResearch", () => {
|
|
6
|
+
const API_KEY = process.env.MACROCOSMOS_API_KEY;
|
|
7
|
+
if (!API_KEY) {
|
|
8
|
+
throw new Error("MACROCOSMOS_API_KEY environment variable is required");
|
|
9
|
+
}
|
|
10
|
+
it("should create a deep research job", async () => {
|
|
11
|
+
// Create ApexClient
|
|
12
|
+
const client = new Client_1.ApexClient({
|
|
13
|
+
apiKey: API_KEY,
|
|
14
|
+
appName: "apex-client.test.ts",
|
|
15
|
+
});
|
|
16
|
+
// Create DeepResearch instance
|
|
17
|
+
const deepResearch = new DeepResearch_1.DeepResearch(client);
|
|
18
|
+
// Create test parameters, enter all DeepResearchJobParams fields for coverage
|
|
19
|
+
const params = {
|
|
20
|
+
messages: [
|
|
21
|
+
{
|
|
22
|
+
role: "user",
|
|
23
|
+
content: `Can you propose a mechanism by which a decentralized network
|
|
24
|
+
of AI agents could achieve provable alignment on abstract ethical principles
|
|
25
|
+
without relying on human-defined ontologies or centralized arbitration?`,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
model: "Default",
|
|
29
|
+
samplingParameters: {
|
|
30
|
+
temperature: 0.7,
|
|
31
|
+
topP: 0.95,
|
|
32
|
+
maxNewTokens: 100,
|
|
33
|
+
doSample: false,
|
|
34
|
+
},
|
|
35
|
+
seed: 42,
|
|
36
|
+
uids: [1, 2, 3],
|
|
37
|
+
};
|
|
38
|
+
// Submit the job
|
|
39
|
+
const response = await deepResearch.createJob(params);
|
|
40
|
+
// Verify response structure
|
|
41
|
+
expect(response).toBeDefined();
|
|
42
|
+
expect(typeof response.jobId).toBe("string");
|
|
43
|
+
expect(typeof response.status).toBe("string");
|
|
44
|
+
expect(typeof response.createdAt).toBe("string");
|
|
45
|
+
expect(typeof response.updatedAt).toBe("string");
|
|
46
|
+
// Log response for debugging
|
|
47
|
+
console.log("Create Job Response:", response);
|
|
48
|
+
}, 30000);
|
|
49
|
+
it("should get deep researcher job results", async () => {
|
|
50
|
+
// Create ApexClient
|
|
51
|
+
const client = new Client_1.ApexClient({
|
|
52
|
+
apiKey: API_KEY,
|
|
53
|
+
appName: "apex-client.test.ts",
|
|
54
|
+
});
|
|
55
|
+
// Create DeepResearch instance
|
|
56
|
+
const deepResearch = new DeepResearch_1.DeepResearch(client);
|
|
57
|
+
// First create a job. Use simple inputs as job creation is tested in the previous test.
|
|
58
|
+
const createParams = {
|
|
59
|
+
messages: [
|
|
60
|
+
{
|
|
61
|
+
role: "user",
|
|
62
|
+
content: `Can you propose a mechanism by which a decentralized network
|
|
63
|
+
of AI agents could achieve provable alignment on abstract ethical principles
|
|
64
|
+
without relying on human-defined ontologies or centralized arbitration?`,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
const createResponse = await deepResearch.createJob(createParams);
|
|
69
|
+
const jobId = createResponse.jobId;
|
|
70
|
+
// Then get the results
|
|
71
|
+
const response = await deepResearch.getJobResults(jobId);
|
|
72
|
+
// Verify response structure
|
|
73
|
+
expect(response).toBeDefined();
|
|
74
|
+
expect(response.jobId).toBe(jobId); // Job ID should match the one from the create response
|
|
75
|
+
expect(typeof response.status).toBe("string");
|
|
76
|
+
expect(typeof response.jobId).toBe("string");
|
|
77
|
+
expect(typeof response.createdAt).toBe("string");
|
|
78
|
+
expect(typeof response.updatedAt).toBe("string");
|
|
79
|
+
expect(Array.isArray(response.result)).toBe(true);
|
|
80
|
+
// Log response for debugging
|
|
81
|
+
console.log("Get Job Results Response:", response);
|
|
82
|
+
}, 60000); // Longer timeout for this test as it involves multiple API calls
|
|
83
|
+
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage } from "../../generated/apex/v1/apex";
|
|
1
|
+
import { ApexServiceClient, ChatCompletionRequest as GeneratedChatCompletionRequest, ChatCompletionResponse, ChatCompletionChunkResponse, WebRetrievalRequest as GeneratedWebRetrievalRequest, WebRetrievalResponse, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse } from "../../generated/apex/v1/apex";
|
|
2
2
|
import * as grpc from "@grpc/grpc-js";
|
|
3
3
|
import { BaseClient, BaseClientOptions } from "../BaseClient";
|
|
4
4
|
import { ApexStream } from "./Stream";
|
|
5
5
|
import { MarkFieldsOptional } from "../util.types";
|
|
6
6
|
type ChatCompletionRequest = MarkFieldsOptional<GeneratedChatCompletionRequest, "uids">;
|
|
7
7
|
type WebRetrievalRequest = MarkFieldsOptional<GeneratedWebRetrievalRequest, "uids">;
|
|
8
|
-
export { ApexStream, WebRetrievalRequest, WebRetrievalResponse, ChatCompletionRequest, ChatMessage, };
|
|
8
|
+
export { ApexStream, WebRetrievalRequest, WebRetrievalResponse, ChatCompletionRequest, ChatMessage, SubmitDeepResearcherJobResponse, GetDeepResearcherJobRequest, GetDeepResearcherJobResponse, };
|
|
9
9
|
interface ApexClientOptions extends BaseClientOptions {
|
|
10
10
|
timeout?: number;
|
|
11
11
|
}
|
|
@@ -16,6 +16,18 @@ export interface ApexProtoClient {
|
|
|
16
16
|
new (address: string, credentials: grpc.ChannelCredentials): ApexService;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
export interface ChatCompletionsCreate {
|
|
20
|
+
(params: ChatCompletionRequest & {
|
|
21
|
+
stream: true;
|
|
22
|
+
},
|
|
23
|
+
/** options are not used, but are accepted for compatibility with the OpenAI API */
|
|
24
|
+
_options?: unknown): Promise<ApexStream<ChatCompletionChunkResponse>>;
|
|
25
|
+
(params: ChatCompletionRequest & {
|
|
26
|
+
stream?: false | undefined;
|
|
27
|
+
},
|
|
28
|
+
/** options are not used, but are accepted for compatibility with the OpenAI API */
|
|
29
|
+
_options?: unknown): Promise<ChatCompletionResponse>;
|
|
30
|
+
}
|
|
19
31
|
/**
|
|
20
32
|
* Client for interacting with the Apex API
|
|
21
33
|
* Provides OpenAI-compatible interface over gRPC
|
|
@@ -24,21 +36,29 @@ export declare class ApexClient extends BaseClient {
|
|
|
24
36
|
private _grpcClient?;
|
|
25
37
|
private defaultTimeout;
|
|
26
38
|
constructor(options: ApexClientOptions, grpcClient?: ApexServiceClient);
|
|
27
|
-
|
|
39
|
+
protected createGrpcClient(): ApexServiceClient;
|
|
28
40
|
/**
|
|
29
41
|
* Get the default timeout for chat completions
|
|
30
42
|
*/
|
|
31
|
-
|
|
43
|
+
protected getDefaultTimeout(): number;
|
|
32
44
|
/**
|
|
33
45
|
* OpenAI-compatible chat completions API
|
|
34
46
|
*/
|
|
35
47
|
chat: {
|
|
36
48
|
completions: {
|
|
37
|
-
create:
|
|
49
|
+
create: ChatCompletionsCreate;
|
|
38
50
|
};
|
|
39
51
|
};
|
|
40
52
|
/**
|
|
41
53
|
* Web retrieval API for searching the internet
|
|
42
54
|
*/
|
|
43
55
|
webRetrieval: (params: WebRetrievalRequest) => Promise<WebRetrievalResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Submit a deep researcher job
|
|
58
|
+
*/
|
|
59
|
+
submitDeepResearcherJob: (params: ChatCompletionRequest) => Promise<SubmitDeepResearcherJobResponse>;
|
|
60
|
+
/**
|
|
61
|
+
* Get a deep researcher job
|
|
62
|
+
*/
|
|
63
|
+
getDeepResearcherJob: (params: GetDeepResearcherJobRequest) => Promise<GetDeepResearcherJobResponse>;
|
|
44
64
|
}
|
package/dist/lib/apex/Client.js
CHANGED
|
@@ -33,14 +33,41 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ApexClient = exports.ChatMessage = exports.WebRetrievalResponse = exports.ApexStream = void 0;
|
|
36
|
+
exports.ApexClient = exports.GetDeepResearcherJobResponse = exports.GetDeepResearcherJobRequest = exports.SubmitDeepResearcherJobResponse = exports.ChatMessage = exports.WebRetrievalResponse = exports.ApexStream = void 0;
|
|
37
37
|
const apex_1 = require("../../generated/apex/v1/apex");
|
|
38
38
|
Object.defineProperty(exports, "WebRetrievalResponse", { enumerable: true, get: function () { return apex_1.WebRetrievalResponse; } });
|
|
39
39
|
Object.defineProperty(exports, "ChatMessage", { enumerable: true, get: function () { return apex_1.ChatMessage; } });
|
|
40
|
+
Object.defineProperty(exports, "SubmitDeepResearcherJobResponse", { enumerable: true, get: function () { return apex_1.SubmitDeepResearcherJobResponse; } });
|
|
41
|
+
Object.defineProperty(exports, "GetDeepResearcherJobRequest", { enumerable: true, get: function () { return apex_1.GetDeepResearcherJobRequest; } });
|
|
42
|
+
Object.defineProperty(exports, "GetDeepResearcherJobResponse", { enumerable: true, get: function () { return apex_1.GetDeepResearcherJobResponse; } });
|
|
40
43
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
41
44
|
const BaseClient_1 = require("../BaseClient");
|
|
42
45
|
const Stream_1 = require("./Stream");
|
|
43
46
|
Object.defineProperty(exports, "ApexStream", { enumerable: true, get: function () { return Stream_1.ApexStream; } });
|
|
47
|
+
function chatCompletionsCreate(params, _options) {
|
|
48
|
+
const client = this.createGrpcClient();
|
|
49
|
+
const requestParams = {
|
|
50
|
+
...params,
|
|
51
|
+
uids: params.uids ?? [],
|
|
52
|
+
timeout: params.timeout || this.getDefaultTimeout(),
|
|
53
|
+
};
|
|
54
|
+
if (requestParams.stream) {
|
|
55
|
+
const stream = client.chatCompletionStream(requestParams);
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
return Promise.resolve(Stream_1.ApexStream.fromGrpcStream(stream, controller));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
client.chatCompletion(requestParams, (error, response) => {
|
|
62
|
+
if (error) {
|
|
63
|
+
reject(error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
resolve(response);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
44
71
|
/**
|
|
45
72
|
* Client for interacting with the Apex API
|
|
46
73
|
* Provides OpenAI-compatible interface over gRPC
|
|
@@ -53,36 +80,7 @@ class ApexClient extends BaseClient_1.BaseClient {
|
|
|
53
80
|
*/
|
|
54
81
|
this.chat = {
|
|
55
82
|
completions: {
|
|
56
|
-
create:
|
|
57
|
-
const client = this.createGrpcClient();
|
|
58
|
-
// Apply default timeout if not specified in params
|
|
59
|
-
const requestParams = {
|
|
60
|
-
...params,
|
|
61
|
-
uids: params.uids ?? [],
|
|
62
|
-
timeout: params.timeout || this.getDefaultTimeout(),
|
|
63
|
-
};
|
|
64
|
-
// Handle streaming vs non-streaming
|
|
65
|
-
if (requestParams.stream) {
|
|
66
|
-
// Create a streaming call
|
|
67
|
-
const stream = client.chatCompletionStream(requestParams);
|
|
68
|
-
// Create controller for abort capability
|
|
69
|
-
const controller = new AbortController();
|
|
70
|
-
// Return a Stream object that wraps the gRPC stream
|
|
71
|
-
return Stream_1.ApexStream.fromGrpcStream(stream, controller);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// For non-streaming, return a promise that resolves with the completion
|
|
75
|
-
return new Promise((resolve, reject) => {
|
|
76
|
-
client.chatCompletion(requestParams, (error, response) => {
|
|
77
|
-
if (error) {
|
|
78
|
-
reject(error);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
resolve(response);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
},
|
|
83
|
+
create: chatCompletionsCreate.bind(this),
|
|
86
84
|
},
|
|
87
85
|
};
|
|
88
86
|
/**
|
|
@@ -100,6 +98,36 @@ class ApexClient extends BaseClient_1.BaseClient {
|
|
|
100
98
|
});
|
|
101
99
|
});
|
|
102
100
|
};
|
|
101
|
+
/**
|
|
102
|
+
* Submit a deep researcher job
|
|
103
|
+
*/
|
|
104
|
+
this.submitDeepResearcherJob = async (params) => {
|
|
105
|
+
const client = this.createGrpcClient();
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
client.submitDeepResearcherJob({ ...params, uids: params.uids ?? [] }, (error, response) => {
|
|
108
|
+
if (error) {
|
|
109
|
+
reject(error);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
resolve(response);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Get a deep researcher job
|
|
118
|
+
*/
|
|
119
|
+
this.getDeepResearcherJob = async (params) => {
|
|
120
|
+
const client = this.createGrpcClient();
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
client.getDeepResearcherJob(params, (error, response) => {
|
|
123
|
+
if (error) {
|
|
124
|
+
reject(error);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
resolve(response);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
103
131
|
this.defaultTimeout = options.timeout || 60;
|
|
104
132
|
this._grpcClient = grpcClient;
|
|
105
133
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ApexClient } from "./Client";
|
|
2
|
+
import { ChatMessage, SamplingParameters, SubmitDeepResearcherJobResponse, GetDeepResearcherJobResponse } from "../../generated/apex/v1/apex";
|
|
3
|
+
/** interface for input parameters that can be defined by the user */
|
|
4
|
+
export interface DeepResearchJobParams {
|
|
5
|
+
/** The messages to generate completions for */
|
|
6
|
+
messages: ChatMessage[];
|
|
7
|
+
/** The miner UIDs that will be used to generate the completion */
|
|
8
|
+
uids?: number[];
|
|
9
|
+
/** The LLM name to use for the completion */
|
|
10
|
+
model?: string;
|
|
11
|
+
/** The seed to use for the completion */
|
|
12
|
+
seed?: number;
|
|
13
|
+
/** The sampling parameters to use for the completion */
|
|
14
|
+
samplingParameters?: SamplingParameters;
|
|
15
|
+
}
|
|
16
|
+
export declare class DeepResearch {
|
|
17
|
+
private client;
|
|
18
|
+
private readonly defaultSamplingParameters;
|
|
19
|
+
constructor(client: ApexClient);
|
|
20
|
+
/**
|
|
21
|
+
* Create a deep research job with proper defaults
|
|
22
|
+
*/
|
|
23
|
+
createJob(params: DeepResearchJobParams): Promise<SubmitDeepResearcherJobResponse>;
|
|
24
|
+
/**
|
|
25
|
+
* Get the status and results of a deep research job
|
|
26
|
+
*/
|
|
27
|
+
getJobResults(jobId: string): Promise<GetDeepResearcherJobResponse>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeepResearch = void 0;
|
|
4
|
+
class DeepResearch {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
// Default sampling parameters for deep research
|
|
7
|
+
this.defaultSamplingParameters = {
|
|
8
|
+
temperature: 0.7,
|
|
9
|
+
topP: 0.95,
|
|
10
|
+
maxNewTokens: 8192,
|
|
11
|
+
doSample: false,
|
|
12
|
+
};
|
|
13
|
+
this.client = client;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a deep research job with proper defaults
|
|
17
|
+
*/
|
|
18
|
+
async createJob(params) {
|
|
19
|
+
const request = {
|
|
20
|
+
// User configurable fields
|
|
21
|
+
messages: params.messages,
|
|
22
|
+
uids: params.uids ?? [], // Default to empty array if not provided
|
|
23
|
+
model: params.model,
|
|
24
|
+
seed: params.seed,
|
|
25
|
+
samplingParameters: params.samplingParameters ?? this.defaultSamplingParameters,
|
|
26
|
+
// Required internal fields for Deep Researcher
|
|
27
|
+
task: "InferenceTask",
|
|
28
|
+
mixture: false,
|
|
29
|
+
inferenceMode: "Chain-of-Thought",
|
|
30
|
+
stream: true,
|
|
31
|
+
};
|
|
32
|
+
return this.client.submitDeepResearcherJob(request);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the status and results of a deep research job
|
|
36
|
+
*/
|
|
37
|
+
async getJobResults(jobId) {
|
|
38
|
+
return this.client.getDeepResearcherJob({ jobId });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.DeepResearch = DeepResearch;
|
|
@@ -5,6 +5,9 @@ export type ReadableStreamInterface = ReadableStream<Uint8Array>;
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class ApexStream<Item> implements AsyncIterable<Item> {
|
|
7
7
|
private iterator;
|
|
8
|
+
/**
|
|
9
|
+
* The AbortController for this stream. Call `abort()` to cancel the stream.
|
|
10
|
+
*/
|
|
8
11
|
controller: AbortController;
|
|
9
12
|
constructor(iterator: () => AsyncIterator<Item>, controller: AbortController);
|
|
10
13
|
/**
|
package/dist/lib/apex/index.d.ts
CHANGED
package/dist/lib/apex/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Stream"), exports);
|
|
18
18
|
__exportStar(require("./Client"), exports);
|
|
19
|
+
__exportStar(require("./DeepResearch"), exports);
|
|
19
20
|
// Future exports from the apex package would go here
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.2.
|
|
1
|
+
export declare const VERSION = "1.2.14";
|
package/dist/version.js
CHANGED