MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / Turn

Class Turn

utils/src/llms.py:230–257  ·  view source on GitHub ↗

A class to represent a turn in a conversation.

Source from the content-addressed store, hash-verified

228
229@dataclass
230class Turn:
231 """
232 A class to represent a turn in a conversation.
233 """
234
235 id: int
236 prompt: str
237 response: str
238 message: list
239 images: list[str] = None
240 input_tokens: int = 0
241 output_tokens: int = 0
242 embedding: Tensor = None
243
244 def to_dict(self):
245 return {k: v for k, v in asdict(self).items() if k != "embedding"}
246
247 def calc_token(self):
248 """
249 Calculate the number of tokens for the turn.
250 """
251 if self.images is not None:
252 self.input_tokens += calc_image_tokens(self.images)
253 self.input_tokens += len(ENCODING.encode(self.prompt))
254 self.output_tokens = len(ENCODING.encode(self.response))
255
256 def __eq__(self, other):
257 return self is other
258
259
260class Role:

Callers 2

retryMethod · 0.70
__call__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected