Skip to content

PR-500 simplified client wrapper functions #562

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
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mogith-pn
Copy link
Contributor

Why

  • https://clarifai.atlassian.net/browse/PR-500
  • The client wrapper function in model upload code, still needed some abstraction for converting images/video/audio into openai compatible format before sending to chat function.

How

  • Since it can be abstacted into the runner data utils function, moved those preprocessing steps into SDK.

Tests

@mogith-pn mogith-pn requested review from Copilot and luv-bansal and removed request for Copilot April 23, 2025 15:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR simplifies the client wrapper functions by introducing a unified helper to format OpenAI chat messages with various media types (image, audio, video) and by adding base64 conversion methods to the corresponding data types.

  • Updated PIL image conversions by importing PILImage and aligning type hints.
  • Added build_openai_chat_format and internal helper functions to process images, audio, and video.
  • Extended data types with new to_base64_str methods for Image, Audio, and Video objects.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
clarifai/runners/utils/data_utils.py Updated image conversion functions and added media processing functions for chat messages.
clarifai/runners/utils/data_types.py Added to_base64_str utility methods for converting media bytes to base64 strings.
Comments suppressed due to low confidence (2)

clarifai/runners/utils/data_utils.py:132

  • [nitpick] Consider using a distinct local variable for the base64 string conversion in _process_audio instead of reassigning the parameter 'audio', to improve code clarity.
if audio.bytes:

clarifai/runners/utils/data_utils.py:158

  • [nitpick] Consider using a separate variable to hold the base64 string in _process_video rather than overwriting the parameter 'video', for improved readability.
if video.bytes:

Copy link

Code Coverage

Package Line Rate Health
clarifai 43%
clarifai.cli 59%
clarifai.client 73%
clarifai.client.auth 74%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 80%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.modules 0%
clarifai.rag 72%
clarifai.runners 10%
clarifai.runners.models 67%
clarifai.runners.utils 59%
clarifai.schema 100%
clarifai.urls 80%
clarifai.utils 76%
clarifai.utils.evaluation 67%
clarifai.workflows 94%
Summary 68% (5803 / 8577)

Minimum allowed line rate is 50%

Copy link
Contributor

@luv-bansal luv-bansal left a comment

Choose a reason for hiding this comment

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

Looks good, but not sure , should we add build_openai_chat_format function to utils/openai_convertor.py file?

@@ -58,6 +58,126 @@ def is_openai_chat_format(messages):
return True


def build_openai_chat_format(prompt: str, image: Image, images: List[Image], audio: Audio,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, do you think we could move this to here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants