8000 add get_image for openai and xai by skyl · Pull Request #72 · corpora-inc/corpora · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add get_image for openai and xai #72

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

Merged
merged 4 commits into from
May 15, 2025
Merged

add get_image for openai and xai #72

merged 4 commits into from
May 15, 2025

Conversation

skyl
Copy link
Collaborator
@skyl skyl commented May 6, 2025

PR Type

enhancement


Description

  • Introduced get_image method for image generation.

  • Added GeneratedImage dataclass for image data handling.

  • Integrated image generation in OpenAI and XAI clients.

  • Updated imports and typing for image handling.


Changes walkthrough 📝

Relevant files
Enhancement
llm_interface.py
Define `GeneratedImage` and `get_image` in interface         

py/packages/corpora_ai/llm_interface.py

  • Added GeneratedImage dataclass for image data.
  • Introduced get_image abstract method in LLMBaseInterface.
  • Updated imports to include Optional.
  • +25/-1   
    llm_client.py
    Implement image generation in OpenAI client                           

    py/packages/corpora_ai_openai/llm_client.py

  • Implemented get_image method for OpenAI client.
  • Added image_model parameter in constructor.
  • Updated imports for image handling.
  • +47/-2   
    llm_client.py
    Implement image generation in XAI client                                 

    py/packages/corpora_ai_xai/llm_client.py

  • Implemented get_image method for XAI client.
  • Added image_model parameter in constructor.
  • Updated imports for image handling.
  • +48/-2   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link
    github-actions bot commented May 6, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Image Format Default

    The GeneratedImage dataclass has a default format set to "png". This should be reviewed to ensure that it aligns with the expected default format for all use cases.

    class GeneratedImage:
        """Holds one generated image's raw bytes plus an optional format hint."""
    
        data: bytes
        format: Optional[str] = "png"
    Hardcoded Image Parameters

    The get_image method in OpenAIClient has hardcoded parameters for image size and number of images. Consider making these configurable or ensuring they meet all use cases.

    def get_image(
        self,
        prompt: str,
        **kwargs,
    ) -> List[GeneratedImage]:
        """
        Generate one or more images.
    
        Args:
            prompt: Natural-language description of the desired image.
            kwargs: Passed through to OpenAI API (e.g. n, size).
    
        Returns:
            A list of GeneratedImage with raw bytes and the appropriate format ("png").
        """
        # build the core params
        params = {
            "model": self.image_model,
            "prompt": prompt,
            # "response_format": "b64_json",
            "n": 1,
            "size": "1024x1024",
        }
        # merge in any overrides (e.g. size="1536x1024", n=2)
        params.update(kwargs)
        resp: ImagesResponse = self.client.images.generate(**params)
    
        images: List[GeneratedImage] = []
        for img in resp.data:
            raw = base64.b64decode(img.b64_json)
            images.append(GeneratedImage(data=raw, format="png"))
    
        return images

    Copy link
    github-actions bot commented May 6, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Correct image size specification

    Ensure the image size is consistent with the documented size of 1024x768 pixels to
    avoid discrepancies between the code and documentation.

    py/packages/corpora_ai_openai/llm_client.py [139]

    -"size": "1024x1024",
    +"size": "1024x768",
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion corrects a discrepancy between the documented image size and the actual code, ensuring consistency and preventing potential confusion or errors in image generation.

    Medium

    @skyl skyl merged commit 4ed4d24 into main May 15, 2025
    2 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant
    0