Skip to content
Snippets Groups Projects
Commit 2791f753 authored by Yi Ding's avatar Yi Ding
Browse files

use Record for object dictionaries

parent c78bb48b
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ export interface BaseLLMPredictor {
getLlmMetadata(): Promise<any>;
apredict(
prompt: string | SimplePrompt,
input?: { [key: string]: string }
input?: Record<string, string>
): Promise<string>;
// stream(prompt: string, options: any): Promise<any>;
}
......@@ -31,7 +31,7 @@ export class ChatGPTLLMPredictor implements BaseLLMPredictor {
async apredict(
prompt: string | SimplePrompt,
input?: { [key: string]: string }
input?: Record<string, string>
): Promise<string> {
if (typeof prompt === "string") {
const result = await this.languageModel.agenerate([
......
......@@ -17,7 +17,7 @@ interface BaseMessage {
interface Generation {
text: string;
generationInfo?: { [key: string]: any };
generationInfo?: Record<string, any>;
}
export interface LLMResult {
......
......@@ -25,7 +25,7 @@ export enum MetadataMode {
export interface RelatedNodeInfo {
nodeId: string;
nodeType?: ObjectType;
metadata: { [key: string]: any };
metadata: Record<string, any>;
hash?: string;
}
......@@ -39,7 +39,7 @@ export abstract class BaseNode {
embedding?: number[];
// Metadata fields
metadata: { [key: string]: any } = {};
metadata: Record<string, any> = {};
excludedEmbedMetadataKeys: string[] = [];
excludedLlmMetadataKeys: string[] = [];
relationships: Partial<Record<NodeRelationship, RelatedNodeType>> = {};
......
......@@ -3,7 +3,7 @@
* NOTE this is a different interface compared to LlamaIndex Python
* NOTE 2: we default to empty string to make it easy to calculate prompt sizes
*/
export type SimplePrompt = (input: { [key: string]: string }) => string;
export type SimplePrompt = (input: Record<string, string>) => string;
/*
DEFAULT_TEXT_QA_PROMPT_TMPL = (
......
import _ from "lodash";
import { Document } from "../Document";
import { Document } from "../Node";
import { BaseReader } from "./base";
import { CompleteFileSystem, walk } from "../storage/FileSystem";
import { DEFAULT_FS } from "../storage/constants";
......@@ -15,7 +15,7 @@ export class TextFileReader implements BaseReader {
}
}
const FILE_EXT_TO_READER: { [key: string]: BaseReader } = {
const FILE_EXT_TO_READER: Record<string, BaseReader> = {
txt: new TextFileReader(),
pdf: new PDFReader(),
};
......@@ -24,7 +24,7 @@ export type SimpleDirectoryReaderLoadDataProps = {
directoryPath: string;
fs?: CompleteFileSystem;
defaultReader?: BaseReader | null;
fileExtToReader?: { [key: string]: BaseReader };
fileExtToReader?: Record<string, BaseReader>;
};
export default class SimpleDirectoryReader implements BaseReader {
......
......@@ -22,7 +22,7 @@ export interface WalkableFileSystem {
* A filesystem implementation that stores files in memory.
*/
export class InMemoryFileSystem implements GenericFileSystem {
private files: { [filepath: string]: any } = {};
private files: Record<string, any> = {};
async writeFile(path: string, content: string, options?: any): Promise<void> {
this.files[path] = _.cloneDeep(content);
......
......@@ -11,7 +11,7 @@ import {
DEFAULT_FS,
} from "../constants";
type SaveDict = { [key: string]: any };
type SaveDict = Record<string, any>;
export class SimpleDocumentStore extends KVDocumentStore {
private kvStore: SimpleKVStore;
......
......@@ -9,7 +9,7 @@ const defaultPersistPath = `${DEFAULT_PERSIST_DIR}/${DEFAULT_DOC_STORE_PERSIST_F
export interface RefDocInfo {
docIds: string[];
extraInfo: { [key: string]: any };
extraInfo: Record<string, any>;
}
export abstract class BaseDocumentStore {
......@@ -41,9 +41,7 @@ export abstract class BaseDocumentStore {
abstract getDocumentHash(docId: string): Promise<string | undefined>;
// Ref Docs
abstract getAllRefDocInfo(): Promise<
{ [key: string]: RefDocInfo } | undefined
>;
abstract getAllRefDocInfo(): Promise<Record<string, RefDocInfo> | undefined>;
abstract getRefDocInfo(refDocId: string): Promise<RefDocInfo | undefined>;
......@@ -66,8 +64,8 @@ export abstract class BaseDocumentStore {
async getNodeDict(nodeIdDict: {
[index: number]: string;
}): Promise<{ [index: number]: BaseNode }> {
let result: { [index: number]: BaseNode } = {};
}): Promise<Record<number, BaseNode>> {
let result: Record<number, BaseNode> = {};
for (let index in nodeIdDict) {
result[index] = await this.getNode(nodeIdDict[index]);
}
......
......@@ -4,9 +4,7 @@ import { DEFAULT_COLLECTION, DEFAULT_FS } from "../constants";
import * as _ from "lodash";
import { BaseKVStore } from "./types";
export interface DataType {
[key: string]: { [key: string]: any };
}
export type DataType = Record<string, Record<string, any>>;
export class SimpleKVStore extends BaseKVStore {
private data: DataType;
......
import { GenericFileSystem } from "../FileSystem";
const defaultCollection = "data";
type StoredValue = { [key: string]: any } | null;
type StoredValue = Record<string, any> | null;
export abstract class BaseKVStore {
abstract put(
key: string,
val: { [key: string]: any },
val: Record<string, any>,
collection?: string
): Promise<void>;
abstract get(key: string, collection?: string): Promise<StoredValue>;
abstract getAll(collection?: string): Promise<{ [key: string]: StoredValue }>;
abstract getAll(collection?: string): Promise<Record<string, StoredValue>>;
abstract delete(key: string, collection?: string): Promise<boolean>;
}
......
......@@ -23,8 +23,8 @@ const LEARNER_MODES = new Set<VectorStoreQueryMode>([
const MMR_MODE = VectorStoreQueryMode.MMR;
class SimpleVectorStoreData {
embeddingDict: { [key: string]: number[] } = {};
textIdToRefDocId: { [key: string]: string } = {};
embeddingDict: Record<string, number> = {};
textIdToRefDocId: Record<string, string> = {};
}
export class SimpleVectorStore implements VectorStore {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment