Skip to content

Commit

Permalink
Merge pull request #1279 from Codium-ai/tr/o1_system
Browse files Browse the repository at this point in the history
feat: add support for O1 model by combining system and user prompt
  • Loading branch information
mrT23 authored Oct 9, 2024
2 parents 5d9d48d + e6c56c7 commit 3ac1ddc
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions pr_agent/algo/ai_handlers/litellm_ai_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ async def chat_completion(self, model: str, system: str, user: str, temperature:
get_logger().warning(
"Empty system prompt for claude model. Adding a newline character to prevent OpenAI API error.")
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]

if img_path:
try:
# check if the image link is alive
Expand All @@ -185,14 +186,29 @@ async def chat_completion(self, model: str, system: str, user: str, temperature:
messages[1]["content"] = [{"type": "text", "text": messages[1]["content"]},
{"type": "image_url", "image_url": {"url": img_path}}]

kwargs = {
"model": model,
"deployment_id": deployment_id,
"messages": messages,
"temperature": temperature,
"timeout": get_settings().config.ai_timeout,
"api_base": self.api_base,
}
# Currently O1 does not support separate system and user prompts
O1_MODEL_PREFIX = 'o1-'
if model.startswith(O1_MODEL_PREFIX):
user = f"{system}\n\n\n{user}"
system = ""
get_logger().info(f"Using O1 model, combining system and user prompts")
messages = [{"role": "user", "content": user}]
kwargs = {
"model": model,
"deployment_id": deployment_id,
"messages": messages,
"timeout": get_settings().config.ai_timeout,
"api_base": self.api_base,
}
else:
kwargs = {
"model": model,
"deployment_id": deployment_id,
"messages": messages,
"temperature": temperature,
"timeout": get_settings().config.ai_timeout,
"api_base": self.api_base,
}

if get_settings().litellm.get("enable_callbacks", False):
kwargs = self.add_litellm_callbacks(kwargs)
Expand Down

0 comments on commit 3ac1ddc

Please sign in to comment.