MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / chat

Method chat

trinity/common/models/tinker_model.py:123–138  ·  view source on GitHub ↗

Generate experiences from a list of history chat messages in async.

(self, messages: List[dict], **kwargs)

Source from the content-addressed store, hash-verified

121 return experiences
122
123 async def chat(self, messages: List[dict], **kwargs) -> Sequence[Experience]:
124 """Generate experiences from a list of history chat messages in async."""
125 if self.tokenizer is None:
126 await self._initialize_tokenizer()
127
128 # TODO: this is a hack to support openai chat messages, which only supports text
129 for msg in messages:
130 if isinstance(msg["content"], list):
131 text_parts = [item["text"] for item in msg["content"] if item["type"] == "text"]
132 content_str = "".join(text_parts)
133 else:
134 content_str = msg["content"]
135 msg["content"] = content_str
136
137 prompt = self.apply_chat_template(self.tokenizer, messages)
138 return await self.generate(prompt=prompt, **kwargs)
139
140 async def logprobs(self, token_ids: List[int], **kwargs) -> Tensor:
141 """Generate logprobs for a list of tokens in async."""

Callers

nothing calls this directly

Calls 3

_initialize_tokenizerMethod · 0.95
generateMethod · 0.95
apply_chat_templateMethod · 0.80

Tested by

no test coverage detected