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

Commit 79aa4aa

Browse files
committed
start adding lm_studio
1 parent 3deb074 commit 79aa4aa

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

src/codegate/pipeline/codegate_context_retriever/codegate.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ def name(self) -> str:
3030
Returns the name of this pipeline step.
3131
"""
3232
return "codegate-context-retriever"
33+
34+
@staticmethod
35+
def process_user_message(user_message: str) -> str:
36+
"""
37+
Process a user message by extracting content inside <task> tags, if present,
38+
and removing all <environment_details> tags along with their content.
39+
40+
Args:
41+
user_message (str): The input user message.
42+
43+
Returns:
44+
str: The processed user message.
45+
"""
46+
# Extract content inside <task> tags if present
47+
task_match = re.search(r"<task>(.*?)</task>", user_message, re.DOTALL)
48+
if task_match:
49+
user_message = task_match.group(1).strip()
50+
51+
# Remove all content inside <environment_details> tags and the tags themselves
52+
user_message = re.sub(r"<environment_details>.*?</environment_details>", "", user_message, flags=re.DOTALL).strip()
53+
54+
return user_message
3355

3456
def generate_context_str(self, objects: list[object], context: PipelineContext) -> str:
3557
context_str = ""

src/codegate/providers/ollama/completion_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async def ollama_stream_generator(
1818
try:
1919
async for chunk in stream:
2020
try:
21+
yield f"{chunk.model_dump_json()}\n\n"
2122
# TODO We should wire in the client info so we can respond with
2223
# the correct format and start to handle multiple clients
2324
# in a more robust way.

src/codegate/providers/ollama/provider.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ async def create_completion(request: Request):
8787

8888
is_fim_request = self._is_fim_request(request, data)
8989
try:
90-
print("i create completion with data", data)
9190
stream = await self.complete(data, api_key=None, is_fim_request=is_fim_request)
9291
except httpx.ConnectError as e:
9392
logger = structlog.get_logger("codegate")
@@ -103,6 +102,4 @@ async def create_completion(request: Request):
103102
else:
104103
# just continue raising the exception
105104
raise e
106-
print("result is")
107-
print(self._completion_handler.create_response(stream))
108105
return self._completion_handler.create_response(stream)

src/codegate/providers/openai/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22

3+
import httpx
34
import structlog
45
from fastapi import Header, HTTPException, Request
56

@@ -35,6 +36,7 @@ def _setup_routes(self):
3536

3637
@self.router.post(f"/{self.provider_route_name}/chat/completions")
3738
@self.router.post(f"/{self.provider_route_name}/completions")
39+
@self.router.post(f"/{self.provider_route_name}/v1/chat/completions")
3840
async def create_completion(
3941
request: Request,
4042
authorization: str = Header(..., description="Bearer token"),
@@ -45,7 +47,6 @@ async def create_completion(
4547
api_key = authorization.split(" ")[1]
4648
body = await request.body()
4749
data = json.loads(body)
48-
4950
is_fim_request = self._is_fim_request(request, data)
5051
try:
5152
stream = await self.complete(data, api_key, is_fim_request=is_fim_request)

0 commit comments

Comments
 (0)