Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task decorator #1028

Merged
merged 5 commits into from
Oct 10, 2024
Merged

Add task decorator #1028

merged 5 commits into from
Oct 10, 2024

Conversation

gabrielmbmb
Copy link
Member

Description

This PR adds a new task decorator that allows to easily create new Tasks defining an output formatting function and the system prompt and user message template using the docstring of the function.

from typing import Dict, Any, Union
from distilabel.steps.tasks import task
from distilabel.llms import InferenceEndpointsLLM


@task(inputs=["task", "instruction"], outputs=["response"])
def MyTask(
    output: Union[str, None], input: Union[Dict[str, Any], None] = None
) -> Dict[str, Any]:
    """
    `MyTask` is a simple `Task` for bla bla bla

    ---
    system_prompt: |
        You are an AI assistant designed to {task}

    user_message_template: |
        {instruction}
    ---
    """
    return {"response": output}


task = MyTask(llm=InferenceEndpointsLLM(model_id="Qwen/Qwen2.5-72B-Instruct"))

task.load()

result = next(
    task.process_applying_mappings(
        [
            {
                "task": "extract information",
                "instruction": "Who won the nobel? The Nobel Committee lauded David Baker, a US biochemist, for completing “the almost impossible feat of building entirely new kinds of proteins,” and Demis Hassabis and John Jumper, who work at Google DeepMind, for developing an AI model to predict proteins’ complex structures – a problem that had been unsolved for 50 years.",
            }
        ]
    )
)

print(result)

Copy link

github-actions bot commented Oct 9, 2024

Documentation for this PR has been built. You can view it at: https://distilabel.argilla.io/pr-1028/

Copy link

codspeed-hq bot commented Oct 9, 2024

CodSpeed Performance Report

Merging #1028 will not alter performance

Comparing task-decorator (e51f8b9) with develop (106e402)

Summary

✅ 1 untouched benchmarks

@gabrielmbmb gabrielmbmb self-assigned this Oct 9, 2024
@gabrielmbmb gabrielmbmb added the enhancement New feature or request label Oct 9, 2024
@gabrielmbmb gabrielmbmb added this to the 1.5.0 milestone Oct 9, 2024
@gabrielmbmb gabrielmbmb linked an issue Oct 9, 2024 that may be closed by this pull request
@gabrielmbmb gabrielmbmb marked this pull request as ready for review October 9, 2024 14:39
@gabrielmbmb gabrielmbmb merged commit 0666dd4 into develop Oct 10, 2024
7 checks passed
@gabrielmbmb gabrielmbmb deleted the task-decorator branch October 10, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] task decorator
2 participants