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 @track(flush=True) #193

Closed
wants to merge 2 commits into from
Closed

Add @track(flush=True) #193

wants to merge 2 commits into from

Conversation

dsblank
Copy link
Contributor

@dsblank dsblank commented Sep 6, 2024

Details

This PR adds @track(flush=True) so that you don't have to do it manually after the function has been called.

Before:

from opik import track, flush_tracker

@track()
def streaming_function(input):
    messages = [{"role": "user", "content": input}]
    response = framework.completion(
        model="gpt-3.5-turbo",
        messages=messages,
    )
    return response
streaming_function("Why?")
flush_tracker()

After:

from opik import track

@track(flush=True)
def streaming_function(input):
    messages = [{"role": "user", "content": input}]
    response = framework.completion(
        model="gpt-3.5-turbo",
        messages=messages,
    )
    return response
streaming_function("Why?")

Issues

None, except for adding some convenience.

I'm not sure if one can flush even async decorators inside the decorator?

Testing

No tests added yet. Just seeing if you think this would be worth while first.

Documentation

None yet.

@dsblank dsblank requested a review from a team as a code owner September 6, 2024 18:46
@dsblank dsblank force-pushed the dsb/flush-as-track-argument branch from 43bf9b9 to 68ae5b5 Compare September 9, 2024 11:07
@dsblank dsblank added the enhancement New feature or request label Sep 12, 2024
@dsblank dsblank self-assigned this Sep 12, 2024
@dsblank dsblank force-pushed the dsb/flush-as-track-argument branch from 68ae5b5 to b209cf1 Compare September 13, 2024 14:10
Copy link
Collaborator

@andrescrz andrescrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but let's get input from @alexkuzmik @japdubengsub

@@ -180,6 +187,9 @@ def wrapper(*args, **kwargs) -> Any: # type: ignore
output=result,
capture_output=capture_output,
)
if flush:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsblank this will not work for generators. See the code above, if the generator was decorated, we return wrapped generator before you are calling flush().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything we can do to flush after the generator is done?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do flushing in _after_call method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the info! I'll revise the PR and flush in the _after_call.

@jverre
Copy link
Collaborator

jverre commented Sep 27, 2024

@dsblank Closing this PR for now and we can re-open when it's ready

@jverre jverre closed this Sep 27, 2024
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.

4 participants