Skip to content

Commit 9187fce

Browse files
committed
version with eni requested changment
1 parent 6bde5f3 commit 9187fce

File tree

5 files changed

+56
-57
lines changed

5 files changed

+56
-57
lines changed

ingesters/src/ingesters/AsciiDocIngester.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ export abstract class AsciiDocIngester extends BaseIngester {
161161
*
162162
* @param sourceDir - Source directory
163163
* @param targetDir - Target directory
164-
* @param fileExtensions - File extension to process
164+
* @param fileExtension - File extension to process
165165
* @returns Promise<boolean> - Whether relevant files were found
166166
*/
167167
private async restructureFiles(
168168
sourceDir: string,
169169
targetDir: string,
170-
fileExtensions: string = '.adoc',
170+
fileExtension: string = '.adoc',
171171
): Promise<boolean> {
172172
const entries = await fs.readdir(sourceDir, { withFileTypes: true });
173173
let hasRelevantFiles = false;
@@ -185,7 +185,7 @@ export abstract class AsciiDocIngester extends BaseIngester {
185185
const subDirHasRelevantFiles = await this.restructureFiles(
186186
sourcePath,
187187
targetDir,
188-
fileExtensions,
188+
fileExtension,
189189
);
190190
if (subDirHasRelevantFiles) {
191191
hasRelevantFiles = true;
@@ -194,16 +194,13 @@ export abstract class AsciiDocIngester extends BaseIngester {
194194
const subDirHasRelevantFiles = await this.restructureFiles(
195195
sourcePath,
196196
targetPath,
197-
fileExtensions,
197+
fileExtension,
198198
);
199199
if (subDirHasRelevantFiles) {
200200
hasRelevantFiles = true;
201201
}
202202
}
203-
} else if (
204-
entry.isFile() &&
205-
path.extname(entry.name) === fileExtensions
206-
) {
203+
} else if (entry.isFile() && path.extname(entry.name) === fileExtension) {
207204
if (entry.name.toLowerCase() === 'nav.adoc') {
208205
continue;
209206
}

ingesters/src/ingesters/OpenZeppelinDocsIngester.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as fsPromises from 'fs/promises';
22
import * as path from 'path';
33
import { Document } from '@langchain/core/documents';
44
import { type BookChunk, DocumentSource } from '../types';
5-
import { VectorStore } from '../db/postgresVectorStore';
65
import { type BookConfig, type BookPageDto } from '../utils/types';
76
import { logger } from '../utils/logger';
87
import {
@@ -68,33 +67,36 @@ export class OpenZeppelinDocsIngester extends AsciiDocIngester {
6867
const entries = await fsPromises.readdir(dir, { withFileTypes: true });
6968

7069
for (const entry of entries) {
71-
for (const fileExtension of config.fileExtensions) {
72-
const fullPath = path.join(dir, entry.name);
70+
const fullPath = path.join(dir, entry.name);
7371

74-
if (entry.isDirectory()) {
75-
// Recursively process subdirectories
76-
await processDirectory(fullPath);
77-
} else if (
78-
entry.isFile() &&
79-
path.extname(entry.name).toLowerCase() === fileExtension // TODO: handle multiple extensions
80-
) {
81-
// Process AsciiDoc files
82-
const content = await fsPromises.readFile(fullPath, 'utf8');
72+
if (entry.isDirectory()) {
73+
// Recursively process subdirectories
74+
await processDirectory(fullPath);
75+
} else if (
76+
entry.isFile() &&
77+
config.fileExtensions.includes(
78+
path.extname(entry.name).toLowerCase(),
79+
)
80+
) {
81+
// Process AsciiDoc files
82+
const content = await fsPromises.readFile(fullPath, 'utf8');
8383

84-
// Get the relative path of the file from the base directory - which reflects the online website directory structure
85-
const relativePath = path.relative(directory, fullPath);
84+
// Get the relative path of the file from the base directory - which reflects the online website directory structure
85+
const relativePath = path.relative(directory, fullPath);
8686

87-
// Inject cairo-contracts/2.0.0 in the fullPath to reflect online website directory structure
88-
// This is the special handling for OpenZeppelin docs
89-
const adaptedFullPageName = path
90-
.join('contracts-cairo', OZ_DOCS_VERSION, relativePath)
91-
.replace(fileExtension, '');
87+
// Get the file extension to remove it from the final page name
88+
const fileExtension = path.extname(entry.name).toLowerCase();
9289

93-
pages.push({
94-
name: adaptedFullPageName,
95-
content,
96-
});
97-
}
90+
// Inject cairo-contracts/2.0.0 in the fullPath to reflect online website directory structure
91+
// This is the special handling for OpenZeppelin docs
92+
const adaptedFullPageName = path
93+
.join('contracts-cairo', OZ_DOCS_VERSION, relativePath)
94+
.replace(fileExtension, '');
95+
96+
pages.push({
97+
name: adaptedFullPageName,
98+
content,
99+
});
98100
}
99101
}
100102
}

ingesters/src/ingesters/StarknetDocsIngester.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,28 @@ export class StarknetDocsIngester extends MarkdownIngester {
112112
const entries = await fs.readdir(dir, { withFileTypes: true });
113113

114114
for (const entry of entries) {
115-
for (const extension of this.config.fileExtensions) {
116-
const fullPath = path.join(dir, entry.name);
117-
118-
if (entry.isDirectory()) {
119-
// Recursively process subdirectories
120-
await processDirectory(fullPath);
121-
} else if (
122-
entry.isFile() &&
123-
path.extname(entry.name).toLowerCase() === extension // Handle specified extensions
124-
) {
125-
// Process MDX files
126-
const content = await fs.readFile(fullPath, 'utf8');
127-
128-
// Remove the repository path to get relative path
129-
const relativePath = path.relative(this.getExtractDir(), fullPath);
130-
const pageName = relativePath.replace('.mdx', '');
131-
132-
pages.push({
133-
name: pageName,
134-
content,
135-
});
136-
}
115+
const fullPath = path.join(dir, entry.name);
116+
117+
if (entry.isDirectory()) {
118+
// Recursively process subdirectories
119+
await processDirectory(fullPath);
120+
} else if (
121+
entry.isFile() &&
122+
this.config.fileExtensions.includes(
123+
path.extname(entry.name).toLowerCase(),
124+
)
125+
) {
126+
// Process MDX files
127+
const content = await fs.readFile(fullPath, 'utf8');
128+
129+
// Remove the repository path to get relative path
130+
const relativePath = path.relative(this.getExtractDir(), fullPath);
131+
const pageName = relativePath.replace('.mdx', '');
132+
133+
pages.push({
134+
name: pageName,
135+
content,
136+
});
137137
}
138138
}
139139
};

python/optimizers/results/optimized_retrieval_program.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

python/src/cairo_coder/dspy/query_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import os
1010
from typing import Optional
1111

12+
import dspy
1213
import structlog
1314
from langsmith import traceable
1415

15-
import dspy
1616
from cairo_coder.core.types import DocumentSource, ProcessedQuery
1717

1818
logger = structlog.get_logger(__name__)

0 commit comments

Comments
 (0)