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

initial stubs

parent fe8ca1dc
No related branches found
No related tags found
No related merge requests found
{
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
export interface BaseDocument {
getText(): string;
getDocId(): string;
getDocHash(): string;
getEmbedding(): number[];
}
export class Document implements BaseDocument {
docId: string;
text: string;
embedding: number[];
docHash: string;
constructor(docId: string, text: string) {
this.docId = docId;
this.text = text;
}
getText() {
console.log("getText");
return "";
}
getDocId() {
console.log("getDocId");
return "";
}
getDocHash() {
console.log("getDocHash");
return "";
}
getEmbedding() {
console.log("getEmbedding");
return [];
}
}
export enum SimilarityType {
DEFAULT = "cosine",
DOT_PRODUCT = "dot_product",
EUCLIDEAN = "euclidean",
}
export class BaseEmbedding {
getQueryEmbedding(query: string): number[] {
return [];
}
getTextEmbedding(text: string): number[] {
return [];
}
similarity(
embedding1: number[],
embedding2: number[],
mode: SimilarityType
): number {
return 0;
}
}
import { Document } from "./Document";
import { Node } from "./Node";
export class BaseIndex {
constructor(nodes?: Node[]) {}
fromDocuments(documents: Document[]) {
console.log("fromDocuments");
}
asQueryEngine() {
console.log("asQueryEngine");
}
}
export class VectorStoreIndex extends BaseIndex {}
export interface BaseLLMPredictor {
getLlmMetadata(): Promise<any>;
predict(prompt: string, options: any): Promise<any>;
stream(prompt: string, options: any): Promise<any>;
}
export class LLMPredictor implements BaseLLMPredictor {
llm: string;
retryOnThrottling: boolean;
constructor(llm: string, retryOnThrottling: boolean = true) {
this.llm = llm;
this.retryOnThrottling = retryOnThrottling;
}
async getLlmMetadata() {
console.log("getLlmMetadata");
}
async predict(prompt: string, options: any) {
console.log("predict");
}
async stream(prompt: string, options: any) {
console.log("stream");
}
}
import { BaseDocument } from "./Document";
export enum DocumentRelationship {
SOURCE = "source",
PREVIOUS = "previous",
NEXT = "next",
PARENT = "parent",
CHILD = "child",
}
export enum NodeType {
TEXT,
IMAGE,
INDEX,
}
export class Node implements BaseDocument {
relationships: { [key in DocumentRelationship]: string | string[] };
getText(): string {
throw new Error("Method not implemented.");
}
getDocId(): string {
throw new Error("Method not implemented.");
}
getDocHash(): string {
throw new Error("Method not implemented.");
}
getEmbedding(): number[] {
throw new Error("Method not implemented.");
}
getNodeInfo(): { [key: string]: any } {
return {};
}
refDocId(): string | null {
return "";
}
prevNodeId(): string {
throw new Error("Node does not have previous node");
}
nextNodeId(): string {
throw new Error("Node does not have next node");
}
parentNodeId(): string {
throw new Error("Node does not have parent node");
}
childNodeIds(): string[] {
return [];
}
}
/**
* A prompt is a function that takes a dictionary of inputs and returns a string.
* NOTE this is a different interface compared to LlamaIndex Python
*/
export type Prompt = (input: { [key: string]: string }) => string;
/*
DEFAULT_TEXT_QA_PROMPT_TMPL = (
"Context information is below. \n"
"---------------------\n"
"{context_str}"
"\n---------------------\n"
"Given the context information and not prior knowledge, "
"answer the question: {query_str}\n"
)
*/
export const defaultTextQaPrompt: Prompt = (input: {
[key: string]: string;
}) => {
const { context, query } = input;
return `Context information is below.
---------------------
${context}
---------------------
Given the context information and not prior knowledge, answer the question: ${query}
`;
};
/*
DEFAULT_SUMMARY_PROMPT_TMPL = (
"Write a summary of the following. Try to use only the "
"information provided. "
"Try to include as many key details as possible.\n"
"\n"
"\n"
"{context_str}\n"
"\n"
"\n"
'SUMMARY:"""\n'
)
*/
export const defaultSummaryPrompt: Prompt = (input: {
[key: string]: string;
}) => {
const { context } = input;
return `Write a summary of the following. Try to use only the information provided. Try to include as many key details as possible.
${input.context}
SUMMARY:"""
`;
};
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