-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: experimental package + json query engine #613
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7e668c6
wip
EmanuelCampos 3ed420d
chore: experimental
EmanuelCampos 2042fc2
fix: lock
EmanuelCampos 4a554d0
feat: add types
EmanuelCampos 192ceae
chore: new-experimental
EmanuelCampos 26d48d7
Merge branch 'main' into feat/experiemental-package
EmanuelCampos 3b32927
typos
EmanuelCampos 6bb7aec
Merge branch 'feat/experiemental-package' of github.com:run-llama/Lla…
EmanuelCampos 1d7f58d
chore: remove duplicated script
EmanuelCampos 2ec8744
Merge branch 'main' of github.com:run-llama/LlamaIndexTS into feat/ex…
EmanuelCampos b7cec38
chore: update buidl script
EmanuelCampos f2495ce
docs(changeset): feat: experimental package + json query engine
EmanuelCampos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 "../dist/index.js"; | ||
|
||
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/env", | ||
"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,69 @@ | ||
{ | ||
"name": "@llamaindex/experimental", | ||
"description": "Experimental package for LlamaIndexTS", | ||
"version": "0.0.1", | ||
"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/himself65/LlamaIndexTS.git", | ||
"directory": "packages/env" | ||
}, | ||
"scripts": { | ||
"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", | ||
"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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#620