DSPy: The framework for programming—not prompting—language models
Python
Fixed Claude
Thomas D Ahle6ba9600e1c73
diff --git a/dsp/modules/lm.py b/dsp/modules/lm.pyindex 5fbf5ec5e..bcb6c3791 100644--- a/dsp/modules/lm.py+++ b/dsp/modules/lm.py@@ -33,7 +33,8 @@ class LM(ABC):def inspect_history(self, n: int = 1, skip: int = 0):"""Prints the last n prompts and their completions.- TODO: print the valid choice that contains filled output field instead of the first++ TODO: print the valid choice that contains filled output field instead of the first."""provider: str = self.provider@@ -45,23 +46,15 @@ class LM(ABC):prompt = x["prompt"]if prompt != last_prompt:-- if provider == "clarifai" or provider == "google" or provider == "claude":- printed.append(- (- prompt,- x['response'],- ),- )+ if provider == "clarifai" or provider == "google":+ printed.append((prompt, x["response"]))+ elif provider == "anthropic":+ blocks = [{"text": block.text} for block in x["response"].content if block.type == "text"]+ printed.append((prompt, blocks))+ elif provider == "cohere":+ printed.append((prompt, x["response"].generations))else:- printed.append(- (- prompt,- x["response"].generations- if provider == "cohere"- else x["response"]["choices"],- ),- )+ printed.append((prompt, x["response"]["choices"]))last_prompt = prompt@@ -79,9 +72,9 @@ class LM(ABC):if provider == "cohere":text = choices[0].textelif provider == "openai" or provider == "ollama":- text = ' ' + self._get_choice_text(choices[0]).strip()- elif provider == "clarifai" or provider == "claude" :- text=choices+ text = " " + self._get_choice_text(choices[0]).strip()+ elif provider == "clarifai":+ text = choiceselif provider == "google":text = choices[0].parts[0].textelse:@@ -99,6 +92,6 @@ class LM(ABC):def copy(self, **kwargs):"""Returns a copy of the language model with the same parameters."""kwargs = {**self.kwargs, **kwargs}- model = kwargs.pop('model')+ model = kwargs.pop("model")return self.__class__(model=model, **kwargs)