MCPcopy Index your code
hub / github.com/TaskingAI/TaskingAI / Message

Class Message

backend/app/models/assistant/message.py:55–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53
54
55class Message(ModelEntity):
56 object: str = "Message"
57 assistant_id: str = id_field("assistant", length_range=(1, 50))
58 chat_id: str = id_field("chat", length=24)
59 message_id: str = id_field("message", length=24)
60
61 role: MessageRole = Field(..., description="The role of the message")
62 content: MessageContent = Field(..., description="The content of the message")
63 num_tokens: int = Field(..., ge=0, description="The number of tokens in the message.")
64 metadata: Dict = metadata_field()
65
66 created_timestamp: int = created_timestamp_field()
67 updated_timestamp: int = updated_timestamp_field()
68
69 @staticmethod
70 def build(row):
71 return Message(
72 assistant_id=row["assistant_id"],
73 chat_id=row["chat_id"],
74 message_id=row["message_id"],
75 role=MessageRole(row["role"]),
76 content=MessageContent(**load_json_attr(row, "content", {})),
77 num_tokens=row["num_tokens"],
78 metadata=load_json_attr(row, "metadata", {}),
79 created_timestamp=row["created_timestamp"],
80 updated_timestamp=row["updated_timestamp"],
81 )
82
83 def to_response_dict(self) -> Dict:
84 return {
85 "object": "Message",
86 "assistant_id": self.assistant_id,
87 "chat_id": self.chat_id,
88 "message_id": self.message_id,
89 "role": self.role,
90 "content": self.content.model_dump(exclude_none=True),
91 "num_tokens": self.num_tokens,
92 "metadata": self.metadata,
93 "created_timestamp": self.created_timestamp,
94 "updated_timestamp": self.updated_timestamp,
95 }
96
97 @staticmethod
98 def object_name() -> str:
99 return "message"
100
101 @staticmethod
102 def object_plural_name() -> str:
103 return "messages"
104
105 @staticmethod
106 def table_name() -> str:
107 return "message"
108
109 @staticmethod
110 def id_field_name() -> str:
111 return "message_id"
112

Callers 1

buildMethod · 0.85

Calls 4

id_fieldFunction · 0.85
metadata_fieldFunction · 0.85
created_timestamp_fieldFunction · 0.85
updated_timestamp_fieldFunction · 0.85

Tested by

no test coverage detected