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 stream callbacks #203

Merged
merged 9 commits into from
Sep 7, 2024
Merged

Add stream callbacks #203

merged 9 commits into from
Sep 7, 2024

Conversation

svilupp
Copy link
Owner

@svilupp svilupp commented Sep 6, 2024

  • Added a new EXPERIMENTAL streamcallback kwarg for aigenerate with the OpenAI and Anthropic prompt schema to enable custom streaming implementations. Simplest usage is simply with streamcallback=stdout, which will print each text chunk into the console. The system is modular enabling custom callbacks and allowing you to inspect received chunks. See ?StreamCallback for more information.

Example usage:

using PromptingTools
const PT = PromptingTools

# Simplest usage, just provide where to steam the text
msg = aigenerate("Count from 1 to 100."; streamcallback = stdout)

streamcallback = PT.StreamCallback()
msg = aigenerate("Count from 1 to 100."; streamcallback)
# this allows you to inspect each chunk with `streamcallback.chunks`

# Get verbose output with details of each chunk
streamcallback = PT.StreamCallback(; verbose=true, throw_on_error=true)
msg = aigenerate("Count from 1 to 10."; streamcallback, model = "claudeh")

Copy link

codecov bot commented Sep 7, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 39 lines in your changes missing coverage. Please review.

Project coverage is 91.83%. Comparing base (d04c737) to head (593ce9c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/streaming.jl 88.07% 26 Missing ⚠️
src/llm_openai.jl 0.00% 8 Missing ⚠️
src/llm_anthropic.jl 37.50% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #203      +/-   ##
==========================================
- Coverage   92.27%   91.83%   -0.45%     
==========================================
  Files          45       46       +1     
  Lines        4129     4359     +230     
==========================================
+ Hits         3810     4003     +193     
- Misses        319      356      +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@svilupp svilupp merged commit 5c198fb into main Sep 7, 2024
4 of 6 checks passed
@svilupp svilupp deleted the add-cheatsheets branch September 7, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant