मुख्य सामग्री पर जाएं
Concept: Middleware | API: Evaluation API
RAILMiddleware किसी भी async function को wrap करता है जो LLM responses generate करता है, और आपकी LLM call logic को बदले बिना automatic RAIL scoring add कर देता है।
import asyncio
from rail_score_sdk import RAILMiddleware

async def my_llm(messages, **kwargs):
    # आपकी LLM call यहाँ — string return करती है
    return "The LLM generated this response."

async def main():
    mw = RAILMiddleware(
        api_key="YOUR_RAIL_API_KEY",
        generate_fn=my_llm,
        threshold=7.0,
        policy="block",
        eval_input=True,
        input_threshold=5.0,
    )

    result = await mw.run(
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Explain quantum computing."},
        ]
    )
    print(f"Score: {result.score}, Met threshold: {result.threshold_met}")
    print(f"Content: {result.content}")

asyncio.run(main())

Parameters

ParameterTypeDefaultDescription
api_keystrRAIL API key
generate_fnasync callableआपका LLM function
thresholdfloatNoneइस score से नीचे block/regenerate करें
policystr"block""block" या "regenerate"
eval_inputboolFalseInput messages को भी score करें
input_thresholdfloatNoneInput scoring के लिए threshold
max_iterationsint3Maximum regeneration attempts