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

Commit d800164

Browse files
authored
Merge branch 'main' into cline
2 parents 50ce55c + c9d4737 commit d800164

File tree

17 files changed

+183
-116
lines changed

17 files changed

+183
-116
lines changed

migrations/versions/2025_01_21_0820-4dec3e456c9e_add_on_delete_cascade.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919

2020
def upgrade() -> None:
21+
# Turn off foreign key constraints for this migration
22+
op.execute("PRAGMA foreign_keys=off;")
23+
24+
# Begin transaction
25+
op.execute("BEGIN TRANSACTION;")
26+
2127
# To add ON DELETE CASCADE to the foreign key constraint, we need to
2228
# rename the table, create a new table with the constraint, and copy
2329
# the data over.
@@ -101,6 +107,13 @@ def upgrade() -> None:
101107
op.execute("CREATE INDEX idx_prompts_workspace_id ON prompts (workspace_id);")
102108
op.execute("CREATE INDEX idx_sessions_workspace_id ON sessions (active_workspace_id);")
103109

110+
# Finish transaction
111+
op.execute("COMMIT;")
112+
113+
# Turn on foreign key constraints after the migration. Just to be sure. This shouldn't
114+
# be necessary, since it should be specified at the beginning of every connection, doesn't hurt.
115+
op.execute("PRAGMA foreign_keys=on;")
116+
104117

105118
def downgrade() -> None:
106119
# Settings table
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""rename system_prompt
2+
3+
Revision ID: 90d5471db49a
4+
Revises: 4dec3e456c9e
5+
Create Date: 2025-01-22 09:56:21.520839+00:00
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
13+
# revision identifiers, used by Alembic.
14+
revision: str = "90d5471db49a"
15+
down_revision: Union[str, None] = "4dec3e456c9e"
16+
branch_labels: Union[str, Sequence[str], None] = None
17+
depends_on: Union[str, Sequence[str], None] = None
18+
19+
20+
def upgrade() -> None:
21+
op.execute("ALTER TABLE workspaces RENAME COLUMN system_prompt TO custom_instructions;")
22+
23+
24+
def downgrade() -> None:
25+
op.execute("ALTER TABLE workspaces RENAME COLUMN custom_instructions TO system_prompt;")

poetry.lock

Lines changed: 22 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ PyYAML = "==6.0.2"
1212
fastapi = "==0.115.6"
1313
uvicorn = "==0.34.0"
1414
structlog = "==25.1.0"
15-
litellm = "==1.59.0"
15+
litellm = "==1.59.1"
1616
llama_cpp_python = "==0.3.5"
1717
cryptography = "==44.0.0"
1818
sqlalchemy = "==2.0.37"
1919
aiosqlite = "==0.20.0"
20-
ollama = "==0.4.6"
20+
ollama = "==0.4.7"
2121
pydantic-settings = "==2.7.1"
2222
numpy = "==2.2.2"
2323
tree-sitter = "==0.24.0"
@@ -28,7 +28,7 @@ tree-sitter-python = "==0.23.6"
2828
tree-sitter-rust = "==0.23.2"
2929
alembic = "==1.14.1"
3030
pygments = "==2.19.1"
31-
sqlite-vec = "==0.1.6"
31+
sqlite-vec-sl-tmp = "==0.0.4"
3232

3333
[tool.poetry.group.dev.dependencies]
3434
pytest = "==8.3.4"
@@ -38,7 +38,7 @@ ruff = "==0.9.2"
3838
bandit = "==1.8.2"
3939
build = "==1.2.2.post1"
4040
wheel = "==0.45.1"
41-
litellm = "==1.59.0"
41+
litellm = "==1.59.1"
4242
pytest-asyncio = "==0.25.2"
4343
llama_cpp_python = "==0.3.5"
4444
scikit-learn = "==1.6.1"
@@ -62,7 +62,7 @@ line-length = 100
6262
target-version = "py310"
6363
fix = true
6464
exclude = [
65-
"src/codegate/db/queries.py", # Ignore auto-generated file from sqlc
65+
"src/codegate/db/queries.py", # Ignore auto-generated file from sqlc
6666
]
6767

6868
[tool.ruff.lint]

scripts/import_packages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sqlite3
66

77
import numpy as np
8-
import sqlite_vec
8+
import sqlite_vec_sl_tmp
99

1010
from codegate.inference.inference_engine import LlamaCppInferenceEngine
1111
from codegate.utils.utils import generate_vector_string
@@ -27,7 +27,7 @@ def __init__(self, jsonl_dir="data", vec_db_path="./sqlite_data/vectordb.db"):
2727
def _get_connection(self):
2828
conn = sqlite3.connect(self.vec_db_path)
2929
conn.enable_load_extension(True)
30-
sqlite_vec.load(conn)
30+
sqlite_vec_sl_tmp.load(conn)
3131
conn.enable_load_extension(False)
3232
return conn
3333

src/codegate/api/v1.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,35 +228,37 @@ async def get_workspace_messages(workspace_name: str) -> List[Conversation]:
228228

229229

