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

Commit 446c226

Browse files
Rebase and formatting changes
1 parent 2f663cd commit 446c226

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

src/codegate/db/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ async def record_output_non_stream(
198198
async def record_alerts(self, alerts: List[Alert]) -> None:
199199
if not alerts:
200200
return
201-
logger.info(f"Recording {len(alerts)} alerts.", alerts=alerts)
202201
sql = text(
203202
"""
204203
INSERT INTO alerts (

src/codegate/pipeline/codegate_context_retriever/codegate.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
from codegate.config import Config
77
from codegate.inference.inference_engine import LlamaCppInferenceEngine
88
from codegate.pipeline.base import (
9+
AlertSeverity,
910
PipelineContext,
1011
PipelineResult,
1112
PipelineStep,
1213
)
13-
from src.codegate.storage.storage_engine import StorageEngine
14-
from src.codegate.utils.utils import generate_vector_string
14+
from codegate.storage.storage_engine import StorageEngine
15+
from codegate.utils.utils import generate_vector_string
1516

1617
logger = structlog.get_logger("codegate")
1718

@@ -54,7 +55,7 @@ def generate_context_str(self, objects: list[object]) -> str:
5455
return context_str
5556

5657
async def __lookup_packages(self, user_query: str):
57-
## Check which packages are referenced in the user query
58+
# Check which packages are referenced in the user query
5859
request = {
5960
"messages": [
6061
{"role": "system", "content": Config.get_config().prompts.lookup_packages},
@@ -125,16 +126,23 @@ async def process(
125126
# is list
126127
message = new_request["messages"][last_user_idx]
127128
if isinstance(message["content"], str):
128-
message["content"] = f'Context: {context_str} \n\n Query: {message["content"]}'
129+
context_msg = f'Context: {context_str} \n\n Query: {message["content"]}'
130+
context.add_alert(
131+
self.name, trigger_string=context_msg, severity_category=AlertSeverity.CRITICAL
132+
)
133+
message["content"] = context_msg
129134
elif isinstance(message["content"], (list, tuple)):
130135
for item in message["content"]:
131136
if isinstance(item, dict) and item.get("type") == "text":
132-
item["text"] = f'Context: {context_str} \n\n Query: {item["text"]}'
133-
134-
return PipelineResult(
135-
request=new_request,
136-
context=context,
137-
)
137+
context_msg = f'Context: {context_str} \n\n Query: {item["text"]}'
138+
context.add_alert(
139+
self.name,
140+
trigger_string=context_msg,
141+
severity_category=AlertSeverity.CRITICAL,
142+
)
143+
item["text"] = context_msg
144+
145+
return PipelineResult(request=new_request, context=context)
138146

139147
# Fall through
140148
return PipelineResult(request=request, context=context)

src/codegate/pipeline/extract_snippets/output.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ async def process_chunk(
9898

9999
# Add an alert to the context
100100
input_context.add_alert(self.name, trigger_string=complete_comment)
101-
logger.info(
102-
f"Added alert {self.name} for new code snippet: {complete_comment}",
103-
alerts=input_context.alerts_raised,
104-
num=len(input_context.alerts_raised),
105-
)
106101

107102
return chunks
108103

src/codegate/pipeline/secrets/secrets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def _redeact_text(
157157
logger.info(f"Original: {secret['original']}")
158158
logger.info(f"Encrypted: REDACTED<${secret['encrypted']}>")
159159

160-
print(f"\nProtected text:\n{protected_string}")
160+
logger.info(f"\nProtected text:\n{protected_string}")
161161
return "".join(protected_text)
162162

163163
async def process(

src/codegate/pipeline/system_prompt/codegate.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
import json
22

33
from litellm import ChatCompletionRequest, ChatCompletionSystemMessage
44

@@ -16,9 +16,7 @@ class SystemPrompt(PipelineStep):
1616
"""
1717

1818
def __init__(self, system_prompt: str):
19-
self._system_message = ChatCompletionSystemMessage(
20-
content=system_prompt, role="system"
21-
)
19+
self._system_message = ChatCompletionSystemMessage(content=system_prompt, role="system")
2220

2321
@property
2422
def name(self) -> str:
@@ -46,11 +44,17 @@ async def process(
4644

4745
if request_system_message is None:
4846
# Add system message
47+
context.add_alert(self.name, trigger_string=json.dumps(self._system_message))
4948
new_request["messages"].insert(0, self._system_message)
5049
elif "codegate" not in request_system_message["content"].lower():
5150
# Prepend to the system message
52-
request_system_message["content"] = self._system_message["content"] + \
53-
"\n Here are additional instructions. \n " + request_system_message["content"]
51+
prepended_message = (
52+
self._system_message["content"]
53+
+ "\n Here are additional instructions. \n "
54+
+ request_system_message["content"]
55+
)
56+
context.add_alert(self.name, trigger_string=prepended_message)
57+
request_system_message["content"] = prepended_message
5458

5559
return PipelineResult(
5660
request=new_request,

src/codegate/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from codegate.dashboard.dashboard import dashboard_router
88
from codegate.pipeline.base import PipelineStep, SequentialPipelineProcessor
99
from codegate.pipeline.codegate_context_retriever.codegate import CodegateContextRetriever
10-
from codegate.pipeline.system_prompt.codegate import SystemPrompt
1110
from codegate.pipeline.extract_snippets.extract_snippets import CodeSnippetExtractor
1211
from codegate.pipeline.extract_snippets.output import CodeCommentStep
1312
from codegate.pipeline.output import OutputPipelineProcessor, OutputPipelineStep
1413
from codegate.pipeline.secrets.manager import SecretsManager
1514
from codegate.pipeline.secrets.secrets import CodegateSecrets, SecretUnredactionStep
1615
from codegate.pipeline.secrets.signatures import CodegateSignatures
16+
from codegate.pipeline.system_prompt.codegate import SystemPrompt
1717
from codegate.pipeline.version.version import CodegateVersion
1818
from codegate.providers.anthropic.provider import AnthropicProvider
1919
from codegate.providers.llamacpp.provider import LlamaCppProvider

src/codegate/storage/storage_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import structlog
22
import weaviate
3+
import weaviate.classes as wvc
34
from weaviate.classes.config import DataType
45
from weaviate.classes.query import MetadataQuery
56
from weaviate.embedded import EmbeddedOptions
6-
import weaviate.classes as wvc
77

88
from codegate.config import Config
99
from codegate.inference.inference_engine import LlamaCppInferenceEngine

0 commit comments

Comments
 (0)