Skip to content

Commit

Permalink
o3-mini and reasoning_effort option, refs #728
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 31, 2025
1 parent 656d8fa commit eb0e1e7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/openai-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ OpenAI Chat: o1
OpenAI Chat: o1-2024-12-17
OpenAI Chat: o1-preview
OpenAI Chat: o1-mini
OpenAI Chat: o3-mini
OpenAI Completion: gpt-3.5-turbo-instruct (aliases: 3.5-instruct, chatgpt-instruct)
```
<!-- [[[end]]] -->
Expand Down
14 changes: 14 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ OpenAI Chat: o1
logit_bias: dict, str
seed: int
json_object: boolean
reasoning_effort: str
Attachment types:
image/gif, image/jpeg, image/png, image/webp
OpenAI Chat: o1-2024-12-17
Expand All @@ -497,6 +498,7 @@ OpenAI Chat: o1-2024-12-17
logit_bias: dict, str
seed: int
json_object: boolean
reasoning_effort: str
Attachment types:
image/gif, image/jpeg, image/png, image/webp
OpenAI Chat: o1-preview
Expand All @@ -521,6 +523,18 @@ OpenAI Chat: o1-mini
logit_bias: dict, str
seed: int
json_object: boolean
OpenAI Chat: o3-mini
Options:
temperature: float
max_tokens: int
top_p: float
frequency_penalty: float
presence_penalty: float
stop: str
logit_bias: dict, str
seed: int
json_object: boolean
reasoning_effort: str
OpenAI Completion: gpt-3.5-turbo-instruct (aliases: 3.5-instruct, chatgpt-instruct)
Options:
temperature: float
Expand Down
4 changes: 2 additions & 2 deletions llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,9 +1139,9 @@ def models_list(options, async_, query):
any_of = [{"type": field["type"]}]
types = ", ".join(
[
_type_lookup.get(item["type"], item["type"])
_type_lookup.get(item.get("type"), item.get("type", "str"))
for item in any_of
if item["type"] != "null"
if item.get("type") != "null"
]
)
bits = ["\n ", name, ": ", types]
Expand Down
34 changes: 32 additions & 2 deletions llm/default_plugins/openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
import click
import datetime
from enum import Enum
import httpx
import openai
import os
Expand Down Expand Up @@ -71,8 +72,8 @@ def register_models(register):
# o1
for model_id in ("o1", "o1-2024-12-17"):
register(
Chat(model_id, vision=True, can_stream=False),
AsyncChat(model_id, vision=True, can_stream=False),
Chat(model_id, vision=True, can_stream=False, reasoning=True),
AsyncChat(model_id, vision=True, can_stream=False, reasoning=True),
)

register(
Expand All @@ -83,6 +84,10 @@ def register_models(register):
Chat("o1-mini", allows_system_prompt=False),
AsyncChat("o1-mini", allows_system_prompt=False),
)
register(
Chat("o3-mini", reasoning=True),
AsyncChat("o3-mini", reasoning=True),
)
# The -instruct completion model
register(
Completion("gpt-3.5-turbo-instruct", default_max_tokens=256),
Expand Down Expand Up @@ -322,6 +327,27 @@ def validate_logit_bias(cls, logit_bias):
return validated_logit_bias


class ReasoningEffortEnum(str, Enum):
low = "low"
medium = "medium"
high = "high"


class OptionsForReasoning(SharedOptions):
json_object: Optional[bool] = Field(
description="Output a valid JSON object {...}. Prompt must mention JSON.",
default=None,
)
reasoning_effort: Optional[ReasoningEffortEnum] = Field(
description=(
"Constraints effort on reasoning for reasoning models. Currently supported "
"values are low, medium, and high. Reducing reasoning effort can result in "
"faster responses and fewer tokens used on reasoning in a response."
),
default=None,
)


def _attachment(attachment):
url = attachment.url
base64_content = ""
Expand Down Expand Up @@ -355,6 +381,7 @@ def __init__(
can_stream=True,
vision=False,
audio=False,
reasoning=False,
allows_system_prompt=True,
):
self.model_id = model_id
Expand All @@ -371,6 +398,9 @@ def __init__(

self.attachment_types = set()

if reasoning:
self.Options = OptionsForReasoning

if vision:
self.attachment_types.update(
{
Expand Down

0 comments on commit eb0e1e7

Please sign in to comment.