Passing variables to the task function in run_experiment #10657
-
Describe your question❓ How to pass custom kwargs to task function in
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Based on the available documentation, the task function in def my_task(*, item, **kwargs):
question = item["input"]
response = OpenAI().chat.completions.create(
model="gpt-4.1", messages=[{"role": "user", "content": question}]
)
return response.choices[0].message.contentAnd for evaluators: def accuracy_evaluator(*, input, output, expected_output, metadata, **kwargs):
if expected_output and expected_output.lower() in output.lower():
return Evaluation(name="accuracy", value=1.0, comment="Correct answer found")
return Evaluation(name="accuracy", value=0.0, comment="Incorrect answer")The documentation doesn't show a mechanism for passing custom parameters (like Workaround approaches:
def make_task(model_name, top_k):
async def classify_label(*, item, **kwargs):
# model_name and top_k are accessible here
...
return classify_label
langfuse.run_experiment(
name="Classifier Test",
data=my_samples,
task=make_task("gpt-4", 3),
)
The current SDK design appears to only forward the standard parameters to task functions, not arbitrary kwargs passed to 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @i59931596-droid, the Langfuse SDK does not support additional kwargs for task functions. One workaround is to use closures or partials. You can find an example here. |
Beta Was this translation helpful? Give feedback.
Hi @i59931596-droid, the Langfuse SDK does not support additional kwargs for task functions. One workaround is to use closures or partials. You can find an example here.