-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: code simplification phase 1 - centralize config, stateless pipeline, extract templates #98
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
Merged
Merged
refactor: code simplification phase 1 - centralize config, stateless pipeline, extract templates #98
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
de96fb2
refactor(config): centralize configuration and constants (#1)
9fd825e
refactor(pipeline): make RagPipeline stateless with PipelineResult (#2)
88386cc
refactor(dspy): extract templates to separate module (#3)
3bd1bf5
refactor(agents): implement lazy program initialization (#4)
46314d2
feat(ingesters): externalize source configurations to JSON (#5)
a3aaf27
test: fix unit tests for stateless pipeline refactoring
74e9d7b
test(ingesters): update error message expectation for unknown source
enitrat c7c2ab1
removed all deprecated/legacy code from the PR
enitrat 33782ea
Simplify retrieval flow and source config paths
enitrat ba4c062
Add sources schema and sourceConfig tests
enitrat 2de3531
chore: fmt
enitrat 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 hidden or 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 hidden or 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,54 @@ | ||
| import { describe, it, expect, beforeEach } from 'bun:test'; | ||
| import { | ||
| clearConfigCache, | ||
| getAvailableSourcesFromConfig, | ||
| getBookConfig, | ||
| getSourceConfig, | ||
| loadSourcesConfig, | ||
| } from '../src/utils/sourceConfig'; | ||
| import { DocumentSource } from '../src/types'; | ||
|
|
||
| describe('sourceConfig', () => { | ||
| beforeEach(() => { | ||
| clearConfigCache(); | ||
| }); | ||
|
|
||
| it('loads sources.json and exposes known sources', () => { | ||
| const config = loadSourcesConfig(); | ||
| const cairoConfig = config.sources[DocumentSource.CAIRO_BOOK]; | ||
|
|
||
| expect(cairoConfig).toBeDefined(); | ||
| expect(cairoConfig.name).toBeTruthy(); | ||
| expect(cairoConfig.config.fileExtensions).toBeInstanceOf(Array); | ||
| }); | ||
|
|
||
| it('returns per-source config and book config helpers', () => { | ||
| const config = loadSourcesConfig(); | ||
| const sourceConfig = getSourceConfig(DocumentSource.CAIRO_BOOK); | ||
| const bookConfig = getBookConfig(DocumentSource.CAIRO_BOOK); | ||
|
|
||
| expect(sourceConfig).toEqual(config.sources[DocumentSource.CAIRO_BOOK]); | ||
| expect(bookConfig).toEqual( | ||
| config.sources[DocumentSource.CAIRO_BOOK].config, | ||
| ); | ||
| }); | ||
|
|
||
| it('returns all available sources from config', () => { | ||
| const sources = getAvailableSourcesFromConfig().slice().sort(); | ||
| const expected = Object.values(DocumentSource).slice().sort(); | ||
|
|
||
| expect(sources).toEqual(expected); | ||
| }); | ||
|
|
||
| it('caches config between loads and can be cleared', () => { | ||
| const first = loadSourcesConfig(); | ||
| const second = loadSourcesConfig(); | ||
|
|
||
| expect(first).toBe(second); | ||
|
|
||
| clearConfigCache(); | ||
| const third = loadSourcesConfig(); | ||
|
|
||
| expect(third).not.toBe(first); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,155 @@ | ||
| { | ||
| "$schema": "./sources.schema.json", | ||
| "sources": { | ||
| "cairo_book": { | ||
| "name": "Cairo Book", | ||
| "description": "The official Cairo programming language book", | ||
| "ingesterClass": "CairoBookIngester", | ||
| "config": { | ||
| "repoOwner": "cairo-book", | ||
| "repoName": "cairo-book", | ||
| "fileExtensions": [".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://book.cairo-lang.org", | ||
| "urlSuffix": ".html", | ||
| "useUrlMapping": true | ||
| } | ||
| }, | ||
| "starknet_docs": { | ||
| "name": "Starknet Docs", | ||
| "description": "Official Starknet documentation", | ||
| "ingesterClass": "StarknetDocsIngester", | ||
| "config": { | ||
| "repoOwner": "starknet-io", | ||
| "repoName": "starknet-docs", | ||
| "fileExtensions": [".mdx"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://docs.starknet.io", | ||
| "urlSuffix": "", | ||
| "useUrlMapping": true | ||
| } | ||
| }, | ||
| "starknet_foundry": { | ||
| "name": "Starknet Foundry", | ||
| "description": "Starknet Foundry testing framework documentation", | ||
| "ingesterClass": "StarknetFoundryIngester", | ||
| "config": { | ||
| "repoOwner": "foundry-rs", | ||
| "repoName": "starknet-foundry", | ||
| "fileExtensions": [".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://foundry-rs.github.io/starknet-foundry", | ||
| "urlSuffix": ".html", | ||
| "useUrlMapping": true | ||
| } | ||
| }, | ||
| "cairo_by_example": { | ||
| "name": "Cairo By Example", | ||
| "description": "Learn Cairo through practical examples", | ||
| "ingesterClass": "CairoByExampleIngester", | ||
| "config": { | ||
| "repoOwner": "NethermindEth", | ||
| "repoName": "StarknetByExample", | ||
| "fileExtensions": [".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://starknet-by-example.voyager.online", | ||
| "urlSuffix": ".html", | ||
| "useUrlMapping": true | ||
| } | ||
| }, | ||
| "openzeppelin_docs": { | ||
| "name": "OpenZeppelin Docs", | ||
| "description": "OpenZeppelin Cairo contracts documentation", | ||
| "ingesterClass": "OpenZeppelinDocsIngester", | ||
| "config": { | ||
| "repoOwner": "OpenZeppelin", | ||
| "repoName": "cairo-contracts", | ||
| "fileExtensions": [".adoc"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://docs.openzeppelin.com/contracts-cairo", | ||
| "urlSuffix": "", | ||
| "useUrlMapping": false | ||
| } | ||
| }, | ||
| "corelib_docs": { | ||
| "name": "Core Library Docs", | ||
| "description": "Cairo core library documentation", | ||
| "ingesterClass": "CoreLibDocsIngester", | ||
| "config": { | ||
| "repoOwner": "starkware-libs", | ||
| "repoName": "cairo", | ||
| "fileExtensions": [".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://docs.cairo-lang.org/core", | ||
| "urlSuffix": ".html", | ||
| "useUrlMapping": true | ||
| } | ||
| }, | ||
| "scarb_docs": { | ||
| "name": "Scarb Docs", | ||
| "description": "Scarb package manager documentation", | ||
| "ingesterClass": "ScarbDocsIngester", | ||
| "config": { | ||
| "repoOwner": "software-mansion", | ||
| "repoName": "scarb", | ||
| "fileExtensions": [".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://docs.swmansion.com/scarb/docs", | ||
| "urlSuffix": ".html", | ||
| "useUrlMapping": true | ||
| } | ||
| }, | ||
| "starknet_js": { | ||
| "name": "Starknet.js", | ||
| "description": "Starknet JavaScript SDK documentation", | ||
| "ingesterClass": "StarknetJSIngester", | ||
| "config": { | ||
| "repoOwner": "starknet-io", | ||
| "repoName": "starknet.js", | ||
| "fileExtensions": [".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://www.starknetjs.com", | ||
| "urlSuffix": "", | ||
| "useUrlMapping": true | ||
| } | ||
| }, | ||
| "starknet_blog": { | ||
| "name": "Starknet Blog", | ||
| "description": "Official Starknet blog posts and articles", | ||
| "ingesterClass": "StarknetBlogIngester", | ||
| "config": { | ||
| "repoOwner": "starknet-io", | ||
| "repoName": "starknet-blog", | ||
| "fileExtensions": [".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://starknet.io/blog", | ||
| "urlSuffix": "", | ||
| "useUrlMapping": false | ||
| } | ||
| }, | ||
| "dojo_docs": { | ||
| "name": "Dojo Docs", | ||
| "description": "Dojo game engine documentation", | ||
| "ingesterClass": "DojoDocsIngester", | ||
| "config": { | ||
| "repoOwner": "dojoengine", | ||
| "repoName": "book", | ||
| "fileExtensions": [".mdx", ".md"], | ||
| "chunkSize": 4096, | ||
| "chunkOverlap": 512, | ||
| "baseUrl": "https://book.dojoengine.org", | ||
| "urlSuffix": "", | ||
| "useUrlMapping": true | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,79 @@ | ||
| { | ||
| "$schema": "https://json-schema.org/draft-07/schema#", | ||
| "title": "Cairo Coder Sources Config", | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["sources"], | ||
| "properties": { | ||
| "sources": { | ||
| "type": "object", | ||
| "additionalProperties": { | ||
| "$ref": "#/definitions/sourceConfig" | ||
| } | ||
| } | ||
| }, | ||
| "definitions": { | ||
| "sourceConfig": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": ["name", "description", "ingesterClass", "config"], | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| }, | ||
| "description": { | ||
| "type": "string" | ||
| }, | ||
| "ingesterClass": { | ||
| "type": "string" | ||
| }, | ||
| "config": { | ||
| "$ref": "#/definitions/bookConfig" | ||
| } | ||
| } | ||
| }, | ||
| "bookConfig": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "required": [ | ||
| "repoOwner", | ||
| "repoName", | ||
| "fileExtensions", | ||
| "chunkSize", | ||
| "chunkOverlap", | ||
| "baseUrl", | ||
| "urlSuffix", | ||
| "useUrlMapping" | ||
| ], | ||
| "properties": { | ||
| "repoOwner": { | ||
| "type": "string" | ||
| }, | ||
| "repoName": { | ||
| "type": "string" | ||
| }, | ||
| "fileExtensions": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "chunkSize": { | ||
| "type": "integer" | ||
| }, | ||
| "chunkOverlap": { | ||
| "type": "integer" | ||
| }, | ||
| "baseUrl": { | ||
| "type": "string" | ||
| }, | ||
| "urlSuffix": { | ||
| "type": "string" | ||
| }, | ||
| "useUrlMapping": { | ||
| "type": "boolean" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.