dspy.LM
dspy.LM(model: str, model_type: Literal['chat', 'text'] = 'chat', temperature: float = 0.0, max_tokens: int = 1000, cache: bool = True, callbacks: Optional[List[BaseCallback]] = None, num_retries: int = 8, provider=None, finetuning_model: Optional[str] = None, launch_kwargs: Optional[dict[str, Any]] = None, **kwargs)
Bases: BaseLM
A language model supporting chat or text completion requests for use with DSPy modules.
Create a new language model instance for use with DSPy modules and programs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The model to use. This should be a string of the form |
required |
model_type
|
Literal['chat', 'text']
|
The type of the model, either |
'chat'
|
temperature
|
float
|
The sampling temperature to use when generating responses. |
0.0
|
max_tokens
|
int
|
The maximum number of tokens to generate per response. |
1000
|
cache
|
bool
|
Whether to cache the model responses for reuse to improve performance and reduce costs. |
True
|
callbacks
|
Optional[List[BaseCallback]]
|
A list of callback functions to run before and after each request. |
None
|
num_retries
|
int
|
The number of times to retry a request if it fails transiently due to network error, rate limiting, etc. Requests are retried with exponential backoff. |
8
|
provider
|
The provider to use. If not specified, the provider will be inferred from the model. |
None
|
|
finetuning_model
|
Optional[str]
|
The model to finetune. In some providers, the models available for finetuning is different from the models available for inference. |
None
|
Source code in dspy/clients/lm.py
Functions
__call__(prompt=None, messages=None, **kwargs)
Source code in dspy/clients/lm.py
copy(**kwargs)
Returns a copy of the language model with possibly updated parameters.