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

OpenAI o1 support #347

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

OpenAI o1 support #347

wants to merge 17 commits into from

Conversation

Hk669
Copy link
Collaborator

@Hk669 Hk669 commented Jan 3, 2025

Why are these changes needed?

the o1 preview and o1 series models doesnt support the same API parameters (Limitations) as the other openai models, so added a helper function in the OpenAIClient that tackles this issue and can be run in the agentic workflow.

tested with the two agent run (with o1-preview) with a question from simple-bench, and it runs perfectly on my side.

Related issue number

Checks

@marklysze
Copy link
Collaborator

I'd like to propose adding documentation regarding o1 separately when we do the documentation updates. I think a table showing supported features and models/clients would be beneficial.

@marklysze
Copy link
Collaborator

Outstanding, if we can put documentation in a separate PR, is testing this with o1. If that's a dependency then we'll need to get that tested first.

Here's sample code to run against this branch to test o1:

altmodel_llm_config = {
    # o1 full model
    "config_list": [
        {
            "api_type": "openai",
            "model": "o1-2024-12-17",
            "max_tokens": 8192,
            "cache_seed": None,
        }
    ]
}

altmodel_llm_config_other = {
    # Leave this as 4o-mini
    "config_list": [{"api_type": "openai", "model": "gpt-4o-mini", "stream": False, "cache_seed": None}]
}

from autogen import (
    AFTER_WORK,
    AfterWorkOption,
    SwarmAgent,
    SwarmResult,
    initiate_swarm_chat,
)


def must_call_me() -> SwarmResult:
    """A must call function, absolutely call it."""
    return SwarmResult(values="This must call me function ran.", agent=emma)


jack = SwarmAgent(
    "Jack",
    llm_config=altmodel_llm_config,
    system_message="List the steps required to solve this.",
    is_termination_msg=lambda x: True if "FINISH" in x["content"] else False,
)
emma = SwarmAgent(
    "Emma",
    llm_config=altmodel_llm_config_other,
    system_message="Use the steps to answer the question.",
    is_termination_msg=lambda x: True if "FINISH" in x["content"] else False,
)

jack.register_hand_off([AFTER_WORK(emma)])
emma.register_hand_off(AFTER_WORK(AfterWorkOption.TERMINATE))

result, messages, last_agent = initiate_swarm_chat(
    initial_agent=jack,
    agents=[jack, emma],
    messages=[
        "Peter needs CPR from his best friend Paul, the only person around. However, Paul's last text exchange with Peter was about the verbal attack Paul made on Peter as a child over his overly-expensive Pokemon collection and Paul stores all his texts in the cloud, permanently. Paul will [ _ ] help Peter.\nA. probably not\nB. definitely\nC. half-heartedly\nD. not\nE. pretend to\nF. ponder deeply over whether to"
    ],
    after_work=AFTER_WORK(AfterWorkOption.TERMINATE),
)

@Hk669
Copy link
Collaborator Author

Hk669 commented Jan 6, 2025

LGTM. thanks @marklysze

test/oai/test_client.py Outdated Show resolved Hide resolved
test/oai/test_client.py Outdated Show resolved Hide resolved
test/oai/test_client.py Outdated Show resolved Hide resolved
test/oai/test_client.py Outdated Show resolved Hide resolved
test/oai/test_client.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: o1 support for AG2
3 participants