KEMBAR78
Add Llama API OAI compatible endpoint support by WuhanMonkey · Pull Request #6442 · microsoft/autogen · GitHub
Skip to content

Conversation

@WuhanMonkey
Copy link
Contributor

Why are these changes needed?

To add the latest support for using Llama API offerings with AutoGen

Checks

@WuhanMonkey WuhanMonkey marked this pull request as draft April 30, 2025 16:01
@WuhanMonkey WuhanMonkey marked this pull request as ready for review April 30, 2025 16:28
@SongChiYoung
Copy link
Contributor

SongChiYoung commented Apr 30, 2025

Llama support is cool!
could you adding register_transformer at _message_transfrom to?
https://github.com/microsoft/autogen/blob/main/python/packages/autogen-ext/src/autogen_ext/models/openai/_message_transform.py

You could start with __BASE_TRANSFORMER_MAP
or build __LLAMA_TRANSFROMER_MAP same as __BASE_TRANSFORMER_MAP for future modified.

# === Transformers ===
__BASE_TRANSFORMER_MAP: TransformerMap = {
SystemMessage: build_transformer_func(
funcs=system_message_transformers,
message_param_func=ChatCompletionSystemMessageParam,
),
UserMessage: build_conditional_transformer_func(
funcs_map=user_transformer_funcs,
message_param_func_map=user_transformer_constructors,
condition_func=user_condition,
),
AssistantMessage: build_conditional_transformer_func(
funcs_map=assistant_transformer_funcs,
message_param_func_map=assistant_transformer_constructors,
condition_func=assistant_condition,
),
FunctionExecutionResultMessage: function_execution_result_message,
}

and...

# set openai models to use the transformer map
total_models = get_args(ModelFamily.ANY)
__openai_models = [model for model in total_models if ModelFamily.is_openai(model)]
__claude_models = [model for model in total_models if ModelFamily.is_claude(model)]
__gemini_models = [model for model in total_models if ModelFamily.is_gemini(model)]
__unknown_models = list(set(total_models) - set(__openai_models) - set(__claude_models) - set(__gemini_models))
for model in __openai_models:
register_transformer("openai", model, __BASE_TRANSFORMER_MAP)
for model in __claude_models:
register_transformer("openai", model, __CLAUDE_TRANSFORMER_MAP)
for model in __gemini_models:
register_transformer("openai", model, __GEMINI_TRANSFORMER_MAP)
for model in __unknown_models:
register_transformer("openai", model, __BASE_TRANSFORMER_MAP)
register_transformer("openai", "default", __BASE_TRANSFORMER_MAP)


I think you are expert of Llama. If you know about Llama's message limited, could support more well with _message_transfrom.

In Anthropic case, Claude does not support empty message, so this message transformer remove empty messages.

Adding links to Llama API website for sign-up
@ekzhu
Copy link
Collaborator

ekzhu commented May 6, 2025

@WuhanMonkey thanks for the PR. Could you address @SongChiYoung 's comments?

Set Llama models to use base message transformer. It is fully compatible with OAI
@WuhanMonkey
Copy link
Contributor Author

@WuhanMonkey thanks for the PR. Could you address @SongChiYoung 's comments?

Hey yes, just updated it.

We are still pending on CLA review from our legal side.

@WuhanMonkey
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Meta"

@WuhanMonkey
Copy link
Contributor Author

We finally get the CLA approved and signed. @SongChiYoung and @ekzhu would you mind help me review and approve this PR? Thanks

@WuhanMonkey
Copy link
Contributor Author

One more question, @SongChiYoung, does AutoGen allows extra headers in the request for customized x-title or http-referer for tracking purpose?

@ekzhu
Copy link
Collaborator

ekzhu commented May 15, 2025

One more question, @SongChiYoung, does AutoGen allows extra headers in the request for customized x-title or http-referer for tracking purpose?

You can pass in default_headers as part of the OpenAIChatCompletionClient. https://microsoft.github.io/autogen/stable/reference/python/autogen_ext.models.openai.html#autogen_ext.models.openai.OpenAIChatCompletionClient

Fix issue during rebase.
@codecov
Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.

Project coverage is 79.52%. Comparing base (1eb7f93) to head (5413c51).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...xt/src/autogen_ext/models/openai/_openai_client.py 20.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6442      +/-   ##
==========================================
- Coverage   79.53%   79.52%   -0.01%     
==========================================
  Files         225      225              
  Lines       16644    16661      +17     
==========================================
+ Hits        13237    13249      +12     
- Misses       3407     3412       +5     
Flag Coverage Δ
unittests 79.52% <76.47%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ekzhu
Copy link
Collaborator

ekzhu commented May 15, 2025

@WuhanMonkey I will bring it to finish. Thanks. For local checks you can see python/README.md for guides.

@ekzhu ekzhu merged commit 9d29731 into microsoft:main May 15, 2025
63 of 64 checks passed
@WuhanMonkey
Copy link
Contributor Author

@WuhanMonkey I will bring it to finish. Thanks. For local checks you can see python/README.md for guides.

Thanks appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants