Skip to content

Commit 443b6c0

Browse files
payneiobkrabach
andauthored
Assistant drive library
Co-authored-by: Brian Krabach <brian@krabach.com>
1 parent 5c76e40 commit 443b6c0

18 files changed

Lines changed: 1433 additions & 22 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"epivision.vscode-file-header",
5858
"esbenp.prettier-vscode",
5959
"github.vscode-github-actions",
60-
"matt-rudge.auto-open-preview-panel",
6160
"ms-azuretools.vscode-docker",
6261
"ms-python.debugpy",
6362
"ms-python.python",

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,6 @@
219219
"winget",
220220
"workbenchservice"
221221
],
222-
"markdown.validate.enabled": true
222+
"markdown.validate.enabled": true,
223+
"makefile.configureOnOpen": false
223224
}

assistants/prospector-assistant/assistant/agents/attachment_agent.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import base64
22
import io
33
import logging
4-
from pathlib import Path
54
from typing import Annotated, Any
65

76
import docx2txt
87
import pdfplumber
8+
from assistant_drive import Drive, DriveConfig
9+
from context import Context
910
from openai.types import chat
1011
from pydantic import BaseModel, Field
1112
from semantic_workbench_api_model.workbench_model import File
@@ -14,11 +15,6 @@
1415
FileStorageContext,
1516
)
1617
from semantic_workbench_assistant.config import UISchema
17-
from semantic_workbench_assistant.storage import (
18-
read_model,
19-
read_models_in_dir,
20-
write_model,
21-
)
2218

2319
logger = logging.getLogger(__name__)
2420

