DSPy: The framework for programming—not prompting—language models
Python
Whoops, fix bugs -- now I understand `stop_sequences` in `request`
Connor Shorten63540a03f9b2
diff --git a/dsp/modules/cohere.py b/dsp/modules/cohere.pyindex 407229162..a6e5289d4 100644--- a/dsp/modules/cohere.py+++ b/dsp/modules/cohere.py@@ -7,7 +7,7 @@ from dsp.modules.lm import LMtry:import cohere- cohere_api_error = cohere.core.api_error.ApiError+ cohere_api_error = cohere.errors.UnauthorizedErrorexcept ImportError:cohere_api_error = Exception# print("Not loading Cohere because it is not installed.")@@ -64,12 +64,9 @@ class Cohere(LM):"temperature": 0.0,"max_tokens": 150,"p": 1,- "frequency_penalty": 0,- "presence_penalty": 0,- "num_generations": 1,- "stop_sequences": stop_sequences**kwargs,}+ self.stop_sequences = stop_sequencesself.max_num_generations = 5self.history: list[dict[str, Any]] = []@@ -78,6 +75,7 @@ class Cohere(LM):raw_kwargs = kwargskwargs = {**self.kwargs,+ "stop_sequences": self.stop_sequences,"chat_history": [],"message": prompt,**kwargs,@@ -118,5 +116,5 @@ class Cohere(LM):if dsp.settings.log_coherelm_usage:self.log_usage(response)'''-+return response.textdiff --git a/playground.py b/playground.pynew file mode 100644index 000000000..36f9ad63e--- /dev/null+++ b/playground.py@@ -0,0 +1,25 @@+from dsp.modules.cohere import Cohere++api_key = "RShnIWkqv26t01ZBVRkVj4TbGh4qyyy1N6ehCYuq"+model = "command-r"++# Initialize the Cohere class+cohere = Cohere(model=model, api_key=api_key)++# Test the __call__ method+prompt = "What is the capital of France?"+response = cohere(prompt)++print("Prompt:")+print(prompt)+print("\nResponse:")+print(response)++# Test the request method directly+prompt = "What is the largest planet in our solar system?"+response = cohere.request(prompt)++print("\nPrompt:")+print(prompt)+print("\nResponse:")+print(response.text)\ No newline at end of file