Skip to content

Commit 64f7303

Browse files
committed
Support system messages for o1 models
o1 uses the "developer" role on system messages. Internally set this role before sending.
1 parent 249f511 commit 64f7303

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/gptcmd/llm/openai.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
file, You can obtain one at https://mozilla.org/MPL/2.0/.
77
"""
88

9-
109
import inspect
1110

1211
from decimal import Decimal
@@ -48,7 +47,14 @@ def from_config(cls, conf: Dict):
4847
return cls(client, model=model)
4948

5049
def _message_to_openai(self, msg: Message) -> Dict[str, Any]:
51-
res = {"role": msg.role}
50+
res = {
51+
"role": (
52+
"developer"
53+
if self.model.startswith("o1")
54+
and msg.role == MessageRole.SYSTEM
55+
else msg.role
56+
)
57+
}
5258
if msg.name:
5359
res["name"] = msg.name
5460
if msg.attachments:

0 commit comments

Comments
 (0)