@@ -84,15 +80,16 @@ async def create_or_update_attachment_from_file(
8480
content = await _file_to_str(context, file)
8581

8682
# see if there is already an attachment with this filename
87-
attachment = read_model(_get_attachment_storage_path(context, filename), Attachment)
88-
if attachment:
83+
try:
84+
attachment = _get_attachment_drive(context).read_model(Attachment, filename)
8985
# if there is, update the content
9086
attachment.content = content
91-
else:
87+
except FileNotFoundError:
9288
# if there isn't, create a new attachment
9389
attachment = Attachment(filename=filename, content=content, metadata=metadata)
9490

95-
write_model(_get_attachment_storage_path(context, filename), attachment)
91+
# write the attachment to the storage
92+
_get_attachment_drive(context).write_model(attachment, filename)
9693

9794
@staticmethod
9895
def delete_attachment_for_file(context: ConversationContext, file: File) -> None:
@@ -101,7 +98,7 @@ def delete_attachment_for_file(context: ConversationContext, file: File) -> None
10198
"""
10299

103100
filename = file.filename
104-
_get_attachment_storage_path(context, filename).unlink(missing_ok=True)
101+
_get_attachment_drive(context).delete(filename)
105102

106103
@staticmethod
107104
def generate_attachment_messages(
@@ -120,7 +117,7 @@ def generate_attachment_messages(
120117
"""
121118

122119
# get all attachments and exit early if there are none
123-
attachments = read_models_in_dir(_get_attachment_storage_path(context), Attachment)
120+
attachments = _get_attachment_drive(context).read_models(Attachment)
124121
if not attachments:
125122
return []
126123

@@ -233,14 +230,13 @@ def reduce_attachment_payload_from_content(value: Any) -> Any:
233230
#
234231

235232

236-
def _get_attachment_storage_path(context: ConversationContext, filename: str | None = None) -> Path:
233+
def _get_attachment_drive(context: ConversationContext) -> Drive:
237234
"""
238-
Get the path where attachments are stored.
235+
Get the Drive instance for the attachments.
239236
"""
240-
path = FileStorageContext.get(context).directory / "attachments"
241-
if filename:
242-
path /= filename
243-
return path
237+
drive_context = Context(session_id=context.id)
238+
drive_root = str(FileStorageContext.get(context).directory / "attachments")
239+
return Drive(DriveConfig(context=drive_context, root=drive_root))
244240

245241

246242
async def _raw_content_from_file(context: ConversationContext, file: File) -> bytes:

assistants/prospector-assistant/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies = [
2222
"document-skill>=0.1.0",
2323
"guided-conversation>=0.1.0",
2424
"openai-client>=0.1.0",
25+
"assistant-drive>=0.1.0",
2526
]
2627

2728
[tool.uv]
@@ -37,6 +38,7 @@ posix-skill = { path = "../../libraries/python/skills/skills/posix-skill", edita
3738
prospector-skill = { path = "../../libraries/python/skills/skills/prospector-skill", editable = true }
3839
document-skill = { path = "../../libraries/python/skills/skills/document-skill", editable = true }
3940
openai-client = { path = "../../libraries/python/openai-client", editable = true }
41+
assistant-drive = { path = "../../libraries/python/assistant-drive", editable = true }
4042

4143
[build-system]
4244
requires = ["hatchling"]

assistants/prospector-assistant/uv.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
__pycache__
2+
.pytest_cache
3+
*.egg*
4+
.data
5+
.venv
6+
venv
7+
.env
8+
9+
poetry.lock
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"aarontamasfe.even-better-toml",
4+
"charliermarsh.ruff",
5+
"ms-python.python"
6+
]
7+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"editor.bracketPairColorization.enabled": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll": "always",
5+
"source.organizeImports": "always"
6+
},
7+
"editor.defaultFormatter": "esbenp.prettier-vscode",
8+
"editor.formatOnPaste": true,
9+
"editor.formatOnSave": true,
10+
"editor.formatOnType": true,
11+
"editor.guides.bracketPairs": "active",
12+
"files.eol": "\n",
13+
"files.trimTrailingWhitespace": true,
14+
"flake8.ignorePatterns": [
15+
"**/*.py"
16+
], // disable flake8 in favor of ruff
17+
"jupyter.debugJustMyCode": false,
18+
"python.analysis.autoFormatStrings": true,
19+
"python.analysis.autoImportCompletions": true,
20+
"python.analysis.diagnosticMode": "workspace",
21+
"python.analysis.exclude": [
22+
"**/.venv/**",
23+
"**/.data/**",
24+
"**/__pycache__/**"
25+
],
26+
"python.analysis.fixAll": [
27+
"source.unusedImports"
28+
],
29+
"python.analysis.inlayHints.functionReturnTypes": true,
30+
"python.analysis.typeCheckingMode": "basic",
31+
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
32+
"python.testing.cwd": "${workspaceFolder}",
33+
"python.testing.pytestArgs": [
34+
"--color",
35+
"yes"
36+
],
37+
"python.testing.pytestEnabled": true,
38+
"search.exclude": {
39+
"**/.venv": true,
40+
"**/data": true
41+
},
42+
"[json]": {
43+
"editor.defaultFormatter": "esbenp.prettier-vscode",
44+
"editor.formatOnSave": true
45+
},
46+
"[jsonc]": {
47+
"editor.defaultFormatter": "esbenp.prettier-vscode",
48+
"editor.formatOnSave": true
49+
},
50+
"[python]": {
51+
"editor.defaultFormatter": "charliermarsh.ruff",
52+
"editor.formatOnSave": true,
53+
"editor.codeActionsOnSave": {
54+
"source.fixAll": "explicit",
55+
"source.unusedImports": "explicit",
56+
"source.organizeImports": "explicit",
57+
"source.formatDocument": "explicit"
58+
}
59+
},
60+
"ruff.nativeServer": "on",
61+
"cSpell.words": [
62+
"dotenv",
63+
"httpx",
64+
"openai",
65+
"pydantic",
66+
"pypdf",
67+
"runtimes",
68+
"tiktoken"
69+
]
70+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
repo_root = $(shell git rev-parse --show-toplevel)
2+
include $(repo_root)/tools/makefiles/python.mk
3+
include $(repo_root)/tools/makefiles/docker-assistant.mk
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Assistant Drive
2+
3+
These are file storage capabilities.

0 commit comments

Comments
 (0)