-
Notifications
You must be signed in to change notification settings - Fork 95
Add openai.chat_completions package to support OSS models
#156
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
Open
dangusev
wants to merge
25
commits into
main
Choose a base branch
from
feature/baseten
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7eaa521
LLM: always get the Conversation from the agent instead of attaching …
dangusev 6993bd5
LLM: set None instructions by default
dangusev 36daca8
Support for video LLMs hosted on Baseten
dangusev 840fd35
LLM: add method `set_conversation` to be called by the agent after it…
dangusev fb7befc
LLM: Fix type hints
dangusev 4639df2
Update uv.lock
dangusev 6f353cc
Fixed mypy
dangusev 5620334
Improve readme
Nash0x7E2 736ff77
Basic example
Nash0x7E2 39da564
LLM: add method `set_conversation` to be called by the agent after it…
dangusev f3d5b11
Rename models to ChatCompletionsLLM and ChatCompletionsVLM and move t…
dangusev 6f70b14
Fix after rebase
dangusev 3b35983
Add ChatCompletionsVLM to openai.__init__
dangusev 1bc042e
Test cleanup
dangusev ae28cce
fix ruff
dangusev 7d33615
Fix mypy
dangusev ff4508b
Fix docstring
dangusev 73b1863
Fix docstring
dangusev 83442ca
Code cleanup
dangusev 42c7d17
Fix typos
dangusev 4508013
Update README.md
dangusev e6767f4
Merge branch 'main' into feature/baseten
dangusev bd6b4cc
Fix fps forwarding
dangusev eaa3738
Add an integration test for a ChatCompletionsLLM
dangusev db9774d
Merge branch 'main' into feature/baseten
dangusev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,63 @@ | ||
| """Video frame utilities.""" | ||
|
|
||
| import io | ||
|
|
||
| import av | ||
| from PIL.Image import Resampling | ||
|
|
||
|
|
||
| def ensure_even_dimensions(frame: av.VideoFrame) -> av.VideoFrame: | ||
| """ | ||
| Ensure frame has even dimensions for H.264 yuv420p encoding. | ||
| Crops by 1 pixel if width or height is odd. | ||
| """ | ||
| needs_width_adjust = frame.width % 2 != 0 | ||
| needs_height_adjust = frame.height % 2 != 0 | ||
|
|
||
| if not needs_width_adjust and not needs_height_adjust: | ||
| return frame | ||
|
|
||
| new_width = frame.width - (1 if needs_width_adjust else 0) | ||
| new_height = frame.height - (1 if needs_height_adjust else 0) | ||
|
|
||
| cropped = frame.reformat(width=new_width, height=new_height) | ||
| cropped.pts = frame.pts | ||
| if frame.time_base is not None: | ||
| cropped.time_base = frame.time_base | ||
|
|
||
| return cropped | ||
|
|
||
|
|
||
| def frame_to_jpeg_bytes( | ||
| frame: av.VideoFrame, target_width: int, target_height: int, quality: int = 85 | ||
| ) -> bytes: | ||
| """ | ||
| Convert a video frame to JPEG bytes with resizing. | ||
| Args: | ||
| frame: an instance of `av.VideoFrame`. | ||
| target_width: target width in pixels. | ||
| target_height: target height in pixels. | ||
| quality: JPEG quality. Default is 85. | ||
| Returns: frame as JPEG bytes. | ||
| """ | ||
| # Convert frame to a PIL image | ||
| img = frame.to_image() | ||
|
|
||
| # Calculate scaling to maintain aspect ratio | ||
| src_width, src_height = img.size | ||
| # Calculate scale factor (fit within target dimensions) | ||
| scale = min(target_width / src_width, target_height / src_height) | ||
| new_width = int(src_width * scale) | ||
| new_height = int(src_height * scale) | ||
dangusev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Resize with aspect ratio maintained | ||
| resized = img.resize((new_width, new_height), Resampling.LANCZOS) | ||
|
|
||
| # Save as JPEG with quality control | ||
| buf = io.BytesIO() | ||
| resized.save(buf, "JPEG", quality=quality, optimize=True) | ||
| return buf.getvalue() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.