Skip to main content

Adds reward functionality to LLM client libraries

Project description

osmosis-ai

A Python library that provides reward functionality for LLM applications with strict type enforcement.

Installation

pip install osmosis-ai

For development:

git clone https://github.com/Osmosis-AI/osmosis-sdk-python
cd osmosis-sdk-python
pip install -e .

Quick Start

from osmosis_ai import osmosis_reward

@osmosis_reward
def simple_reward(solution_str: str, ground_truth: str, extra_info: dict = None) -> float:
    """Basic exact match reward function."""
    return 1.0 if solution_str.strip() == ground_truth.strip() else 0.0

# Use the reward function
score = simple_reward("hello world", "hello world")  # Returns 1.0

Required Function Signature

All functions decorated with @osmosis_reward must have exactly this signature:

@osmosis_reward
def your_function(solution_str: str, ground_truth: str, extra_info: dict = None) -> float:
    # Your reward logic here
    return float_score

Parameters

  • solution_str: str - The solution string to evaluate (required)
  • ground_truth: str - The correct/expected answer (required)
  • extra_info: dict = None - Optional dictionary for additional configuration

Return Value

  • -> float - Must return a float value representing the reward score

The decorator will raise a TypeError if the function doesn't match this exact signature or doesn't return a float.

Examples

See the examples/ directory for complete examples:

@osmosis_reward
def case_insensitive_match(solution_str: str, ground_truth: str, extra_info: dict = None) -> float:
    """Case-insensitive string matching with partial credit."""
    match = solution_str.lower().strip() == ground_truth.lower().strip()

    if extra_info and 'partial_credit' in extra_info:
        if not match and extra_info['partial_credit']:
            len_diff = abs(len(solution_str) - len(ground_truth))
            if len_diff <= 2:
                return 0.5

    return 1.0 if match else 0.0

@osmosis_reward
def numeric_tolerance(solution_str: str, ground_truth: str, extra_info: dict = None) -> float:
    """Numeric comparison with configurable tolerance."""
    try:
        solution_num = float(solution_str.strip())
        truth_num = float(ground_truth.strip())

        tolerance = extra_info.get('tolerance', 0.01) if extra_info else 0.01
        return 1.0 if abs(solution_num - truth_num) <= tolerance else 0.0
    except ValueError:
        return 0.0

Running Examples

python examples/reward_functions.py

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and examples
  5. Submit a pull request

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osmosis_ai-0.1.9.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

osmosis_ai-0.1.9-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file osmosis_ai-0.1.9.tar.gz.

File metadata

  • Download URL: osmosis_ai-0.1.9.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for osmosis_ai-0.1.9.tar.gz
Algorithm Hash digest
SHA256 ceef926c3965942d0ba44bbd6ca90f3e90b58502e81a7fc294d7d3d77c6d9090
MD5 c63e50aca60c539337607d9c6cda1ac1
BLAKE2b-256 32023f44ec1333b3ecdb6185ae243b03ccab6cc52bf1c5eb6367824909549a5c

See more details on using hashes here.

File details

Details for the file osmosis_ai-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: osmosis_ai-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for osmosis_ai-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 2b6053f92456059cb18fb540116c1d8673b0db6c849e2597127036662fd8e6f4
MD5 4c199328025853e0f113c9d4a2ca097f
BLAKE2b-256 3c1e601ba20af34b1cd22aed8f9b0a6c7876efedc014232f805fe062db90fc98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page