Generate experiences from a list of history chat messages in async.
(self, messages: List[dict], **kwargs)
| 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.""" |
nothing calls this directly
no test coverage detected