From 716e3fe58adee5b8a6bfa91de4b3ba6cf204d172 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Wed, 29 May 2024 00:53:39 +0200 Subject: Wip memory --- rag/generator/cohere.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'rag/generator/cohere.py') diff --git a/rag/generator/cohere.py b/rag/generator/cohere.py index 28a87e7..fb0cc5b 100644 --- a/rag/generator/cohere.py +++ b/rag/generator/cohere.py @@ -1,6 +1,6 @@ import os from dataclasses import asdict -from typing import Any, Generator +from typing import Any, Dict, Generator, List, Optional import cohere from loguru import logger as log @@ -13,12 +13,15 @@ class Cohere(metaclass=AbstractGenerator): def __init__(self) -> None: self.client = cohere.Client(os.environ["COHERE_API_KEY"]) - def generate(self, prompt: Prompt) -> Generator[Any, Any, Any]: + def generate( + self, prompt: Prompt, history: Optional[List[Dict[str, str]]] + ) -> Generator[Any, Any, Any]: log.debug("Generating answer from cohere...") query = f"{prompt.query}\n\n{ANSWER_INSTRUCTION}" for event in self.client.chat_stream( message=query, documents=[asdict(d) for d in prompt.documents], + chat_history=history, prompt_truncation="AUTO", ): if event.event_type == "text-generation": -- cgit v1.2.3-70-g09d2