Skip to content

Commit

Permalink
0.8.0: Fixed optional envvar and added ingest script
Browse files Browse the repository at this point in the history
  • Loading branch information
flavienbwk committed Sep 8, 2024
1 parent df7e2c5 commit ac04d47
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 11 deletions.
6 changes: 5 additions & 1 deletion action/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as core from '@actions/core';
import { Container, createClient } from '@scaleway/sdk';

import { ingestFiles } from './ingest'

const providers = ['scaleway'];

try {
Expand Down Expand Up @@ -173,7 +175,9 @@ try {
}

// Feed RepoChat with repo data
// TODO(flavienbwk): !!
const containerEndpointApi = 'https://' + containerEndpoint + '/api/ingest';
console.log(`Ingesting files at ${containerEndpointApi}...`);
ingestFiles('./', containerEndpointApi);

// Set outputs
core.setOutput('domain', containerEndpoint);
Expand Down
51 changes: 51 additions & 0 deletions action/ingest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const fs = require('fs');
const path = require('path');
const axios = require('axios');

function isValidFile(filePath) {
return fs.statSync(filePath).isFile() && !path.basename(filePath).startsWith('.');
}

async function sendFileToApi(filePath, apiUrl) {
const content = fs.readFileSync(filePath, { encoding: 'base64' });
const metadata = { source: path.basename(filePath) };
const payload = { content, metadata };

try {
const response = await axios.post(apiUrl, payload);
return response;
} catch (error) {
console.error(`Error sending file: ${error.message}`);
return { status: error.response ? error.response.status : 500 };
}
}

async function ingestFiles(directoryPath, apiUrl) {
if (!fs.existsSync(directoryPath) || !fs.statSync(directoryPath).isDirectory()) {
console.error(`Error: ${directoryPath} is not a valid directory.`);
return;
}

const files = fs.readdirSync(directoryPath, { withFileTypes: true });

for (const file of files) {
const filePath = path.join(directoryPath, file.name);
if (file.isDirectory()) {
await ingestFiles(filePath, apiUrl);
} else if (isValidFile(filePath)) {
console.log(`Sending file: ${filePath}`);
const response = await sendFileToApi(filePath, apiUrl);
if (response.status === 200) {
console.log(`Successfully ingested: ${filePath}`);
} else {
console.log(`Failed to ingest ${filePath}. Status code: ${response.status}`);
}
} else {
console.log(`Skipping invalid or hidden file: ${filePath}`);
}
}
}

module.exports = {
ingestFiles
};
2 changes: 1 addition & 1 deletion api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
OPEN_AI_API_KEY = os.environ['OPENAI_API_KEY'].strip()
MODEL_TYPE_INFERENCE = os.environ['MODEL_TYPE_INFERENCE'].strip()
MODEL_TYPE_EMBEDDING = os.environ['MODEL_TYPE_EMBEDDING'].strip()
CLEAR_DB_AT_RESTART = True if os.environ['CLEAR_DB_AT_RESTART'].strip().lower() == 'true' else False
CLEAR_DB_AT_RESTART = True if os.getenv('CLEAR_DB_AT_RESTART', 'false').strip().lower() == 'true' else False
MODE = os.environ['MODE'].strip()

PATH_NAME_SPLITTER = f'{CURRENT_DIR}/splitted_docs.jsonl'
Expand Down
15 changes: 14 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24829,6 +24829,14 @@ function version(uuid) {
var _default = version;
exports["default"] = _default;

/***/ }),

/***/ 5225:
/***/ ((module) => {

module.exports = eval("require")("./ingest");


/***/ }),

/***/ 9491:
Expand Down Expand Up @@ -70141,6 +70149,9 @@ module.exports = randomName;
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(2186);
/* harmony import */ var _scaleway_sdk__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(5701);
/* harmony import */ var _ingest__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(5225);





Expand Down Expand Up @@ -70316,7 +70327,9 @@ try {
}

// Feed RepoChat with repo data
// TODO(flavienbwk): !!
const containerEndpointApi = 'https://' + containerEndpoint + '/api/ingest';
console.log(`Ingesting files at ${containerEndpointApi}...`);
(0,_ingest__WEBPACK_IMPORTED_MODULE_2__.ingestFiles)('./', containerEndpointApi);

// Set outputs
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('domain', containerEndpoint);
Expand Down
122 changes: 116 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gh-action-repochat",
"version": "0.7.0",
"version": "0.8.0",
"type": "module",
"description": "GitHub Action to run repochat",
"main": "index.js",
Expand All @@ -15,7 +15,9 @@
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
"typescript": "^5.1.3",
"axios": "^1.7.7",
"commander": "^12.1.0"
},
"dependencies": {
"@actions/core": "^1.10.1",
Expand Down

0 comments on commit ac04d47

Please sign in to comment.