Skip to content

Conversation

@Shashikant86
Copy link

@Shashikant86 Shashikant86 commented Aug 15, 2025

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

  • Added a modern 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.
  • Updated .gitignore to a standard Python template (ignores OS/editor files, build/test artifacts, etc.).
  • Added requirements.txt and generated uv.lock for reproducible installs.

2. Linting, Formatting, and CI

  • Added .pre-commit-config.yaml with ruff (temporarily set to --ignore=ALL to not block on existing errors).
  • Updated GitHub Actions workflow (.github/workflows/ci.yml) to:
    • Build with uv (or pip fallback)
    • Run ruff (with --ignore=ALL), there are many errors we can fix later
    • No publish/deploy steps yet, we can add them later once we figure out the distribution strategy.

3. Documentation & Community

  • Added CONTRIBUTING.md with clear instructions for using uv, pip, and pre-commit.
  • Added CHANGELOG.md (Keep a Changelog format).
  • Added docs/gepa_adapter.md for using GEPA in Optimas, including custom adapter and logging instructions.
  • Updated README.md with advanced GEPA usage and logging config examples.

4. GEPA Optimizer Integration

  • Updated optimas/optim/args.py and cp_optimizer.py to:
    • Support all current GEPA config options (including logging, wandb, and budget).
    • Ensure compatibility with DSPy 3.0.1 and GEPA 0.0.4.
    • Restrict GEPA to DSPy-based components, with clear error messages otherwise.

5. Testing

  • Added tests/test_gepa_optimizer.py:
    • Uses the correct DSPy 3.0.1 signature style.
    • Uses max_metric_calls for GEPA budget (per latest API).
    • Passes in a clean environment with latest DSPy and GEPA.

How to Use

  • Install dependencies with uv pip install .[dev] (recommended) or pip.
  • Run tests with pytest.
  • Use pre-commit for local linting (ruff is non-blocking for now).
  • See CONTRIBUTING.md for full dev setup and docs/gepa_adapter.md for GEPA usage.

Things to note

  • Ruff is enabled but will not block commits/CI until errors are fixed (--ignore=ALL).
  • All changes are backward compatible and do not break existing workflows.
  • Optimas OSS project is now ready for robust, community-friendly open source development.

If team is new to modern Python tooling like uv ruff, I am happy to add more docs and guides as needed.

@Shashikant86
Copy link
Author

@Wuyxin Feel free to add relevant reviewers to the PR.

@Shashikant86 Shashikant86 changed the title Modernize Optimas Project Structure, GEPA Integration, and Tooling [WIP]Modernize Optimas Project Structure, GEPA Integration, and Tooling Aug 18, 2025
@Shashikant86 Shashikant86 marked this pull request as draft August 18, 2025 14:02
@Shashikant86 Shashikant86 changed the title [WIP]Modernize Optimas Project Structure, GEPA Integration, and Tooling Modernize Optimas Project Structure, GEPA Integration, and Tooling Aug 19, 2025
@Shashikant86 Shashikant86 changed the title Modernize Optimas Project Structure, GEPA Integration, and Tooling [READY FOR REVIEW] Modernize Optimas Project Structure, GEPA Integration, and Tooling Aug 19, 2025
@Shashikant86 Shashikant86 marked this pull request as ready for review August 19, 2025 14:04
@Shashikant86
Copy link
Author

@Wuyxin I have fully tested this PR locally and documented my observations in the resources directory also made sure it's not affecting the current features and functionality. I would like to be reviewed. Happy to answer any question and make further changes or simplify PR ..
Feel free to add any other reviewers and give feedback.

Copy link
Collaborator

@parthsarthi03 parthsarthi03 left a 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:
Copy link
Collaborator

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

Copy link
Author

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?

Copy link
Collaborator

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?

Copy link
Author

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

Copy link
Author

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 ..

Copy link
Author

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."""
Copy link
Collaborator

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?

Copy link
Author

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 ..

@Shashikant86
Copy link
Author

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 ..

@parthsarthi03
Copy link
Collaborator

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!

@Shashikant86
Copy link
Author

@parthsarthi03 Just revisiting this, wondering if you have done testing on this or need more time?

@parthsarthi03
Copy link
Collaborator

@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!

Copy link
Collaborator

@parthsarthi03 parthsarthi03 left a 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
Copy link
Collaborator

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

Copy link
Author

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.**
Copy link
Collaborator

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

Copy link
Author

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
Copy link
Collaborator

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

Copy link
Author

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

@Shashikant86
Copy link
Author

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.

@Shashikant86
Copy link
Author

@parthsarthi03 I have kept README.md minimal and moved some demo and GUIDE in the examples/gepa .. You should be able to run those demo locally and see how they perform. I tested and worked well but let me now if anything needs to be done here


```bash
# Quick demo with local models
ollama pull llama3.1:8b && ollama pull qwen3:8b
Copy link
Collaborator

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)

Copy link
Author

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.

Copy link
Collaborator

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.

@Shashikant86
Copy link
Author

Whats up Guys, Are you planning to planning to maintain the project or too busy with studies and academia?

Copy link
Collaborator

@parthsarthi03 parthsarthi03 left a 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.
Copy link
Collaborator

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):
Copy link
Collaborator

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):
Copy link
Collaborator

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
Copy link
Collaborator

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(
Copy link
Collaborator

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...")
Copy link
Collaborator

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",
Copy link
Collaborator

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(
Copy link
Collaborator

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(
Copy link
Collaborator

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

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.

2 participants