Get the conversation history.
(self, similar: int, recent: int, prompt: str)
| 321 | self.output_tokens += 3 |
| 322 | |
| 323 | def get_history(self, similar: int, recent: int, prompt: str): |
| 324 | """ |
| 325 | Get the conversation history. |
| 326 | """ |
| 327 | history = self.history[-recent:] if recent > 0 else [] |
| 328 | if similar > 0: |
| 329 | embedding = get_text_embedding(prompt, self.text_model) |
| 330 | history.sort(key=lambda x: cosine_similarity(embedding, x.embedding)) |
| 331 | for turn in history: |
| 332 | if len(history) > similar + recent: |
| 333 | break |
| 334 | if turn not in history: |
| 335 | history.append(turn) |
| 336 | history.sort(key=lambda x: x.id) |
| 337 | return history |
| 338 | |
| 339 | def save_history(self, output_dir: str): |
| 340 | """ |
no test coverage detected