From 2cb47938fd387144c79caaa072f98c8d1938d616 Mon Sep 17 00:00:00 2001 From: cachho Date: Tue, 12 Sep 2023 05:58:42 +0200 Subject: [PATCH] fix: llama2 - use config with specific defaults (#594) --- embedchain/llm/llama2.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/embedchain/llm/llama2.py b/embedchain/llm/llama2.py index 68958589..f59a0b1e 100644 --- a/embedchain/llm/llama2.py +++ b/embedchain/llm/llama2.py @@ -13,6 +13,19 @@ class Llama2Llm(BaseLlm): def __init__(self, config: Optional[BaseLlmConfig] = None): if "REPLICATE_API_TOKEN" not in os.environ: raise ValueError("Please set the REPLICATE_API_TOKEN environment variable.") + + # Set default config values specific to this llm + if not config: + config = BaseLlmConfig() + # Add variables to this block that have a default value in the parent class + config.max_tokens = 500 + config.temperature = 0.75 + # Add variables that are `none` by default to this block. + if not config.model: + config.model = ( + "a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5" + ) + super().__init__(config=config) def get_llm_model_answer(self, prompt): @@ -20,7 +33,11 @@ class Llama2Llm(BaseLlm): if self.config.system_prompt: raise ValueError("Llama2App does not support `system_prompt`") llm = Replicate( - model="a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5", - input={"temperature": self.config.temperature or 0.75, "max_length": 500, "top_p": self.config.top_p}, + model=self.config.model, + input={ + "temperature": self.config.temperature, + "max_length": self.config.max_tokens, + "top_p": self.config.top_p, + }, ) return llm(prompt)