230230
@v1.get(
231-
"/workspaces/{workspace_name}/system-prompt",
231+
"/workspaces/{workspace_name}/custom-instructions",
232232
tags=["Workspaces"],
233233
generate_unique_id_function=uniq_name,
234234
)
235-
async def get_workspace_system_prompt(workspace_name: str) -> v1_models.SystemPrompt:
236-
"""Get the system prompt for a workspace."""
235+
async def get_workspace_custom_instructions(workspace_name: str) -> v1_models.CustomInstructions:
236+
"""Get the custom instructions of a workspace."""
237237
try:
238238
ws = await wscrud.get_workspace_by_name(workspace_name)
239239
except crud.WorkspaceDoesNotExistError:
240240
raise HTTPException(status_code=404, detail="Workspace does not exist")
241241
except Exception:
242242
raise HTTPException(status_code=500, detail="Internal server error")
243243

244-
if ws.system_prompt is None:
245-
return v1_models.SystemPrompt(prompt="")
244+
if ws.custom_instructions is None:
245+
return v1_models.CustomInstructions(prompt="")
246246

247-
return v1_models.SystemPrompt(prompt=ws.system_prompt)
247+
return v1_models.CustomInstructions(prompt=ws.custom_instructions)
248248

249249

250250
@v1.put(
251-
"/workspaces/{workspace_name}/system-prompt",
251+
"/workspaces/{workspace_name}/custom-instructions",
252252
tags=["Workspaces"],
253253
generate_unique_id_function=uniq_name,
254254
status_code=204,
255255
)
256-
async def set_workspace_system_prompt(workspace_name: str, request: v1_models.SystemPrompt):
256+
async def set_workspace_custom_instructions(
257+
workspace_name: str, request: v1_models.CustomInstructions
258+
):
257259
try:
258260
# This already checks if the workspace exists
259-
await wscrud.update_workspace_system_prompt(workspace_name, [request.prompt])
261+
await wscrud.update_workspace_custom_instructions(workspace_name, [request.prompt])
260262
except crud.WorkspaceDoesNotExistError:
261263
raise HTTPException(status_code=404, detail="Workspace does not exist")
262264
except Exception:
@@ -266,15 +268,15 @@ async def set_workspace_system_prompt(workspace_name: str, request: v1_models.Sy
266268

267269

268270
@v1.delete(
269-
"/workspaces/{workspace_name}/system-prompt",
271+
"/workspaces/{workspace_name}/custom-instructions",
270272
tags=["Workspaces"],
271273
generate_unique_id_function=uniq_name,
272274
status_code=204,
273275
)
274-
async def delete_workspace_system_prompt(workspace_name: str):
276+
async def delete_workspace_custom_instructions(workspace_name: str):
275277
try:
276278
# This already checks if the workspace exists
277-
await wscrud.update_workspace_system_prompt(workspace_name, [])
279+
await wscrud.update_workspace_custom_instructions(workspace_name, [])
278280
except crud.WorkspaceDoesNotExistError:
279281
raise HTTPException(status_code=404, detail="Workspace does not exist")
280282
except Exception:

src/codegate/api/v1_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Workspace(pydantic.BaseModel):
1010
is_active: bool
1111

1212

13-
class SystemPrompt(pydantic.BaseModel):
13+
class CustomInstructions(pydantic.BaseModel):
1414
prompt: str
1515

1616

src/codegate/db/connection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ async def add_workspace(self, workspace_name: str) -> Workspace:
271271
It may raise a ValidationError if the workspace name is invalid.
272272
or a AlreadyExistsError if the workspace already exists.
273273
"""
274-
workspace = Workspace(id=str(uuid.uuid4()), name=workspace_name, system_prompt=None)
274+
workspace = Workspace(id=str(uuid.uuid4()), name=workspace_name, custom_instructions=None)
275275
sql = text(
276276
"""
277277
INSERT INTO workspaces (id, name)
@@ -294,7 +294,7 @@ async def update_workspace(self, workspace: Workspace) -> Workspace:
294294
"""
295295
UPDATE workspaces SET
296296
name = :name,
297-
system_prompt = :system_prompt
297+
custom_instructions = :custom_instructions
298298
WHERE id = :id
299299
RETURNING *
300300
"""
@@ -477,7 +477,7 @@ async def get_archived_workspaces(self) -> List[Workspace]:
477477
sql = text(
478478
"""
479479
SELECT
480-
id, name, system_prompt
480+
id, name, custom_instructions
481481
FROM workspaces
482482
WHERE deleted_at IS NOT NULL
483483
ORDER BY deleted_at DESC
@@ -490,7 +490,7 @@ async def get_workspace_by_name(self, name: str) -> Optional[Workspace]:
490490
sql = text(
491491
"""
492492
SELECT
493-
id, name, system_prompt
493+
id, name, custom_instructions
494494
FROM workspaces
495495
WHERE name = :name AND deleted_at IS NULL
496496
"""
@@ -505,7 +505,7 @@ async def get_archived_workspace_by_name(self, name: str) -> Optional[Workspace]
505505
sql = text(
506506
"""
507507
SELECT
508-
id, name, system_prompt
508+
id, name, custom_instructions
509509
FROM workspaces
510510
WHERE name = :name AND deleted_at IS NOT NULL
511511
"""
@@ -531,7 +531,7 @@ async def get_active_workspace(self) -> Optional[ActiveWorkspace]:
531531
sql = text(
532532
"""
533533
SELECT
534-
w.id, w.name, w.system_prompt, s.id as session_id, s.last_update
534+
w.id, w.name, w.custom_instructions, s.id as session_id, s.last_update
535535
FROM sessions s
536536
INNER JOIN workspaces w ON w.id = s.active_workspace_id
537537
"""

0 commit comments

Comments
 (0)