mirror of
https://github.com/langchain-ai/llmanager.git
synced 2026-07-01 20:44:01 -04:00
fix: Few shot storage schema
This commit is contained in:
+8
-1
@@ -4,5 +4,12 @@
|
||||
"agent": "./src/llmanager/index.ts:graph"
|
||||
},
|
||||
"env": ".env",
|
||||
"dependencies": ["."]
|
||||
"dependencies": ["."],
|
||||
"store": {
|
||||
"index": {
|
||||
"embed": "openai:text-embedding-3-large",
|
||||
"dims": 3072,
|
||||
"fields": ["$"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"@langchain/langgraph-sdk": "0.0.66",
|
||||
"@langchain/openai": "^0.5.5",
|
||||
"dotenv": "^16.4.7",
|
||||
"langchain": "^0.3.21",
|
||||
"langsmith": "^0.3.15",
|
||||
"uuid": "^11.0.4",
|
||||
"zod": "^3.23.8"
|
||||
|
||||
+4
-27
@@ -1,8 +1,8 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { BaseStore } from "@langchain/langgraph";
|
||||
import { traceable } from "langsmith/traceable";
|
||||
|
||||
const FEW_SHOT_NAMESPACE = ["few-shot"];
|
||||
const FEW_SHOT_KEY = "examples";
|
||||
|
||||
export type FewShotExample = {
|
||||
/**
|
||||
@@ -19,27 +19,6 @@ export type FewShotExample = {
|
||||
input: string;
|
||||
};
|
||||
|
||||
const _DATA_KEY = "few_shots";
|
||||
|
||||
async function getFewShotExamplesFunc(
|
||||
store: BaseStore | undefined,
|
||||
): Promise<FewShotExample[]> {
|
||||
if (!store) {
|
||||
throw new Error("Store not found");
|
||||
}
|
||||
|
||||
const results = await store.get(FEW_SHOT_NAMESPACE, FEW_SHOT_KEY);
|
||||
if (!results?.value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return results.value[_DATA_KEY] ?? [];
|
||||
}
|
||||
|
||||
export const getFewShotExamples = traceable(getFewShotExamplesFunc, {
|
||||
name: "get-few-shot-examples",
|
||||
});
|
||||
|
||||
async function searchFewShotExamplesFunc(
|
||||
store: BaseStore | undefined,
|
||||
query: string,
|
||||
@@ -54,9 +33,7 @@ async function searchFewShotExamplesFunc(
|
||||
limit: args?.limit,
|
||||
});
|
||||
|
||||
const items: FewShotExample[] = results.flatMap(
|
||||
(r) => r.value?.[_DATA_KEY] ?? [],
|
||||
);
|
||||
const items = results.map((r) => r.value as FewShotExample);
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -66,12 +43,12 @@ export const searchFewShotExamples = traceable(searchFewShotExamplesFunc, {
|
||||
|
||||
async function putFewShotExamplesFunc(
|
||||
store: BaseStore | undefined,
|
||||
examples: FewShotExample[],
|
||||
example: FewShotExample,
|
||||
): Promise<void> {
|
||||
if (!store) {
|
||||
throw new Error("Store not found");
|
||||
}
|
||||
await store.put(FEW_SHOT_NAMESPACE, FEW_SHOT_KEY, { [_DATA_KEY]: examples });
|
||||
await store.put(FEW_SHOT_NAMESPACE, uuidv4(), example);
|
||||
}
|
||||
|
||||
export const putFewShotExamples = traceable(putFewShotExamplesFunc, {
|
||||
|
||||
@@ -1202,7 +1202,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@langchain/openai@npm:^0.5.5":
|
||||
"@langchain/openai@npm:>=0.1.0 <0.6.0, @langchain/openai@npm:^0.5.5":
|
||||
version: 0.5.5
|
||||
resolution: "@langchain/openai@npm:0.5.5"
|
||||
dependencies:
|
||||
@@ -1216,6 +1216,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@langchain/textsplitters@npm:>=0.0.0 <0.2.0":
|
||||
version: 0.1.0
|
||||
resolution: "@langchain/textsplitters@npm:0.1.0"
|
||||
dependencies:
|
||||
js-tiktoken: ^1.0.12
|
||||
peerDependencies:
|
||||
"@langchain/core": ">=0.2.21 <0.4.0"
|
||||
checksum: f179113423b003968127abc0b41c23e9ba21bed9336745841bf54b95e283fc3cbfcd67e40d1b58922b89b35953caeb38d8d5d7a3a49c1c5b202f1542bf76dc3a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@nodelib/fs.scandir@npm:2.1.5":
|
||||
version: 2.1.5
|
||||
resolution: "@nodelib/fs.scandir@npm:2.1.5"
|
||||
@@ -5152,6 +5163,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"jsonpointer@npm:^5.0.1":
|
||||
version: 5.0.1
|
||||
resolution: "jsonpointer@npm:5.0.1"
|
||||
checksum: 0b40f712900ad0c846681ea2db23b6684b9d5eedf55807b4708c656f5894b63507d0e28ae10aa1bddbea551241035afe62b6df0800fc94c2e2806a7f3adecd7c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"keyv@npm:^4.5.3":
|
||||
version: 4.5.4
|
||||
resolution: "keyv@npm:4.5.4"
|
||||
@@ -5175,6 +5193,80 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"langchain@npm:^0.3.21":
|
||||
version: 0.3.21
|
||||
resolution: "langchain@npm:0.3.21"
|
||||
dependencies:
|
||||
"@langchain/openai": ">=0.1.0 <0.6.0"
|
||||
"@langchain/textsplitters": ">=0.0.0 <0.2.0"
|
||||
js-tiktoken: ^1.0.12
|
||||
js-yaml: ^4.1.0
|
||||
jsonpointer: ^5.0.1
|
||||
langsmith: ">=0.2.8 <0.4.0"
|
||||
openapi-types: ^12.1.3
|
||||
p-retry: 4
|
||||
uuid: ^10.0.0
|
||||
yaml: ^2.2.1
|
||||
zod: ^3.22.4
|
||||
zod-to-json-schema: ^3.22.3
|
||||
peerDependencies:
|
||||
"@langchain/anthropic": "*"
|
||||
"@langchain/aws": "*"
|
||||
"@langchain/cerebras": "*"
|
||||
"@langchain/cohere": "*"
|
||||
"@langchain/core": ">=0.2.21 <0.4.0"
|
||||
"@langchain/deepseek": "*"
|
||||
"@langchain/google-genai": "*"
|
||||
"@langchain/google-vertexai": "*"
|
||||
"@langchain/google-vertexai-web": "*"
|
||||
"@langchain/groq": "*"
|
||||
"@langchain/mistralai": "*"
|
||||
"@langchain/ollama": "*"
|
||||
"@langchain/xai": "*"
|
||||
axios: "*"
|
||||
cheerio: "*"
|
||||
handlebars: ^4.7.8
|
||||
peggy: ^3.0.2
|
||||
typeorm: "*"
|
||||
peerDependenciesMeta:
|
||||
"@langchain/anthropic":
|
||||
optional: true
|
||||
"@langchain/aws":
|
||||
optional: true
|
||||
"@langchain/cerebras":
|
||||
optional: true
|
||||
"@langchain/cohere":
|
||||
optional: true
|
||||
"@langchain/deepseek":
|
||||
optional: true
|
||||
"@langchain/google-genai":
|
||||
optional: true
|
||||
"@langchain/google-vertexai":
|
||||
optional: true
|
||||
"@langchain/google-vertexai-web":
|
||||
optional: true
|
||||
"@langchain/groq":
|
||||
optional: true
|
||||
"@langchain/mistralai":
|
||||
optional: true
|
||||
"@langchain/ollama":
|
||||
optional: true
|
||||
"@langchain/xai":
|
||||
optional: true
|
||||
axios:
|
||||
optional: true
|
||||
cheerio:
|
||||
optional: true
|
||||
handlebars:
|
||||
optional: true
|
||||
peggy:
|
||||
optional: true
|
||||
typeorm:
|
||||
optional: true
|
||||
checksum: c8bab98c68d7c40189243b55c683da9d7d0c0582f542c2aeed67c7a85ba90a904c553aacf3e654eb0ddecb367cc6f57c88de8a756eb3885ce14672f215947aaa
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"langsmith@npm:>=0.2.8 <0.4.0, langsmith@npm:^0.3.15":
|
||||
version: 0.3.15
|
||||
resolution: "langsmith@npm:0.3.15"
|
||||
@@ -5373,6 +5465,7 @@ __metadata:
|
||||
eslint-plugin-no-instanceof: ^1.0.1
|
||||
eslint-plugin-prettier: ^4.2.1
|
||||
jest: ^29.7.0
|
||||
langchain: ^0.3.21
|
||||
langsmith: ^0.3.15
|
||||
prettier: ^3.3.3
|
||||
ts-jest: ^29.1.0
|
||||
@@ -5948,6 +6041,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"openapi-types@npm:^12.1.3":
|
||||
version: 12.1.3
|
||||
resolution: "openapi-types@npm:12.1.3"
|
||||
checksum: 7fa5547f87a58d2aa0eba6e91d396f42d7d31bc3ae140e61b5d60b47d2fd068b48776f42407d5a8da7280cf31195aa128c2fc285e8bb871d1105edee5647a0bb
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"optionator@npm:^0.9.3":
|
||||
version: 0.9.4
|
||||
resolution: "optionator@npm:0.9.4"
|
||||
@@ -7705,7 +7805,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"yaml@npm:^2.7.0":
|
||||
"yaml@npm:^2.2.1, yaml@npm:^2.7.0":
|
||||
version: 2.7.1
|
||||
resolution: "yaml@npm:2.7.1"
|
||||
bin:
|
||||
|
||||
Reference in New Issue
Block a user