-
Notifications
You must be signed in to change notification settings - Fork 7
[READY FOR REVIEW] Modernize Optimas Project Structure, GEPA Integration, and Tooling #3
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
base: main
Are you sure you want to change the base?
Conversation
|
@Wuyxin Feel free to add relevant reviewers to the PR. |
|
@Wuyxin I have fully tested this PR locally and documented my observations in the |
parthsarthi03
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I've left a few comments, I think majorly looks good, I will test it post the fixes. The ollama integration, might be suited for another PR, I don't believe it is required for GEPA.
| if error: | ||
| return "Task failed with error - agent needs better error handling or clearer instructions" | ||
|
|
||
| if score >= 0.8: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: are these numbers from the GEPA paper? can we avoid magic numbers if possible, many magic numbers repeated below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are conventional performance ML evaluation bands? like grades?
We can use more advanced threshold based approached but I think this is good enough for now? It's like grades in schools. They are not coming from GEPA paper .. I think we should be good for basis GEPA performance assessment?
resources/demos/ollama_local_demo.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary for the GEPA implementation, if not can we move this to a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything in the resource is basically testing and demo purpose so that contributors can feel confident that nothing broken and all the changes works as expected by running these basic demos and tests. Also included some guides. GEPA with Ollama is good ideas for anyone trying it first time as one of the hurdle while running GEPA optimization on the cloud based models is cost. Using cloud models like GPT5 Claude etc can be very expensive so Ollama integration script allow users to test the GEPA integration quickly and feel how GEPA works without worrying about the cost. Implementation is already there its just example/demo how to use GEPA with Ollama .. I can remove it but good for information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parthsarthi03 I am happy to remove the entire resources directory as I added to show demos works and no existing features broken because of this PR .. We can cover that somewhere later as part of the documentation site somehow? What you think? Let me know and I will remove entire directory and keep the features related code in the repo ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed entire resources now as we can update the demos and guides in the documentation instead of the repo.
| ) | ||
|
|
||
| def _create_default_metric(self, component: BaseComponent) -> callable: | ||
| """Create a default metric function for the component.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of the metric in the optimization process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically something better than nothing. GEPA needs optimizers to be defined and advanced users should define their own metric but we are including basic default exact_match and letting user know that they are main default metric and define your own .. This allows GEPA optimization gets going for starters ..
|
Thanks @parthsarthi03 for reviewing the PR. I have updated the PR as per your suggestion and left some comments for clarification .. Let me know what you think and needs further improvements .. |
|
Thanks @Shashikant86, I'll review and run the tests this weekend, and if all looks good, we'll merge it early next week! Thanks for the effort! |
|
@parthsarthi03 Just revisiting this, wondering if you have done testing on this or need more time? |
Hey @Shashikant86, apologies for the delay, will try and get it merged this week! |
parthsarthi03
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Shashikant86, sorry for the delay, can we just update the readme once to remove the outdated links and add information on how to run with gepa, i.e. change the configs etc? Thanks!
README.md
Outdated
| python examples/universal_gepa_demo.py --quick-test | ||
| ``` | ||
|
|
||
| ### Using Local Models with Ollama |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove this from the readme for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will tidy this up
README.md
Outdated
| python resources/testing/test_gepa_local.py --model llama3.1:8b | ||
| ``` | ||
|
|
||
| 📖 **See [LOCAL_TESTING_GUIDE.md](resources/guides/LOCAL_TESTING_GUIDE.md) for comprehensive testing instructions and troubleshooting.** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think this link exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire resource directory has been removed as part of earlier commit to keep the code and documentation separate
README.md
Outdated
| python -c "from optimas.arch.system import CompoundAISystem; print('✅ Optimas ready!')" | ||
|
|
||
| # Run GEPA integration demo | ||
| python examples/universal_gepa_demo.py --quick-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples/universal_gepa_demo.py also doesnt exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That has been removed from earlier feedback to keep only implementation in the repo and take out everything. I will fix it later with adding bette example
|
I need to keep it simple and tidy just one example and minimal update in the REAMME. I tested all examples GEPA config again but I will revisit and simplify this in few days time. |
|
@parthsarthi03 I have kept README.md minimal and moved some demo and GUIDE in the |
|
|
||
| ```bash | ||
| # Quick demo with local models | ||
| ollama pull llama3.1:8b && ollama pull qwen3:8b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ollama strictly required for GEPA? If not can we use api based models? (trying to avoid extra dependencies, if there is some reason it is recommended/needed, we can also add it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current implementation will work for both cloud based and local models. Ollama is just for executing the examples locally, GEPA will work with both local and cloud based morels if configured accordingly. We are not adding adding any dependency to the project self but its way if someone try to run the GEPA optimizaton on local machine using those examples. It's just easier and cheap way to run GEPA optimization without burning cloud model credits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use litellm in optimas.utils which handles ollama, can we change this to use the existing get_llm_output function.
|
Whats up Guys, Are you planning to planning to maintain the project or too busy with studies and academia? |
parthsarthi03
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shashikant86 Thank you so much again for your contributions and my sincerest apologies for the delay!
This pr is mostly good to go, except I think removing separate request call to ollama and openai, we already support this functionality in optimas in get_llm_output function which use litellm and handles ollama.
Apart from that, we'd be really interested to know if you had run any experiments and compared gepa with optimas and seen better performance than the optimizers we support.
Again, thank you so much for contributing and I will work on getting this merged asap!
|
|
||
| ## 🚀 GEPA Integration | ||
|
|
||
| Optimas includes GEPA (Generate, Evaluate, Predict, and Adapt) for automatic prompt optimization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not the GEPA full form
| ```python | ||
| import openai | ||
|
|
||
| def openai_reflection_lm(prompt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use get_llm_output from optimas.utils.api import get_llm_output instead of separetly using openai calls
| ```python | ||
| import requests | ||
|
|
||
| def ollama_reflection_lm(prompt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets change it use the existing get_llm_output function which supports ollama
|
|
||
| ```bash | ||
| # Quick demo with local models | ||
| ollama pull llama3.1:8b && ollama pull qwen3:8b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use litellm in optimas.utils which handles ollama, can we change this to use the existing get_llm_output function.
| """Create reflection model using qwen3:8b""" | ||
| def reflection_lm(prompt: str) -> str: | ||
| try: | ||
| response = requests.post( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above, lets use get_llm_output from optimas.utils.api, for cleaner code and consistency
| print("=" * 40) | ||
|
|
||
| # Check Ollama | ||
| print("Checking Ollama...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the existing get_llm_output function which supports ollama
| def __call__(self, prompt, **kwargs): | ||
| try: | ||
| response = requests.post( | ||
| "http://localhost:11434/api/generate", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above, lets use functions from optimas.utils.api, for cleaner code and consistency
| prompt = f"{self.variable}\n\nQuestion: {question}\nAnswer:" | ||
|
|
||
| try: | ||
| response = requests.post( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use function from optimas.utils.api, for cleaner code and consistency
| """Create reflection model using qwen3:8b""" | ||
| def reflection_lm(prompt: str) -> str: | ||
| try: | ||
| response = requests.post( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use function from optimas.utils.api, for cleaner code and consistency
Summary
FULLY TESTED : Not affecting current features.
This PR brings Optimas up to modern open-source Python standards, add GEPA optimizer integration, and enhances developer/contributor experience. DSPy has released 3.0.1 with some hot fixes in the GEPA so accommodating that as well.
Key Changes
1. Project Structure & Packaging
pyproject.toml(PEP 621) for build, metadata, and dependency management. Please update the emails of the group or original authors in the file the email is very generic now..gitignoreto a standard Python template (ignores OS/editor files, build/test artifacts, etc.).requirements.txtand generateduv.lockfor reproducible installs.2. Linting, Formatting, and CI
.pre-commit-config.yamlwith ruff (temporarily set to--ignore=ALLto not block on existing errors)..github/workflows/ci.yml) to:uv(or pip fallback)--ignore=ALL), there are many errors we can fix later3. Documentation & Community
CONTRIBUTING.mdwith clear instructions for usinguv, pip, and pre-commit.CHANGELOG.md(Keep a Changelog format).docs/gepa_adapter.mdfor using GEPA in Optimas, including custom adapter and logging instructions.README.mdwith advanced GEPA usage and logging config examples.4. GEPA Optimizer Integration
optimas/optim/args.pyandcp_optimizer.pyto:5. Testing
tests/test_gepa_optimizer.py:max_metric_callsfor GEPA budget (per latest API).How to Use
uv pip install .[dev](recommended) or pip.pytest.CONTRIBUTING.mdfor full dev setup anddocs/gepa_adapter.mdfor GEPA usage.Things to note
--ignore=ALL).If team is new to modern Python tooling like uv ruff, I am happy to add more docs and guides as needed.