Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the format model list #21

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions pipeline/gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
import dspy.adapters
import dspy.utils

MODELS_WITH_RESPONSE_FORMAT = [
"ailab-llm",
"ailab-llm-gpt-4o"
] # List of models that support the response_format option
SUPPORTED_MODELS = {
"gpt-3.5-turbo": {
"max_token": 12000,
"api_version": "2024-02-01",
"response_format": { "type": "json_object" },
},
"gpt-4o": {
"max_token": 4096,
"api_version": "2024-02-15-preview",
"response_format": { "type": "json_object" },
}
}

SPECIFICATION = """
Keys:
Expand Down Expand Up @@ -64,27 +72,19 @@ def __init__(self, api_endpoint, api_key, deployment_id):
if not api_endpoint or not api_key or not deployment_id:
raise ValueError("The API endpoint, key and deployment_id are required to instantiate the GPT class.")

response_format = None
if deployment_id in MODELS_WITH_RESPONSE_FORMAT:
response_format = { "type": "json_object" }

max_token = 12000
api_version = "2024-02-01"
if deployment_id == MODELS_WITH_RESPONSE_FORMAT[0]:
max_token = 3500
elif deployment_id == MODELS_WITH_RESPONSE_FORMAT[1]:
max_token = 4096
api_version="2024-02-15-preview"

config = SUPPORTED_MODELS.get(deployment_id)
if not config:
raise ValueError(f"The deployment_id {deployment_id} is not supported.")

self.dspy_client = dspy.AzureOpenAI(
user="fertiscan",
api_base=api_endpoint,
api_key=api_key,
deployment_id=deployment_id,
# model_type='text',
api_version=api_version,
max_tokens=max_token,
response_format=response_format,
api_version=config.get("api_version"),
max_tokens=config.get("max_token"),
response_format=config.get("response_format"),
)

def create_inspection(self, prompt) -> Prediction:
Expand Down
Loading