DSPy: The framework for programming—not prompting—language models
Python
Bugfix to Cohere model support
Jayda2b43d2c1a0
diff --git a/dsp/modules/cohere.py b/dsp/modules/cohere.pyindex 876c80086..900d5ee5b 100644--- a/dsp/modules/cohere.py+++ b/dsp/modules/cohere.py@@ -39,6 +39,7 @@ class Cohere(LM):model: str = "command-nightly",api_key: Optional[str] = None,stop_sequences: list[str] = [],+ **kwargs):"""Parameters@@ -51,6 +52,8 @@ class Cohere(LM):It can be obtained from https://dashboard.cohere.ai/register.stop_sequences : list of strAdditional stop tokens to end generation.+ **kwargs: dict+ Additional arguments to pass to the API provider."""super().__init__(model)self.co = cohere.Client(api_key)@@ -64,6 +67,7 @@ class Cohere(LM):"presence_penalty": 0,"num_generations": 1,"return_likelihoods": "GENERATION",+ **kwargs}self.stop_sequences = stop_sequencesself.max_num_generations = 5diff --git a/dspy/__init__.py b/dspy/__init__.pyindex 71aba8b1a..ecc67960b 100644--- a/dspy/__init__.py+++ b/dspy/__init__.py@@ -16,6 +16,7 @@ import dspsettings = dsp.settingsOpenAI = dsp.GPT3+Cohere = dsp.CohereColBERTv2 = dsp.ColBERTv2Pyserini = dsp.PyseriniRetrieverdiff --git a/dspy/predict/predict.py b/dspy/predict/predict.pyindex a24474832..2fc9b15d1 100644--- a/dspy/predict/predict.py+++ b/dspy/predict/predict.py@@ -73,7 +73,8 @@ class Predict(Parameter):temperature = lm.kwargs['temperature'] if temperature is None else temperaturenum_generations = config.get("n", None)- num_generations = lm.kwargs['n'] if num_generations is None else num_generations+ if num_generations is None:+ num_generations = lm.kwargs.get('n', lm.kwargs.get('num_generations', None))if (temperature is None or temperature <= 0.15) and num_generations > 1:config["temperature"] = 0.7