Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit fbabe31

Browse files
author
Luke Hinds
committed
Convert async _close_models in LlamaCppInferenceEngine
Fixes RuntimeWarning about unawaited coroutine by converting the async cleanup method to synchronous since it's called from del. Also fixes dictionary iteration and adjusts method name to follow Python protected method conventions. Resolves: #109
1 parent 0bc3c03 commit fbabe31

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/codegate/inference/inference_engine.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ def __init__(self):
2424
self.__models = {}
2525

2626
def __del__(self):
27-
self.__close_models()
27+
self._close_models()
28+
29+
def _close_models(self):
30+
"""
31+
Closes all open models and samplers
32+
"""
33+
for _, model in self.__models.items():
34+
if model._sampler:
35+
model._sampler.close()
36+
model.close()
2837

2938
async def __get_model(self, model_path, embedding=False, n_ctx=512, n_gpu_layers=0):
3039
"""
@@ -70,12 +79,3 @@ async def embed(self, model_path, content):
7079
"""
7180
model = await self.__get_model(model_path=model_path, embedding=True)
7281
return model.embed(content)
73-
74-
async def __close_models(self):
75-
"""
76-
Closes all open models and samplers
77-
"""
78-
for _, model in self.__models:
79-
if model._sampler:
80-
model._sampler.close()
81-
model.close()

src/codegate/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from codegate.pipeline.codegate_context_retriever.codegate import CodegateContextRetriever
99
from codegate.pipeline.codegate_system_prompt.codegate import CodegateSystemPrompt
1010
from codegate.pipeline.extract_snippets.extract_snippets import CodeSnippetExtractor
11-
from codegate.pipeline.secrets.signatures import CodegateSignatures
1211
from codegate.pipeline.secrets.secrets import CodegateSecrets
12+
from codegate.pipeline.secrets.signatures import CodegateSignatures
1313
from codegate.pipeline.version.version import CodegateVersion
1414
from codegate.providers.anthropic.provider import AnthropicProvider
1515
from codegate.providers.llamacpp.provider import LlamaCppProvider

0 commit comments

Comments
 (0)