Skip to content
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

✨ Add hability to run kai demo from the script #34

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions kai-client-ci/.env.example
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
KAI_CLIENT_DOWNLOAD_URL = "https://github.com/konveyor/editor-extensions/releases/download/v0.0.1-dev%2B20241022/konveyor-linux-0.0.1.vsix"
REPOSITORY_URL="https://github.com/konveyor-ecosystem/coolstore"
ORIGINAL_BRANCH="main"
EVALUATION_BRANCH="quarkus"
KAI_EVAL_PATH="/path/to/kai-eval"
S3_BUCKET_NAME=""
3 changes: 3 additions & 0 deletions kai-client-ci/.gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.env
data/
.idea/
kai_files/
venv/
__pycache__/
96 changes: 96 additions & 0 deletions kai-client-ci/files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import json
import platform
import shutil
import stat
import sys
import time
import zipfile
from datetime import datetime
import logging
import os
import pandas as pd

import git

import requests
from dotenv import load_dotenv

from logger import get_logger

logger = get_logger(__name__)


def download_file(url, file_path):
response = requests.get(url, stream=True)
if response.status_code == 200:
with open(file_path, 'wb') as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
logger.info(f'Downloaded {file_path}')
else:
logger.error(f'Failed to download the file {file_path} | Status code: {response.status_code}')


def rename_extracted_folder(base_folder, target_folder_name):
'''
Renames the extracted source code folder which is in format konveyor-kai-[uid] to a standard name 'kai'
'''
extracted_folders = [
folder for folder in os.listdir(base_folder)
if os.path.isdir(os.path.join(base_folder, folder)) and folder.startswith('konveyor-kai-')
]

original_folder_path = os.path.join(base_folder, extracted_folders[0])
target_folder_path = os.path.join(base_folder, target_folder_name)

try:
shutil.move(original_folder_path, target_folder_path)
except Exception as e:
logger.error(f'Failed to rename folder: {e}')


def clone_repository(app_name, repository_url, branch):
clone_dir = os.path.join('data', f'{app_name}')
git.Repo.clone_from(repository_url, clone_dir, branch=branch)
logger.info(f"Repository {app_name} cloned into 'data' with branch 'main'")
abrugaro marked this conversation as resolved.
Show resolved Hide resolved


def unzip_file(zip_path, extract_folder):
try:
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_folder)
logger.info(f'Extracted {zip_path} into {extract_folder}')
except zipfile.BadZipFile:
logger.error(f'Failed to extract {zip_path}')


def zip_folder(file_path, file_name):
zip_filename = f'{file_name}.zip'
zip_path = os.path.join('data', zip_filename)

shutil.make_archive(zip_path.replace('.zip', ''), 'zip', file_path)
abrugaro marked this conversation as resolved.
Show resolved Hide resolved
logger.info(f'Repository compressed into {zip_path}')
return zip_path


def copy_file(src, dst):
try:
if os.path.isdir(src):
shutil.copytree(src, dst)
else:
shutil.copy(src, dst)
logger.info(f'Copied {src} to {dst}')
except Exception as e:
logger.error(f'Error while copying {src} to {dst}: {e}')


def set_executable_permissions(file_path):
try:
logger.info(f'Setting executable permissions for {file_path}')
st = os.stat(file_path)
os.chmod(file_path, st.st_mode | stat.S_IEXEC)
logger.info(f'Executable permissions set for {file_path}')
except FileNotFoundError:
logger.error(f'File not found: {file_path}')
except Exception as e:
logger.error(f'Failed to set executable permissions for {file_path}: {e}')
Binary file added kai-client-ci/fixtures/bundle.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions kai-client-ci/fixtures/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
log_level = "info"
file_log_level = "debug"
log_dir = "./kai-logs/"
demo_mode = false
[models]
provider = "ChatBedrock"
[models.args]
model_id = "meta.llama3-1-70b-instruct-v1:0"
Loading