Compare commits

...

1 Commits

Author SHA1 Message Date
Alex Yang c439162d7c refactor: use crypto.randomUUID
Ref: https://nodejs.org/docs/latest/api/crypto.html#cryptorandomuuidoptions
2024-01-12 12:14:05 -06:00
7 changed files with 15 additions and 33 deletions
-2
View File
@@ -27,7 +27,6 @@
"rake-modified": "^1.0.8",
"replicate": "^0.21.1",
"string-strip-html": "^13.4.3",
"uuid": "^9.0.1",
"wink-nlp": "^1.14.3"
},
"devDependencies": {
@@ -36,7 +35,6 @@
"@types/node": "^18.19.2",
"@types/papaparse": "^5.3.14",
"@types/pg": "^8.10.9",
"@types/uuid": "^9.0.7",
"node-stdlib-browser": "^1.2.0",
"tsup": "^7.2.0",
"typescript": "^5.3.2"
+4 -4
View File
@@ -1,4 +1,4 @@
import { v4 as uuidv4 } from "uuid";
import { randomUUID } from "node:crypto";
import { ChatHistory } from "./ChatHistory";
import { NodeWithScore, TextNode } from "./Node";
import {
@@ -206,7 +206,7 @@ export class DefaultContextGenerator implements ContextGenerator {
async generate(message: string, parentEvent?: Event): Promise<Context> {
if (!parentEvent) {
parentEvent = {
id: uuidv4(),
id: randomUUID(),
type: "wrapper",
tags: ["final"],
};
@@ -272,7 +272,7 @@ export class ContextChatEngine implements ChatEngine {
}
const parentEvent: Event = {
id: uuidv4(),
id: randomUUID(),
type: "wrapper",
tags: ["final"],
};
@@ -304,7 +304,7 @@ export class ContextChatEngine implements ChatEngine {
chatHistory = chatHistory ?? this.chatHistory;
const parentEvent: Event = {
id: uuidv4(),
id: randomUUID(),
type: "wrapper",
tags: ["final"],
};
+2 -2
View File
@@ -1,6 +1,6 @@
import { encodingForModel } from "js-tiktoken";
import { v4 as uuidv4 } from "uuid";
import { randomUUID } from "node:crypto";
import { Event, EventTag, EventType } from "./callbacks/CallbackManager";
export enum Tokenizers {
@@ -64,7 +64,7 @@ class GlobalsHelper {
tags?: EventTag[];
}): Event {
return {
id: uuidv4(),
id: randomUUID(),
type,
// inherit parent tags if tags not set
tags: tags || parentEvent?.tags,
+3 -4
View File
@@ -1,7 +1,6 @@
import _ from "lodash";
import { createHash } from "node:crypto";
import path from "path";
import { v4 as uuidv4 } from "uuid";
import { createHash, randomUUID } from "node:crypto";
import path from "node:path";
export enum NodeRelationship {
SOURCE = "SOURCE",
@@ -49,7 +48,7 @@ export abstract class BaseNode<T extends Metadata = Metadata> {
*
* Set to a UUID by default.
*/
id_: string = uuidv4();
id_: string = randomUUID();
embedding?: number[];
// Metadata fields
+4 -4
View File
@@ -1,4 +1,4 @@
import { v4 as uuidv4 } from "uuid";
import { randomUUID } from "node:crypto";
import { NodeWithScore, TextNode } from "./Node";
import {
BaseQuestionGenerator,
@@ -72,7 +72,7 @@ export class RetrieverQueryEngine implements BaseQueryEngine {
async query(query: string, parentEvent?: Event) {
const _parentEvent: Event = parentEvent || {
id: uuidv4(),
id: randomUUID(),
type: "wrapper",
tags: ["final"],
};
@@ -136,14 +136,14 @@ export class SubQuestionQueryEngine implements BaseQueryEngine {
// groups final retrieval+synthesis operation
const parentEvent: Event = {
id: uuidv4(),
id: randomUUID(),
type: "wrapper",
tags: ["final"],
};
// groups all sub-queries
const subQueryParentEvent: Event = {
id: uuidv4(),
id: randomUUID(),
parentId: parentEvent.id,
type: "wrapper",
tags: ["intermediate"],
+2 -2
View File
@@ -1,4 +1,4 @@
import { v4 as uuidv4 } from "uuid";
import { randomUUID } from "node:crypto";
import { BaseNode, Document, jsonToNode } from "../Node";
import { BaseQueryEngine } from "../QueryEngine";
import { BaseRetriever } from "../Retriever";
@@ -16,7 +16,7 @@ export abstract class IndexStruct {
indexId: string;
summary?: string;
constructor(indexId = uuidv4(), summary = undefined) {
constructor(indexId = randomUUID(), summary = undefined) {
this.indexId = indexId;
this.summary = summary;
}
-15
View File
@@ -212,9 +212,6 @@ importers:
string-strip-html:
specifier: ^13.4.3
version: 13.4.3
uuid:
specifier: ^9.0.1
version: 9.0.1
wink-nlp:
specifier: ^1.14.3
version: 1.14.3
@@ -234,9 +231,6 @@ importers:
'@types/pg':
specifier: ^8.10.9
version: 8.10.9
'@types/uuid':
specifier: ^9.0.7
version: 9.0.7
node-stdlib-browser:
specifier: ^1.2.0
version: 1.2.0
@@ -4794,10 +4788,6 @@ packages:
resolution: {integrity: sha512-d0XxK3YTObnWVp6rZuev3c49+j4Lo8g4L1ZRm9z5L0xpoZycUPshHgczK5gsUMaZOstjVYYi09p5gYvUtfChYw==}
dev: false
/@types/uuid@9.0.7:
resolution: {integrity: sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g==}
dev: true
/@types/validate-npm-package-name@3.0.0:
resolution: {integrity: sha512-iFNNIrEaJH1lbPiyX+O/QyxSbKxrTjdNBVZGckt+iEL9So0hdZNBL68sOfHnt2txuUD8UJXvmKv/1DkgkebgUg==}
dev: true
@@ -16047,11 +16037,6 @@ packages:
hasBin: true
dev: false
/uuid@9.0.1:
resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}
hasBin: true
dev: false
/v8-compile-cache-lib@3.0.1:
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
dev: true