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.2.0.tar.gz (4.8 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.2.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: osmosis_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 4.8 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.2.0.tar.gz
Algorithm Hash digest
SHA256 6a59e330e02ccb1177e8925cf7c7df58fac0eac7135206fa6f9fe3ab27c70328
MD5 2a17590e59f302bba8442a0a856a4c19
BLAKE2b-256 d01ec86bedae18588afcc295cc44a6d506adb14edb73946e2d06691e813f13b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: osmosis_ai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ac3fb23535250117d06319e7b20db42a70b450172dac8bcaa6554b31c1091aa
MD5 3f06b40ee53254d53bc2d0a6c57d02b5
BLAKE2b-256 96280379ad1adbf514aa32f32bfb23bbcf589f46fe6aa6d5763887ffc252ad02

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