Skip to content

armgit / dspy

Public Imported from GitHub
0

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.py
index 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 str
Additional 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_sequences
self.max_num_generations = 5
diff --git a/dspy/__init__.py b/dspy/__init__.py
index 71aba8b1a..ecc67960b 100644
--- a/dspy/__init__.py
+++ b/dspy/__init__.py
@@ -16,6 +16,7 @@ import dsp
settings = dsp.settings
OpenAI = dsp.GPT3
+Cohere = dsp.Cohere
ColBERTv2 = dsp.ColBERTv2
Pyserini = dsp.PyseriniRetriever
diff --git a/dspy/predict/predict.py b/dspy/predict/predict.py
index 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 temperature
num_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