Skip to content

Commit

Permalink
Neel/o1 imagefix (#75)
Browse files Browse the repository at this point in the history
Adding query images and developer message to o1

---------

Co-authored-by: neel <[email protected]>
  • Loading branch information
neelsj and neel authored Jan 17, 2025
1 parent c62dac5 commit 74da19b
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions eureka_ml_insights/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,19 +491,31 @@ def __post_init__(self):
class OpenAIO1RequestResponseMixIn:

def create_request(self, prompt, query_images=None, system_message=None, previous_messages=None):
if system_message:
# system messages are not supported for OAI reasoning models
# https://platform.openai.com/docs/guides/reasoning
logging.warning("System messages are not supported for OAI reasoning models.")

if query_images and self.model_name == "o1-preview":
logging.warning("Images are not supported by OpenAI O1 preview model.")

messages = []
if system_message:
# Developer messages are the new system messages:
# Starting with o1-2024-12-17, o1 models support developer messages rather than system messages,
# to align with the chain of command behavior described in the model spec.
messages.append({"role": "developer", "content": system_message})
if previous_messages:
messages.extend(previous_messages)

user_content = prompt
if query_images and self.model_name == "o1-preview":
logging.warning("Images are not supported by OpenAI O1 preview model.")
elif query_images:
encoded_images = self.base64encode(query_images)
user_content = [
{"type": "text", "text": prompt},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{encoded_images[0]}",
},
},
]

messages.append({"role": "user", "content": prompt})
messages.append({"role": "user", "content": user_content})
return {"messages": messages}

def get_response(self, request):
Expand Down

0 comments on commit 74da19b

Please sign in to comment.