medpromptjs 0.4.4 → 0.5.1
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 +40 -0
- package/dist/agent.d.ts +6 -21
- package/dist/chain.d.ts +5 -2
- package/dist/embedding.d.ts +53 -0
- package/dist/index.d.ts +4 -0
- package/dist/llm.d.ts +91 -0
- package/dist/medpromptjs.cjs.development.js +633 -773
- package/dist/medpromptjs.cjs.development.js.map +1 -1
- package/dist/medpromptjs.cjs.production.min.js +1 -1
- package/dist/medpromptjs.cjs.production.min.js.map +1 -1
- package/dist/medpromptjs.esm.js +634 -776
- package/dist/medpromptjs.esm.js.map +1 -1
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -14,6 +14,46 @@ A set of base classes for making GenAI application development easy. Implements
|
|
|
14
14
|
npm i --save medpromptjs
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### BaseLLM
|
|
20
|
+
|
|
21
|
+
`BaseLLM` is a base class for LLMs that communicate with a remote API. It extends the LangChain `LLM` class and provides configurable parameters for model inference.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { BaseLLM } from 'medpromptjs';
|
|
25
|
+
|
|
26
|
+
const llm = new BaseLLM({
|
|
27
|
+
baseUrl: 'http://localhost:8080/api/chat',
|
|
28
|
+
model: 'llama2',
|
|
29
|
+
apiKey: 'your-api-key', // optional
|
|
30
|
+
temperature: 0.1,
|
|
31
|
+
maxOutputTokens: 512,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const response = await llm.invoke('Hello, how are you?');
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### BaseEmbedding
|
|
38
|
+
|
|
39
|
+
`BaseEmbedding` is a base class for embeddings that communicate with a remote API. It extends the LangChain `Embeddings` class.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { BaseEmbedding } from 'medpromptjs';
|
|
43
|
+
|
|
44
|
+
const embedding = new BaseEmbedding({
|
|
45
|
+
baseUrl: 'http://localhost:8080/api/embeddings',
|
|
46
|
+
model: 'nomic-embed-text',
|
|
47
|
+
apiKey: 'your-api-key', // optional
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Embed multiple documents
|
|
51
|
+
const embeddings = await embedding.embedDocuments(['doc1', 'doc2']);
|
|
52
|
+
|
|
53
|
+
// Embed a single query
|
|
54
|
+
const queryEmbedding = await embedding.embedQuery('search query');
|
|
55
|
+
```
|
|
56
|
+
|
|
17
57
|
## Give us a star ⭐️
|
|
18
58
|
If you find this project useful, give us a star. It helps others discover the project.
|
|
19
59
|
|
package/dist/agent.d.ts
CHANGED
|
@@ -13,30 +13,15 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { BaseChain } from './chain';
|
|
17
17
|
import type { ToolInterface } from '@langchain/core/tools';
|
|
18
|
-
export declare class BaseAgent {
|
|
19
|
-
container: any;
|
|
20
|
-
private _name;
|
|
21
|
-
private _description;
|
|
22
|
-
private _template;
|
|
18
|
+
export declare class BaseAgent extends BaseChain {
|
|
23
19
|
private _tools;
|
|
24
|
-
prompt: any;
|
|
25
|
-
llm: LLM;
|
|
26
|
-
chat_model: boolean;
|
|
27
|
-
runnable: any;
|
|
28
|
-
constructor(container: any);
|
|
29
|
-
get name(): string;
|
|
30
|
-
set name(value: string);
|
|
31
|
-
get description(): string;
|
|
32
|
-
set description(value: string);
|
|
33
|
-
get template(): string;
|
|
34
|
-
set template(value: string);
|
|
35
20
|
get tools(): ToolInterface[];
|
|
36
21
|
set tools(value: ToolInterface[]);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Run the agent using the provided input.
|
|
24
|
+
* This uses createStructuredChatAgent and AgentExecutor from langchain/agents.
|
|
25
|
+
*/
|
|
41
26
|
run(input: any): Promise<import("@langchain/core/utils/types").ChainValues>;
|
|
42
27
|
}
|
package/dist/chain.d.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { LLM } from '@langchain/core/language_models/llms';
|
|
17
|
+
import { FakeListChatModel } from '@langchain/core/utils/testing';
|
|
17
18
|
export declare class BaseChain {
|
|
18
19
|
container: any;
|
|
19
20
|
private _name;
|
|
@@ -23,16 +24,18 @@ export declare class BaseChain {
|
|
|
23
24
|
llm: LLM;
|
|
24
25
|
chat_model: boolean;
|
|
25
26
|
runnable: any;
|
|
27
|
+
fakeLLM: FakeListChatModel;
|
|
26
28
|
constructor(container: any);
|
|
29
|
+
initializePrompt(): void;
|
|
27
30
|
get name(): string;
|
|
28
31
|
set name(value: string);
|
|
29
32
|
get description(): string;
|
|
30
33
|
set description(value: string);
|
|
31
34
|
get template(): string;
|
|
32
35
|
set template(value: string);
|
|
33
|
-
|
|
34
|
-
resolve(name: string): any;
|
|
36
|
+
resolve(name: string, defaultValue?: any): any;
|
|
35
37
|
camelize(str: string): string;
|
|
36
38
|
snake_case(str: string): string;
|
|
37
39
|
chain(input: any): Promise<any>;
|
|
40
|
+
invoke(input: any): Promise<any>;
|
|
38
41
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 Bell Eapen
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Embeddings, type EmbeddingsParams } from '@langchain/core/embeddings';
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for configuring BaseEmbedding
|
|
19
|
+
*/
|
|
20
|
+
export interface BaseEmbeddingInput extends EmbeddingsParams {
|
|
21
|
+
baseUrl: string;
|
|
22
|
+
model: string;
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* BaseEmbedding is a base class for embeddings that communicate with a remote API.
|
|
27
|
+
* It extends the LangChain Embeddings class and provides methods for embedding
|
|
28
|
+
* documents and queries.
|
|
29
|
+
*/
|
|
30
|
+
export declare class BaseEmbedding extends Embeddings {
|
|
31
|
+
baseUrl: string;
|
|
32
|
+
model: string;
|
|
33
|
+
apiKey: string;
|
|
34
|
+
constructor(fields: BaseEmbeddingInput);
|
|
35
|
+
/**
|
|
36
|
+
* Embed a list of documents
|
|
37
|
+
* @param texts - Array of strings to embed
|
|
38
|
+
* @returns Promise of array of embedding vectors
|
|
39
|
+
*/
|
|
40
|
+
embedDocuments(texts: string[]): Promise<number[][]>;
|
|
41
|
+
/**
|
|
42
|
+
* Embed a single query
|
|
43
|
+
* @param text - String to embed
|
|
44
|
+
* @returns Promise of embedding vector
|
|
45
|
+
*/
|
|
46
|
+
embedQuery(text: string): Promise<number[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Helper method to get embeddings for a list of texts
|
|
49
|
+
* @param texts - Array of strings to embed
|
|
50
|
+
* @returns Promise of array of embedding vectors
|
|
51
|
+
*/
|
|
52
|
+
protected getEmbeddings(texts: string[]): Promise<number[][]>;
|
|
53
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,7 @@ export { BaseChain } from './chain';
|
|
|
2
2
|
export { BaseAgent } from './agent';
|
|
3
3
|
export { BaseTool } from './tool';
|
|
4
4
|
export { LLMLoop } from './llm_loop';
|
|
5
|
+
export { BaseLLM } from './llm';
|
|
6
|
+
export type { BaseLLMInput, ModelParams } from './llm';
|
|
7
|
+
export { BaseEmbedding } from './embedding';
|
|
8
|
+
export type { BaseEmbeddingInput } from './embedding';
|
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2024 Bell Eapen
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { LLM, type BaseLLMParams } from '@langchain/core/language_models/llms';
|
|
17
|
+
import type { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
18
|
+
/**
|
|
19
|
+
* Model parameters for BaseLLM
|
|
20
|
+
*/
|
|
21
|
+
export interface ModelParams {
|
|
22
|
+
maxOutputTokens?: number;
|
|
23
|
+
nPredict?: number;
|
|
24
|
+
topK?: number;
|
|
25
|
+
topP?: number;
|
|
26
|
+
temperature?: number;
|
|
27
|
+
nBatch?: number;
|
|
28
|
+
repeatPenalty?: number;
|
|
29
|
+
repeatLastN?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parameters for configuring BaseLLM
|
|
33
|
+
*/
|
|
34
|
+
export interface BaseLLMInput extends BaseLLMParams {
|
|
35
|
+
baseUrl: string;
|
|
36
|
+
model: string;
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
timeout?: number;
|
|
39
|
+
backend?: string;
|
|
40
|
+
temperature?: number;
|
|
41
|
+
topP?: number;
|
|
42
|
+
topK?: number;
|
|
43
|
+
nBatch?: number;
|
|
44
|
+
nThreads?: number;
|
|
45
|
+
nPredict?: number;
|
|
46
|
+
maxOutputTokens?: number;
|
|
47
|
+
repeatLastN?: number;
|
|
48
|
+
repeatPenalty?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* BaseLLM is a base class for LLMs that communicate with a remote API.
|
|
52
|
+
* It extends the LangChain LLM class and provides configurable parameters
|
|
53
|
+
* for model inference.
|
|
54
|
+
*/
|
|
55
|
+
export declare class BaseLLM extends LLM {
|
|
56
|
+
baseUrl: string;
|
|
57
|
+
model: string;
|
|
58
|
+
apiKey: string;
|
|
59
|
+
timeout: number;
|
|
60
|
+
backend: string;
|
|
61
|
+
temperature: number;
|
|
62
|
+
topP: number;
|
|
63
|
+
topK: number;
|
|
64
|
+
nBatch: number;
|
|
65
|
+
nThreads: number;
|
|
66
|
+
nPredict: number;
|
|
67
|
+
maxOutputTokens: number;
|
|
68
|
+
repeatLastN: number;
|
|
69
|
+
repeatPenalty: number;
|
|
70
|
+
constructor(fields: BaseLLMInput);
|
|
71
|
+
/**
|
|
72
|
+
* Get the model default parameters
|
|
73
|
+
*/
|
|
74
|
+
get modelDefaultParameters(): ModelParams;
|
|
75
|
+
/**
|
|
76
|
+
* Get the identifying parameters
|
|
77
|
+
*/
|
|
78
|
+
get identifyingParams(): Record<string, unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Get the LLM type identifier
|
|
81
|
+
*/
|
|
82
|
+
_llmType(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Prepare the request payload for the API
|
|
85
|
+
*/
|
|
86
|
+
protected preparePayload(prompt: string): Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* Make the API call to generate text
|
|
89
|
+
*/
|
|
90
|
+
_call(prompt: string, _options: this['ParsedCallOptions'], _runManager?: CallbackManagerForLLMRun): Promise<string>;
|
|
91
|
+
}
|