Skip to content

Commit 1609d45

Browse files
committed
implement aiservice side
1 parent 1f79fac commit 1609d45

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

codeflash/api/aiservice.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pydantic.json import pydantic_encoder
1111

1212
from codeflash.cli_cmds.console import console, logger
13+
from codeflash.code_utils.code_utils import get_installed_packages
1314
from codeflash.code_utils.env_utils import get_codeflash_api_key
1415
from codeflash.code_utils.git_utils import get_last_commit_author_if_pr_exists, get_repo_owner_and_name
1516
from codeflash.models.models import OptimizedCandidate
@@ -27,6 +28,7 @@ class AiServiceClient:
2728
def __init__(self) -> None:
2829
self.base_url = self.get_aiservice_base_url()
2930
self.headers = {"Authorization": f"Bearer {get_codeflash_api_key()}", "Connection": "close"}
31+
self.installed_packages = get_installed_packages()
3032

3133
def get_aiservice_base_url(self) -> str:
3234
if os.environ.get("CODEFLASH_AIS_SERVER", default="prod").lower() == "local":
@@ -66,6 +68,8 @@ def make_ai_service_request(
6668
"""
6769
url = f"{self.base_url}/ai{endpoint}"
6870
if method.upper() == "POST":
71+
if self.installed_packages:
72+
payload["installed_packages"] = self.installed_packages
6973
json_payload = json.dumps(payload, indent=None, default=pydantic_encoder)
7074
headers = {**self.headers, "Content-Type": "application/json"}
7175
response = requests.post(url, data=json_payload, headers=headers, timeout=timeout)

codeflash/code_utils/code_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,10 @@ def exit_with_message(message: str, *, error_on_exit: bool = False) -> None:
245245
}
246246

247247

248-
def get_installed_packages() -> set[str]:
248+
def get_installed_packages() -> list[str]:
249249
pkgs = importlib.metadata.packages_distributions().keys()
250-
return {
250+
return [
251251
pkg
252252
for pkg in pkgs
253253
if not any(blacklisted in pkg for blacklisted in blacklist_installed_pkgs) and not pkg.startswith("_")
254-
}
255-
256-
257-
print(get_installed_packages())
254+
]

0 commit comments

Comments
 (0)