Skip to content

Commit d836fd8

Browse files
Remove hardcoded model list from OpenAIProvider file (#8649)
* update openai model list * remove hardcoded list * increment * revert unexpected formatting * style --------- Co-authored-by: Zach Parent <[email protected]>
1 parent 5268d3d commit d836fd8

File tree

2 files changed

+9
-63
lines changed

2 files changed

+9
-63
lines changed

dspy/clients/lm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,12 @@ def finetune(
188188
) -> TrainingJob:
189189
from dspy import settings as settings
190190

191-
err = f"Provider {self.provider} does not support fine-tuning."
192-
assert self.provider.finetunable, err
191+
if not self.provider.finetunable:
192+
raise ValueError(
193+
f"Provider {self.provider} does not support fine-tuning, please specify your provider by explicitly "
194+
"setting `provider` when creating the `dspy.LM` instance. For example, "
195+
"`dspy.LM('openai/gpt-4.1-mini-2025-04-14', provider=dspy.OpenAIProvider())`."
196+
)
193197

194198
def thread_function_wrapper():
195199
return self._run_finetune_job(job)

dspy/clients/openai.py

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
import time
32
from datetime import datetime
43
from typing import Any
@@ -8,48 +7,6 @@
87
from dspy.clients.provider import Provider, TrainingJob
98
from dspy.clients.utils_finetune import TrainDataFormat, TrainingStatus, save_data
109

11-
_OPENAI_MODELS = [
12-
"gpt-4-turbo",
13-
"gpt-4-turbo-2024-04-09",
14-
"tts-1",
15-
"tts-1-1106",
16-
"chatgpt-4o-latest",
17-
"dall-e-2",
18-
"whisper-1",
19-
"gpt-3.5-turbo-instruct",
20-
"gpt-3.5-turbo",
21-
"gpt-3.5-turbo-0125",
22-
"babbage-002",
23-
"davinci-002",
24-
"gpt-4o-mini-2024-07-18",
25-
"gpt-4o",
26-
"dall-e-3",
27-
"gpt-4o-mini",
28-
"gpt-4o-2024-08-06",
29-
"gpt-4o-2024-05-13",
30-
"o1-preview",
31-
"gpt-4o-audio-preview-2024-10-01",
32-
"o1-mini-2024-09-12",
33-
"gpt-4o-audio-preview",
34-
"tts-1-hd",
35-
"tts-1-hd-1106",
36-
"o1-preview-2024-09-12",
37-
"o1-mini",
38-
"gpt-4-1106-preview",
39-
"text-embedding-ada-002",
40-
"gpt-3.5-turbo-16k",
41-
"text-embedding-3-small",
42-
"text-embedding-3-large",
43-
"gpt-4o-realtime-preview-2024-10-01",
44-
"gpt-4o-realtime-preview",
45-
"gpt-3.5-turbo-1106",
46-
"gpt-4-0613",
47-
"gpt-4-turbo-preview",
48-
"gpt-4-0125-preview",
49-
"gpt-4",
50-
"gpt-3.5-turbo-instruct-0914",
51-
]
52-
5310

5411
class TrainingJobOpenAI(TrainingJob):
5512
def __init__(self, *args, **kwargs):
@@ -90,24 +47,9 @@ def __init__(self):
9047

9148
@staticmethod
9249
def is_provider_model(model: str) -> bool:
93-
model = OpenAIProvider._remove_provider_prefix(model)
94-
95-
# Check if the model is a base OpenAI model
96-
# TODO(enhance) The following list can be replaced with
97-
# openai.models.list(), but doing so might require a key. Is there a
98-
# way to get the list of models without a key?
99-
if model in _OPENAI_MODELS:
100-
return True
101-
102-
# Check if the model is a fine-tuned OpenAI model. Fine-tuned OpenAI
103-
# models have the prefix "ft:<BASE_MODEL_NAME>:", followed by a string
104-
# specifying the fine-tuned model. The following RegEx pattern is used
105-
# to match the base model name.
106-
# TODO(enhance): This part can be updated to match the actual fine-tuned
107-
# model names by making a call to the OpenAI API to be more exact, but
108-
# this might require an API key with the right permissions.
109-
match = re.match(r"ft:([^:]+):", model)
110-
if match and match.group(1) in _OPENAI_MODELS:
50+
if model.startswith("openai/") or model.startswith("ft:"):
51+
# Althought it looks strange, `ft:` is a unique identifer for openai finetuned models in litellm context:
52+
# https://github.com/BerriAI/litellm/blob/cd893134b7974d9f21477049a373b469fff747a5/litellm/utils.py#L4495
11153
return True
11254

11355
return False

0 commit comments

Comments
 (0)