Skip to content

Commit

Permalink
feat: add support for aider
Browse files Browse the repository at this point in the history
Aider offers two types of integrations:
- compatible OPENAI API
- local ollama

Add support for those 2 integrations, and correct all different nuances
that we are getting with this new engine

Closes: #440
  • Loading branch information
yrobla committed Jan 10, 2025
1 parent 84d589a commit 70cb1ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ sqlite_data/vectordb.db

# certificate directory
*certs/
.aider*
8 changes: 5 additions & 3 deletions src/codegate/pipeline/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ def get_latest_user_messages(request: ChatCompletionRequest) -> str:

for message in reversed(request.get("messages", [])):
if message["role"] == "user":
latest_user_messages += "\n" + message["content"]
else:
break
# if found we can stop here, if not we continue until we find it
message_str = message.get("content", "")
if message_str:
latest_user_messages += "\n" + str(message_str)
break

return latest_user_messages

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ async def process(
"""
Use RAG DB to add context to the user request
"""

# Get the latest user messages
user_messages = self.get_latest_user_messages(request)

Expand Down
2 changes: 2 additions & 0 deletions src/codegate/pipeline/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class OutputPipelineContext:
snippets: List[CodeSnippet] = field(default_factory=list)
# Store all content that has been processed by the pipeline
processed_content: List[str] = field(default_factory=list)
# partial buffer to store prefixes
prefix_buffer: str = ""


class OutputPipelineStep(ABC):
Expand Down
13 changes: 9 additions & 4 deletions src/codegate/pipeline/secrets/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def process(
if "content" in message and message["content"]:
# Protect the text
protected_string, redacted_count = self._redact_text(
message["content"], secrets_manager, session_id, context
str(message["content"]), secrets_manager, session_id, context
)
new_request["messages"][i]["content"] = protected_string

Expand Down Expand Up @@ -389,12 +389,17 @@ async def process_chunk(
return [chunk]

# If we have a partial marker at the end, keep buffering
if self.marker_start in buffered_content or self._is_partial_marker_prefix(
buffered_content
):
if self.marker_start in buffered_content:
context.prefix_buffer = ""
return []

if self._is_partial_marker_prefix(buffered_content):
context.prefix_buffer += buffered_content
return []

# No markers or partial markers, let pipeline handle the chunk normally
chunk.choices[0].delta.content = context.prefix_buffer + chunk.choices[0].delta.content
context.prefix_buffer = ""
return [chunk]


Expand Down

0 comments on commit 70cb1ec

Please sign in to comment.