Skip to content

Commit efd41bd

Browse files
authored
Merge pull request #61 from ethernautdao/json-setup-fix
Adds json to .gitignore
2 parents 32dbc30 + e3ae427 commit efd41bd

File tree

8 files changed

+39
-12
lines changed

8 files changed

+39
-12
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
**/coverage
77
.nyc_output
88
.nyc_cache
9-
.DS_Store
9+
.DS_Store
10+
11+
12+
packages/ethernaut-ai/src/internal/assistants/docs/kb-files/
13+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethernaut-cli-monorepo",
3-
"version": "1.1.12",
3+
"version": "1.2.0",
44
"private": true,
55
"workspaces": [
66
"packages/*"

packages/ethernaut-ai/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/ethernaut-ai/src/internal/assistants/docs/kb-files/last-update-docs.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/ethernaut-ai/src/internal/assistants/docs/kb-files/last-update-hub.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/ethernaut-ai/src/internal/assistants/utils/build-docs-docs.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ const path = require('path')
33
const openai = require('../../openai')
44
const VECTOR_STORE_ID = 'OP_DOCS_7'
55

6-
const documentKeywords = require('../docs/kb-files/output/optimism/docs/keywords.json')
6+
let documentKeywords = {}
7+
try {
8+
documentKeywords = require('../docs/kb-files/output/optimism/docs/keywords.json')
9+
} catch (err) {
10+
// expected exception on 1st run
11+
if (err.code !== 'MODULE_NOT_FOUND') {
12+
throw err
13+
}
14+
}
715

816
// New vector store implementation 🔴
917
async function buildDocsDocsWithVector(query) {
@@ -30,7 +38,10 @@ async function buildDocsDocsWithVector(query) {
3038
__dirname,
3139
'../docs/kb-files/output/optimism/docs/chapters',
3240
)
33-
const files = Object.keys(documentKeywords)
41+
const files =
42+
Object.keys(documentKeywords).length > 0
43+
? Object.keys(documentKeywords)
44+
: fs.readdirSync(docsDir).filter((file) => file.endsWith('.md'))
3445
const batchSize = 5 // Upload files in batches to avoid rate limits
3546
const allFileIds = []
3647

packages/ethernaut-ai/src/internal/assistants/utils/build-hub-docs.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ function calculateRelevance(query, keywords) {
4545
// Original keyword-based implementation
4646
// DEPRECATED
4747
// Keywords associated with each document
48-
const documentKeywords = require('../docs/kb-files/output/optimism/community-hub/keywords.json')
48+
let documentKeywords = {}
49+
try {
50+
documentKeywords = require('../docs/kb-files/output/optimism/community-hub/keywords.json')
51+
} catch (err) {
52+
// expected exception on 1st run
53+
if (err.code !== 'MODULE_NOT_FOUND') {
54+
throw err
55+
}
56+
}
4957

5058
function buildHubDocsWithKeywords(query) {
5159
const docs = []
@@ -54,6 +62,11 @@ function buildHubDocsWithKeywords(query) {
5462
'../docs/kb-files/output/optimism/community-hub/chapters',
5563
)
5664

65+
// Si no hay keywords, devolver array vacío
66+
if (Object.keys(documentKeywords).length === 0) {
67+
return docs
68+
}
69+
5770
// Calculate relevance for each document
5871
const relevanceScores = Object.entries(documentKeywords).map(
5972
([file, keywords]) => ({
@@ -100,10 +113,13 @@ async function buildHubDocsWithVector(query) {
100113

101114
const docsDir = path.join(
102115
__dirname,
103-
'../docs/kb-files/output/optimism/docs/chapters',
116+
'../docs/kb-files/output/optimism/community-hub/chapters',
104117
)
105118

106-
const files = Object.keys(documentKeywords)
119+
const files =
120+
Object.keys(documentKeywords).length > 0
121+
? Object.keys(documentKeywords)
122+
: fs.readdirSync(docsDir).filter((file) => file.endsWith('.md'))
107123
const batchSize = 5 // Upload files in batches to avoid rate limits
108124
const allFileIds = []
109125

packages/ethernaut-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethernaut-cli",
3-
"version": "1.2.0",
3+
"version": "1.1.12",
44
"description": "Ai agent cli with web3 capabilities",
55
"license": "ISC",
66
"author": "Alejandro Santander",

0 commit comments

Comments
 (0)