forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: experimental package + json query engine (run-llama#613)
- Loading branch information
1 parent
fdf48dd
commit aefc326
Showing
18 changed files
with
654 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"llamaindex": patch | ||
--- | ||
|
||
feat: experimental package + json query engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
}, | ||
"target": "esnext" | ||
}, | ||
"module": { | ||
"type": "commonjs", | ||
"ignoreDynamic": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript" | ||
}, | ||
"target": "esnext" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @llamaindex/experimental |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { JSONQueryEngine } from "@llamaindex/experimental"; | ||
|
||
import { OpenAI, serviceContextFromDefaults } from "llamaindex"; | ||
|
||
const jsonValue = { | ||
blogPosts: [ | ||
{ | ||
id: 1, | ||
title: "First blog post", | ||
content: "This is my first blog post", | ||
}, | ||
{ | ||
id: 2, | ||
title: "Second blog post", | ||
content: "This is my second blog post", | ||
}, | ||
], | ||
comments: [ | ||
{ | ||
id: 1, | ||
content: "Nice post!", | ||
username: "jerry", | ||
blogPostId: 1, | ||
}, | ||
{ | ||
id: 2, | ||
content: "Interesting thoughts", | ||
username: "simon", | ||
blogPostId: 2, | ||
}, | ||
{ | ||
id: 3, | ||
content: "Loved reading this!", | ||
username: "simon", | ||
blogPostId: 2, | ||
}, | ||
], | ||
}; | ||
|
||
const jsonSchema = { | ||
type: "object", | ||
properties: { | ||
blogPosts: { | ||
type: "array", | ||
items: { | ||
type: "object", | ||
properties: { | ||
id: { | ||
type: "number", | ||
}, | ||
title: { | ||
type: "string", | ||
}, | ||
content: { | ||
type: "string", | ||
}, | ||
}, | ||
required: ["id", "title", "content"], | ||
}, | ||
}, | ||
comments: { | ||
type: "array", | ||
items: { | ||
type: "object", | ||
properties: { | ||
id: { | ||
type: "number", | ||
}, | ||
content: { | ||
type: "string", | ||
}, | ||
username: { | ||
type: "string", | ||
}, | ||
blogPostId: { | ||
type: "number", | ||
}, | ||
}, | ||
required: ["id", "content", "username", "blogPostId"], | ||
}, | ||
}, | ||
}, | ||
required: ["blogPosts", "comments"], | ||
}; | ||
|
||
async function main() { | ||
const llm = new OpenAI({ model: "gpt-4" }); | ||
|
||
const serviceContext = serviceContextFromDefaults({ | ||
llm, | ||
}); | ||
|
||
const jsonQueryEngine = new JSONQueryEngine({ | ||
jsonValue, | ||
jsonSchema, | ||
serviceContext, | ||
}); | ||
|
||
const rawQueryEngine = new JSONQueryEngine({ | ||
jsonValue, | ||
jsonSchema, | ||
serviceContext, | ||
synthesizeResponse: false, | ||
}); | ||
|
||
const response = await jsonQueryEngine.query({ | ||
query: "give to me the comment with id 1", | ||
}); | ||
|
||
const rawResponse = await rawQueryEngine.query({ | ||
query: "give me all simon comments", | ||
}); | ||
|
||
console.log({ response }); | ||
|
||
console.log({ rawResponse }); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "examples", | ||
"private": true, | ||
"version": "0.0.3", | ||
"dependencies": { | ||
"@llamaindex/experimental": "latest", | ||
"llamaindex": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.19.10", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.3.3" | ||
}, | ||
"scripts": { | ||
"lint": "eslint ." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@llamaindex/experimental", | ||
"version": "0.0.5", | ||
"exports": { | ||
".": "./src/index.ts", | ||
"./type": "./src/type.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"name": "@llamaindex/experimental", | ||
"description": "Experimental package for LlamaIndexTS", | ||
"version": "0.0.2", | ||
"type": "module", | ||
"types": "dist/type/index.d.ts", | ||
"main": "dist/cjs/index.js", | ||
"exports": { | ||
".": { | ||
"workerd": { | ||
"types": "./dist/type/index.d.ts", | ||
"default": "./dist/index.polyfill.js" | ||
}, | ||
"edge-light": { | ||
"types": "./dist/type/index.d.ts", | ||
"default": "./dist/index.polyfill.js" | ||
}, | ||
"import": { | ||
"types": "./dist/type/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/type/index.d.ts", | ||
"default": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"./*": { | ||
"import": { | ||
"types": "./dist/type/*.d.ts", | ||
"default": "./dist/*.js" | ||
}, | ||
"require": { | ||
"types": "./dist/type/*.d.ts", | ||
"default": "./dist/cjs/*.js" | ||
} | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"CHANGELOG.md" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/run-llama/LlamaIndexTS.git", | ||
"directory": "packages/experimental" | ||
}, | ||
"scripts": { | ||
"lint": "eslint .", | ||
"build": "rm -rf ./dist && pnpm run build:esm && pnpm run build:cjs && pnpm run build:type", | ||
"build:esm": "swc src -d dist --strip-leading-paths --config-file ../../.swcrc", | ||
"build:cjs": "swc src -d dist/cjs --strip-leading-paths --config-file ../../.cjs.swcrc", | ||
"build:type": "tsc -p tsconfig.json", | ||
"postbuild": "node -e \"require('fs').writeFileSync('./dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }))\"", | ||
"dev": "concurrently \"pnpm run build:esm --watch\" \"pnpm run build:cjs --watch\" \"pnpm run build:type --watch\"" | ||
}, | ||
"devDependencies": { | ||
"@aws-crypto/sha256-js": "^5.2.0", | ||
"@swc/cli": "^0.3.9", | ||
"@swc/core": "^1.4.2", | ||
"@types/jsonpath": "^0.2.4", | ||
"concurrently": "^8.2.2", | ||
"pathe": "^1.1.2" | ||
}, | ||
"dependencies": { | ||
"@types/lodash": "^4.14.202", | ||
"@types/node": "^20.11.20", | ||
"jsonpath": "^1.1.1", | ||
"llamaindex": "workspace:*", | ||
"lodash": "^4.17.21" | ||
} | ||
} |
Oops, something went wrong.