mirror of
https://github.com/ianarawjo/ChainForge.git
synced 2025-03-15 00:36:29 +00:00
wip converting queryLLM in flask_app to TS
This commit is contained in:
parent
d61bd922ca
commit
476e59365f
1103
chainforge/react-server/src/backend/backend.ts
Normal file
1103
chainforge/react-server/src/backend/backend.ts
Normal file
File diff suppressed because it is too large
Load Diff
37
chainforge/react-server/src/backend/cache.ts
Normal file
37
chainforge/react-server/src/backend/cache.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Dict } from "./typing";
|
||||
|
||||
/**
|
||||
* Singleton JSON cache that functions like a local filesystem in a Python backend,
|
||||
* but where 'storageKeys' are used in place of filepaths.
|
||||
*/
|
||||
export default class StorageCache {
|
||||
private static instance: StorageCache;
|
||||
private data: Dict;
|
||||
|
||||
private constructor() {
|
||||
// Initialize the singleton instance
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
/** Gets the storage cache. Initializes it if the singleton instance does not yet exist. */
|
||||
public static getInstance(): StorageCache {
|
||||
if (!StorageCache.instance) {
|
||||
StorageCache.instance = new StorageCache();
|
||||
}
|
||||
return StorageCache.instance;
|
||||
}
|
||||
|
||||
private getCacheData(key: string): Dict {
|
||||
return this.data[key] || {};
|
||||
}
|
||||
public static get(key: string): Dict {
|
||||
return StorageCache.getInstance().getCacheData(key);
|
||||
}
|
||||
|
||||
private storeCacheData(key: string, _data: any): void {
|
||||
this.data[key] = _data;
|
||||
}
|
||||
public static store(key: string, data: any): void {
|
||||
StorageCache.getInstance().storeCacheData(key, data);
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import { PromptTemplate, PromptPermutationGenerator } from "./template";
|
||||
import { LLM, RATE_LIMITS } from './models';
|
||||
import { Dict, LLMResponseError, LLMResponseObject, LLMAPICall } from "./typing";
|
||||
import { call_chatgpt, call_anthropic, call_google_palm, call_azure_openai, call_dalai, getEnumName, extract_responses, merge_response_objs } from "./utils";
|
||||
import StorageCache from "./cache";
|
||||
|
||||
interface _IntermediateLLMResponseType {
|
||||
prompt: PromptTemplate | string,
|
||||
@ -17,42 +18,6 @@ interface _IntermediateLLMResponseType {
|
||||
past_resp_obj?: LLMResponseObject | undefined,
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton JSON cache that functions like a local filesystem in a Python backend,
|
||||
* but where 'storageKeys' are used in place of filepaths.
|
||||
*/
|
||||
class StorageCache {
|
||||
private static instance: StorageCache;
|
||||
private data: Dict;
|
||||
|
||||
private constructor() {
|
||||
// Initialize the singleton instance
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
/** Gets the storage cache. Initializes it if the singleton instance does not yet exist. */
|
||||
public static getInstance(): StorageCache {
|
||||
if (!StorageCache.instance) {
|
||||
StorageCache.instance = new StorageCache();
|
||||
}
|
||||
return StorageCache.instance;
|
||||
}
|
||||
|
||||
private getCacheData(key: string): Dict {
|
||||
return this.data[key] || {};
|
||||
}
|
||||
public static get(key: string): Dict {
|
||||
return StorageCache.getInstance().getCacheData(key);
|
||||
}
|
||||
|
||||
private storeCacheData(key: string, _data: any): void {
|
||||
this.data[key] = _data;
|
||||
}
|
||||
public static store(key: string, data: any): void {
|
||||
StorageCache.getInstance().storeCacheData(key, data);
|
||||
}
|
||||
}
|
||||
|
||||
// From trincot @ SO: https://stackoverflow.com/a/76477994/1911342
|
||||
// Functions equivalently to Python's asyncio 'as_completed' method,
|
||||
// performing a Promise.race() but where all promises are yielded as they complete
|
||||
|
Loading…
x
Reference in New Issue
Block a user