(
self,
prompt: str,
*,
system: Optional[str] = None,
temperature: float = 0.0,
max_tokens: int = 1024,
)
| 201 | self._client = Anthropic(api_key=api_key, base_url=base_url, timeout=timeout) |
| 202 | |
| 203 | def generate( |
| 204 | self, |
| 205 | prompt: str, |
| 206 | *, |
| 207 | system: Optional[str] = None, |
| 208 | temperature: float = 0.0, |
| 209 | max_tokens: int = 1024, |
| 210 | ) -> LLMResponse: |
| 211 | kwargs = { |
| 212 | "model": self.model, |
| 213 | "max_tokens": max_tokens, |
| 214 | "temperature": temperature, |
| 215 | "messages": [{"role": "user", "content": prompt}], |
| 216 | } |
| 217 | if system: |
| 218 | kwargs["system"] = system |
| 219 | |
| 220 | response = self._client.messages.create(**kwargs) |
| 221 | text = "".join( |
| 222 | block.text # type: ignore[attr-defined] |
| 223 | for block in response.content |
| 224 | if getattr(block, "type", None) == "text" |
| 225 | ) |
| 226 | return LLMResponse( |
| 227 | text=text, |
| 228 | model=self.model, |
| 229 | provider=self.name, |
| 230 | prompt_tokens=getattr(response.usage, "input_tokens", 0) or 0, |
| 231 | completion_tokens=getattr(response.usage, "output_tokens", 0) or 0, |
| 232 | ) |
| 233 | |
| 234 | def stream_generate( |
| 235 | self, |
nothing calls this directly
no test coverage detected