Skip to content

Commit 2f17cdc

Browse files
committed
Add ArtifactEvent model and update workflows to use it
1 parent 6104c3d commit 2f17cdc

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

python/llama-index-server/examples/artifact/code_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919
from llama_index.server.api.models import (
2020
Artifact,
21+
ArtifactEvent,
2122
ArtifactType,
2223
ChatRequest,
2324
CodeArtifactData,
@@ -306,8 +307,7 @@ async def generate_artifact(
306307
)
307308
# To show the Canvas panel for the artifact
308309
ctx.write_event_to_stream(
309-
UIEvent(
310-
type="artifact",
310+
ArtifactEvent(
311311
data=Artifact(
312312
type=ArtifactType.CODE,
313313
created_at=int(time.time()),

python/llama-index-server/examples/artifact/document_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919
from llama_index.server.api.models import (
2020
Artifact,
21+
ArtifactEvent,
2122
ArtifactType,
2223
ChatRequest,
2324
DocumentArtifactData,
@@ -274,8 +275,7 @@ async def generate_artifact(
274275
)
275276
# To show the Canvas panel for the artifact
276277
ctx.write_event_to_stream(
277-
UIEvent(
278-
type="artifact",
278+
ArtifactEvent(
279279
data=Artifact(
280280
type=ArtifactType.DOCUMENT,
281281
created_at=int(time.time()),

python/llama-index-server/llama_index/server/api/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,14 @@ def from_message(cls, message: ChatAPIMessage) -> Optional["Artifact"]:
193193
)
194194

195195
return None
196+
197+
198+
class ArtifactEvent(Event):
199+
type: str = "artifact"
200+
data: Artifact
201+
202+
def to_response(self) -> dict:
203+
return {
204+
"type": self.type,
205+
"data": self.data.model_dump(),
206+
}

0 commit comments

Comments
 (0)