Skip to content

Commit 23ebf9c

Browse files
authored
Merge pull request #16 from CVector-Energy/amy/add-agent-post
[PD1-668] Add ability to add agent post
2 parents 5410539 + fac4454 commit 23ebf9c

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

examples/add_agent_post_example.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
import uuid
3+
4+
from cvec import CVec
5+
from cvec.models.agent_post import AgentPostRecommendation, AgentPostTag, Severity
6+
7+
8+
def main() -> None:
9+
# Initialize CVec client
10+
cvec = CVec(
11+
host=os.environ.get("CVEC_HOST", "https://your-subdomain.cvector.dev"),
12+
api_key=os.environ.get("CVEC_API_KEY", "your-api-key"),
13+
)
14+
15+
recommendations = [
16+
AgentPostRecommendation(
17+
content="Critical recommendation",
18+
severity=Severity.CRITICAL,
19+
),
20+
AgentPostRecommendation(
21+
content="Warning recommendation",
22+
severity=Severity.WARNING,
23+
),
24+
AgentPostRecommendation(
25+
content="Info recommendation",
26+
severity=Severity.INFO,
27+
),
28+
]
29+
30+
tags = [
31+
AgentPostTag(
32+
content="urgent",
33+
severity=Severity.CRITICAL,
34+
),
35+
AgentPostTag(
36+
content="monitoring",
37+
severity=Severity.INFO,
38+
),
39+
]
40+
41+
cvec.add_agent_post(
42+
title="Test post",
43+
author="Operational Agent",
44+
image_id=str(uuid.uuid4()), # Replace with actual image UUID uploaded to S3
45+
content="SDK add post test.",
46+
recommendations=recommendations,
47+
tags=tags,
48+
)
49+
50+
51+
if __name__ == "__main__":
52+
main()

src/cvec/cvec.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from urllib.parse import urlencode, urljoin
88
from urllib.request import Request, urlopen
99

10+
from cvec.models.agent_post import AgentPost, AgentPostRecommendation, AgentPostTag
1011
from cvec.models.eav_column import EAVColumn
1112
from cvec.models.eav_filter import EAVFilter
1213
from cvec.models.eav_table import EAVTable
@@ -426,6 +427,35 @@ def get_modeling_metrics_data_arrow(
426427
assert isinstance(result, bytes)
427428
return result
428429

430+
def add_agent_post(
431+
self,
432+
title: str,
433+
author: str,
434+
image_id: Optional[str] = None,
435+
content: Optional[str] = None,
436+
recommendations: Optional[List[AgentPostRecommendation]] = None,
437+
tags: Optional[List[AgentPostTag]] = None,
438+
) -> None:
439+
"""
440+
Add an agent post.
441+
442+
Note: If image_id is provided, the image must be uploaded to S3 beforehand.
443+
The image_id should be the UUID used as the filename (without .png extension)
444+
in the S3 bucket at the tenant's path.
445+
"""
446+
447+
post = AgentPost(
448+
title=title,
449+
author=author,
450+
image_id=image_id,
451+
content=content,
452+
recommendations=recommendations,
453+
tags=tags,
454+
)
455+
payload = post.model_dump(mode="json", exclude_none=True)
456+
457+
self._make_request("POST", "/api/agent_posts/add", json_data=payload)
458+
429459
def _login_with_supabase(self, email: str, password: str) -> None:
430460
"""
431461
Login to Supabase and get access/refresh tokens.

src/cvec/models/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
from .agent_post import (
2+
AgentPost,
3+
AgentPostRecommendation,
4+
AgentPostTag,
5+
Severity,
6+
)
17
from .eav_column import EAVColumn
28
from .eav_filter import EAVFilter
39
from .eav_table import EAVTable
410
from .metric import Metric, MetricDataPoint
511
from .span import Span
612

713
__all__ = [
14+
"AgentPost",
15+
"AgentPostRecommendation",
16+
"AgentPostTag",
817
"EAVColumn",
918
"EAVFilter",
1019
"EAVTable",
1120
"Metric",
1221
"MetricDataPoint",
22+
"Severity",
1323
"Span",
1424
]

src/cvec/models/agent_post.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from enum import Enum
2+
from typing import List, Optional
3+
4+
from pydantic import BaseModel, Field
5+
6+
7+
class Severity(str, Enum):
8+
"""Severity level for recommendations and tags."""
9+
10+
CRITICAL = "critical"
11+
WARNING = "warning"
12+
INFO = "info"
13+
14+
15+
class AgentPostRecommendation(BaseModel):
16+
"""
17+
Represents a recommendation for creating an agent post.
18+
"""
19+
20+
content: str = Field(..., min_length=1)
21+
severity: Severity
22+
23+
24+
class AgentPostTag(BaseModel):
25+
"""
26+
Represents a tag for creating an agent post.
27+
"""
28+
29+
content: str = Field(..., min_length=1)
30+
severity: Severity
31+
32+
33+
class AgentPost(BaseModel):
34+
"""
35+
Represents an agent post with optional recommendations and tags.
36+
"""
37+
38+
author: str
39+
title: str
40+
content: Optional[str] = None
41+
image_id: Optional[str] = None
42+
recommendations: Optional[List[AgentPostRecommendation]] = None
43+
tags: Optional[List[AgentPostTag]] = None

0 commit comments

Comments
 (0)