@langchain/google-common 0.0.26 → 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/dist/auth.cjs +26 -5
- package/dist/auth.d.ts +3 -2
- package/dist/auth.js +26 -5
- package/dist/chat_models.cjs +11 -10
- package/dist/chat_models.d.ts +4 -4
- package/dist/chat_models.js +12 -11
- package/dist/connection.cjs +34 -7
- package/dist/connection.d.ts +14 -8
- package/dist/connection.js +32 -6
- package/dist/embeddings.cjs +4 -2
- package/dist/embeddings.js +4 -2
- package/dist/experimental/media.cjs +494 -0
- package/dist/experimental/media.d.ts +210 -0
- package/dist/experimental/media.js +478 -0
- package/dist/experimental/utils/media_core.cjs +524 -0
- package/dist/experimental/utils/media_core.d.ts +209 -0
- package/dist/experimental/utils/media_core.js +514 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/llms.cjs +10 -5
- package/dist/llms.d.ts +4 -1
- package/dist/llms.js +11 -6
- package/dist/types.d.ts +8 -1
- package/dist/utils/gemini.cjs +491 -491
- package/dist/utils/gemini.d.ts +15 -50
- package/dist/utils/gemini.js +489 -465
- package/experimental/media.cjs +1 -0
- package/experimental/media.d.cts +1 -0
- package/experimental/media.d.ts +1 -0
- package/experimental/media.js +1 -0
- package/experimental/utils/media_core.cjs +1 -0
- package/experimental/utils/media_core.d.cts +1 -0
- package/experimental/utils/media_core.d.ts +1 -0
- package/experimental/utils/media_core.js +1 -0
- package/package.json +39 -18
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { BaseStore } from "@langchain/core/stores";
|
|
2
|
+
import { Serializable } from "@langchain/core/load/serializable";
|
|
3
|
+
export type MediaBlobData = {
|
|
4
|
+
value: string;
|
|
5
|
+
type: string;
|
|
6
|
+
};
|
|
7
|
+
export interface MediaBlobParameters {
|
|
8
|
+
data?: MediaBlobData;
|
|
9
|
+
metadata?: Record<string, unknown>;
|
|
10
|
+
path?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Represents a chunk of data that can be identified by the path where the
|
|
14
|
+
* data is (or will be) located, along with optional metadata about the data.
|
|
15
|
+
*/
|
|
16
|
+
export declare class MediaBlob extends Serializable implements MediaBlobParameters {
|
|
17
|
+
lc_serializable: boolean;
|
|
18
|
+
lc_namespace: string[];
|
|
19
|
+
data: MediaBlobData;
|
|
20
|
+
metadata?: Record<string, any>;
|
|
21
|
+
path?: string;
|
|
22
|
+
constructor(params: MediaBlobParameters);
|
|
23
|
+
get size(): number;
|
|
24
|
+
get dataType(): string;
|
|
25
|
+
get encoding(): string;
|
|
26
|
+
get mimetype(): string;
|
|
27
|
+
get asBytes(): Uint8Array;
|
|
28
|
+
asString(): Promise<string>;
|
|
29
|
+
asBase64(): Promise<string>;
|
|
30
|
+
asDataUrl(): Promise<string>;
|
|
31
|
+
asUri(): Promise<string>;
|
|
32
|
+
encode(): Promise<{
|
|
33
|
+
encoded: string;
|
|
34
|
+
encoding: string;
|
|
35
|
+
}>;
|
|
36
|
+
static fromDataUrl(url: string): MediaBlob;
|
|
37
|
+
static fromBlob(blob: Blob, other?: Omit<MediaBlobParameters, "data">): Promise<MediaBlob>;
|
|
38
|
+
}
|
|
39
|
+
export type ActionIfInvalidAction = "ignore" | "prefixPath" | "prefixUuid1" | "prefixUuid4" | "prefixUuid6" | "prefixUuid7" | "removePath";
|
|
40
|
+
export interface BlobStoreStoreOptions {
|
|
41
|
+
/**
|
|
42
|
+
* If the path is missing or invalid in the blob, how should we create
|
|
43
|
+
* a new path?
|
|
44
|
+
* Subclasses may define their own methods, but the following are supported
|
|
45
|
+
* by default:
|
|
46
|
+
* - Undefined or an emtpy string: Reject the blob
|
|
47
|
+
* - "ignore": Attempt to store it anyway (but this may fail)
|
|
48
|
+
* - "prefixPath": Use the default prefix for the BlobStore and get the
|
|
49
|
+
* unique portion from the URL. The original path is stored in the metadata
|
|
50
|
+
* - "prefixUuid": Use the default prefix for the BlobStore and get the
|
|
51
|
+
* unique portion from a generated UUID. The original path is stored
|
|
52
|
+
* in the metadata
|
|
53
|
+
*/
|
|
54
|
+
actionIfInvalid?: ActionIfInvalidAction;
|
|
55
|
+
/**
|
|
56
|
+
* The expected prefix for URIs that are stored.
|
|
57
|
+
* This may be used to test if a MediaBlob is valid and used to create a new
|
|
58
|
+
* path if "prefixPath" or "prefixUuid" is set for actionIfInvalid.
|
|
59
|
+
*/
|
|
60
|
+
pathPrefix?: string;
|
|
61
|
+
}
|
|
62
|
+
export type ActionIfBlobMissingAction = "emptyBlob";
|
|
63
|
+
export interface BlobStoreFetchOptions {
|
|
64
|
+
/**
|
|
65
|
+
* If the blob is not found when fetching, what should we do?
|
|
66
|
+
* Subclasses may define their own methods, but the following are supported
|
|
67
|
+
* by default:
|
|
68
|
+
* - Undefined or an empty string: return undefined
|
|
69
|
+
* - "emptyBlob": return a new MediaBlob that has the path set, but nothing else.
|
|
70
|
+
*/
|
|
71
|
+
actionIfBlobMissing?: ActionIfBlobMissingAction;
|
|
72
|
+
}
|
|
73
|
+
export interface BlobStoreOptions {
|
|
74
|
+
defaultStoreOptions?: BlobStoreStoreOptions;
|
|
75
|
+
defaultFetchOptions?: BlobStoreFetchOptions;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A specialized Store that is designed to handle MediaBlobs and use the
|
|
79
|
+
* key that is included in the blob to determine exactly how it is stored.
|
|
80
|
+
*
|
|
81
|
+
* The full details of a MediaBlob may be changed when it is stored.
|
|
82
|
+
* For example, it may get additional or different Metadata. This should be
|
|
83
|
+
* what is returned when the store() method is called.
|
|
84
|
+
*
|
|
85
|
+
* Although BlobStore extends BaseStore, not all of the methods from
|
|
86
|
+
* BaseStore may be implemented (or even possible). Those that are not
|
|
87
|
+
* implemented should be documented and throw an Error if called.
|
|
88
|
+
*/
|
|
89
|
+
export declare abstract class BlobStore extends BaseStore<string, MediaBlob> {
|
|
90
|
+
lc_namespace: string[];
|
|
91
|
+
defaultStoreOptions: BlobStoreStoreOptions;
|
|
92
|
+
defaultFetchOptions: BlobStoreFetchOptions;
|
|
93
|
+
constructor(opts?: BlobStoreOptions);
|
|
94
|
+
protected _realKey(key: string | MediaBlob): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Is the path supported by this BlobStore?
|
|
97
|
+
*
|
|
98
|
+
* Although this is async, this is expected to be a relatively fast operation
|
|
99
|
+
* (ie - you shouldn't make network calls).
|
|
100
|
+
*
|
|
101
|
+
* @param path The path to check
|
|
102
|
+
* @param opts Any options (if needed) that may be used to determine if it is valid
|
|
103
|
+
* @return If the path is supported
|
|
104
|
+
*/
|
|
105
|
+
hasValidPath(path: string | undefined, opts?: BlobStoreStoreOptions): Promise<boolean>;
|
|
106
|
+
protected _blobPathSuffix(blob: MediaBlob): string;
|
|
107
|
+
protected _newBlob(oldBlob: MediaBlob, newPath?: string): Promise<MediaBlob>;
|
|
108
|
+
protected _validBlobPrefixPath(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob>;
|
|
109
|
+
protected _validBlobPrefixUuidFunction(name: ActionIfInvalidAction | string): string;
|
|
110
|
+
protected _validBlobPrefixUuid(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob>;
|
|
111
|
+
protected _validBlobRemovePath(blob: MediaBlob, _opts?: BlobStoreStoreOptions): Promise<MediaBlob>;
|
|
112
|
+
/**
|
|
113
|
+
* Based on the blob and options, return a blob that has a valid path
|
|
114
|
+
* that can be saved.
|
|
115
|
+
* @param blob
|
|
116
|
+
* @param opts
|
|
117
|
+
*/
|
|
118
|
+
protected _validStoreBlob(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;
|
|
119
|
+
store(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;
|
|
120
|
+
protected _missingFetchBlobEmpty(path: string, _opts?: BlobStoreFetchOptions): Promise<MediaBlob>;
|
|
121
|
+
protected _missingFetchBlob(path: string, opts?: BlobStoreFetchOptions): Promise<MediaBlob | undefined>;
|
|
122
|
+
fetch(key: string | MediaBlob, opts?: BlobStoreFetchOptions): Promise<MediaBlob | undefined>;
|
|
123
|
+
}
|
|
124
|
+
export interface BackedBlobStoreOptions extends BlobStoreOptions {
|
|
125
|
+
backingStore: BaseStore<string, MediaBlob>;
|
|
126
|
+
}
|
|
127
|
+
export declare class BackedBlobStore extends BlobStore {
|
|
128
|
+
backingStore: BaseStore<string, MediaBlob>;
|
|
129
|
+
constructor(opts: BackedBlobStoreOptions);
|
|
130
|
+
mdelete(keys: string[]): Promise<void>;
|
|
131
|
+
mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;
|
|
132
|
+
mset(keyValuePairs: [string, MediaBlob][]): Promise<void>;
|
|
133
|
+
yieldKeys(prefix: string | undefined): AsyncGenerator<string>;
|
|
134
|
+
}
|
|
135
|
+
export interface ReadThroughBlobStoreOptions extends BlobStoreOptions {
|
|
136
|
+
baseStore: BlobStore;
|
|
137
|
+
backingStore: BlobStore;
|
|
138
|
+
}
|
|
139
|
+
export declare class ReadThroughBlobStore extends BlobStore {
|
|
140
|
+
baseStore: BlobStore;
|
|
141
|
+
backingStore: BlobStore;
|
|
142
|
+
constructor(opts: ReadThroughBlobStoreOptions);
|
|
143
|
+
store(blob: MediaBlob, opts?: BlobStoreStoreOptions): Promise<MediaBlob | undefined>;
|
|
144
|
+
mdelete(keys: string[]): Promise<void>;
|
|
145
|
+
mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;
|
|
146
|
+
mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;
|
|
147
|
+
yieldKeys(prefix: string | undefined): AsyncGenerator<string>;
|
|
148
|
+
}
|
|
149
|
+
export declare class SimpleWebBlobStore extends BlobStore {
|
|
150
|
+
_notImplementedException(): void;
|
|
151
|
+
hasValidPath(path: string | undefined, _opts?: BlobStoreStoreOptions): Promise<boolean>;
|
|
152
|
+
_fetch(url: string): Promise<MediaBlob | undefined>;
|
|
153
|
+
mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;
|
|
154
|
+
mdelete(_keys: string[]): Promise<void>;
|
|
155
|
+
mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;
|
|
156
|
+
yieldKeys(_prefix: string | undefined): AsyncGenerator<string>;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A blob "store" that works with data: URLs that will turn the URL into
|
|
160
|
+
* a blob.
|
|
161
|
+
*/
|
|
162
|
+
export declare class DataBlobStore extends BlobStore {
|
|
163
|
+
_notImplementedException(): void;
|
|
164
|
+
hasValidPath(path: string, _opts?: BlobStoreStoreOptions): Promise<boolean>;
|
|
165
|
+
_fetch(url: string): MediaBlob;
|
|
166
|
+
mget(keys: string[]): Promise<(MediaBlob | undefined)[]>;
|
|
167
|
+
mdelete(_keys: string[]): Promise<void>;
|
|
168
|
+
mset(_keyValuePairs: [string, MediaBlob][]): Promise<void>;
|
|
169
|
+
yieldKeys(_prefix: string | undefined): AsyncGenerator<string>;
|
|
170
|
+
}
|
|
171
|
+
export interface MediaManagerConfiguration {
|
|
172
|
+
/**
|
|
173
|
+
* A store that, given a common URI, returns the corresponding MediaBlob.
|
|
174
|
+
* The returned MediaBlob may have a different URI.
|
|
175
|
+
* In many cases, this will be a ReadThroughStore or something similar
|
|
176
|
+
* that has a cached version of the MediaBlob, but also a way to get
|
|
177
|
+
* a new (or refreshed) version.
|
|
178
|
+
*/
|
|
179
|
+
store: BlobStore;
|
|
180
|
+
/**
|
|
181
|
+
* BlobStores that can resolve a URL into the MediaBlob to save
|
|
182
|
+
* in the canonical store. This list is evaluated in order.
|
|
183
|
+
* If not provided, a default list (which involves a DataBlobStore
|
|
184
|
+
* and a SimpleWebBlobStore) will be used.
|
|
185
|
+
*/
|
|
186
|
+
resolvers?: BlobStore[];
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Responsible for converting a URI (typically a web URL) into a MediaBlob.
|
|
190
|
+
* Allows for aliasing / caching of the requested URI and what it resolves to.
|
|
191
|
+
* This MediaBlob is expected to be usable to provide to an LLM, either
|
|
192
|
+
* through the Base64 of the media or through a canonical URI that the LLM
|
|
193
|
+
* supports.
|
|
194
|
+
*/
|
|
195
|
+
export declare class MediaManager {
|
|
196
|
+
store: BlobStore;
|
|
197
|
+
resolvers: BlobStore[] | undefined;
|
|
198
|
+
constructor(config: MediaManagerConfiguration);
|
|
199
|
+
defaultResolvers(): BlobStore[];
|
|
200
|
+
_isInvalid(blob: MediaBlob | undefined): Promise<boolean>;
|
|
201
|
+
/**
|
|
202
|
+
* Given the public URI, load what is at this URI and save it
|
|
203
|
+
* in the store.
|
|
204
|
+
* @param uri The URI to resolve using the resolver
|
|
205
|
+
* @return A canonical MediaBlob for this URI
|
|
206
|
+
*/
|
|
207
|
+
_resolveAndSave(uri: string): Promise<MediaBlob | undefined>;
|
|
208
|
+
getMediaBlob(uri: string): Promise<MediaBlob | undefined>;
|
|
209
|
+
}
|