Skip to content

feat(genie): add TogetherGenie for TogetherAI integration#112

Open
KacemMathlouthi wants to merge 6 commits intochonkie-inc:mainfrom
KacemMathlouthi:feat/add-together-genie
Open

feat(genie): add TogetherGenie for TogetherAI integration#112
KacemMathlouthi wants to merge 6 commits intochonkie-inc:mainfrom
KacemMathlouthi:feat/add-together-genie

Conversation

@KacemMathlouthi
Copy link

feat(genie): Add TogetherGenie for TogetherAI model integration

Summary

This PR introduces a new TogetherGenie class in the genie module, allowing Chonkie to use TogetherAI models. It supports standard text generation and structured JSON outputs using pydantic schemas, following TogetherAI's documented capabilities.

Features

  • TogetherGenie.generate(prompt: str) — sends a prompt to a TogetherAI model and returns plain text output.
  • TogetherGenie.generate_json(prompt: str, schema: BaseModel) — uses TogetherAI's [structured output support](https://docs.together.ai/docs/json-mode) to return a dictionary validated against a pydantic schema.
  • Validates whether the selected model supports structured JSON before attempting to call.

Supported Models for JSON Mode

A set of supported models is defined, based on: https://docs.together.ai/docs/json-mode
The full list is maintained in the SUPPORTED_JSON_MODELS constant.

Dependency Notes:

The following dependencies were added under the dev group in pyproject.toml:

  • together
  • pydantic

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @KacemMathlouthi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces a new TogetherGenie class to enable integration with TogetherAI models within the Chonkie framework. It supports both standard text generation and structured JSON output using Pydantic schemas, leveraging TogetherAI's capabilities. The PR also includes the addition of together and pydantic as dependencies in the pyproject.toml file.

Highlights

  • New Feature: TogetherAI Integration: Adds TogetherGenie class for interacting with TogetherAI models.
  • JSON Schema Support: Implements generate_json method for structured JSON output using Pydantic schemas, validating against a list of supported models.
  • Dependency Management: Adds together and pydantic as dependencies to pyproject.toml.

Changelog

Click here to see the changelog
  • pyproject.toml
    • Added pydantic[dev]>=2.11.2 as a dependency at line 50.
    • Added together[dev]>=1.4.6 as a dependency at line 51.
  • src/chonkie/genie/init.py
    • Imported TogetherGenie from chonkie.genie.together at line 6.
    • Added TogetherGenie to the __all__ list at line 13.
  • src/chonkie/genie/together.py
    • Created new file src/chonkie/genie/together.py implementing the TogetherGenie class.
    • Implements generate for basic chat completions.
    • Implements generate_json for structured JSON output.
    • Includes a list of supported models for JSON mode.
    • Adds dependency management for together and pydantic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A Genie new,
TogetherAI's call,
JSON takes its form.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This PR introduces a new TogetherGenie class to integrate TogetherAI models into Chonkie, supporting both text generation and structured JSON outputs. The implementation looks good overall, with clear separation of concerns and adherence to best practices. However, there are a few areas that could be improved for better maintainability and clarity.

Summary of Findings

  • Dependency Management: Consider grouping dependencies in pyproject.toml by purpose rather than alphabetically for better readability and maintainability.
  • Global Imports: The _import_dependencies method uses global to import dependencies, which can make the code harder to understand and maintain. Consider refactoring this to avoid using global.
  • Error Message Clarity: The error message in the ImportError could be more user-friendly by providing specific instructions on how to install the dependencies.

Merge Readiness

The code is well-structured and implements the desired functionality. However, addressing the comments regarding dependency management and global imports would improve the code's maintainability and readability. I recommend addressing these points before merging. I am unable to directly approve this pull request, and other reviewers should review and approve this code before merging.

Comment on lines +9 to +17
if TYPE_CHECKING:
try:
from together import Together
except ImportError:
Together = Any
try:
from pydantic import BaseModel
except ImportError:
BaseModel = Any
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider using typing.TYPE_CHECKING to avoid circular dependencies and improve type checking performance. You can move the import statements inside the if TYPE_CHECKING: block to prevent runtime import errors when these dependencies are not installed. This is especially useful for optional dependencies like together and pydantic.

if TYPE_CHECKING:
    from together import Together
    from pydantic import BaseModel

api_key (Optional[str]): The API key to use. Defaults to the environment variable TOGETHER_API_KEY.
"""
super().__init__()
self._import_dependencies()
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It might be beneficial to move the dependency check to the constructor to ensure that dependencies are available when the class is instantiated. This can prevent unexpected errors later on.

self._import_dependencies()

Comment on lines +107 to +114
if self._is_available():
global Together, BaseModel
from together import Together
from pydantic import BaseModel
else:
raise ImportError(
"TogetherGenie requires `together` and `pydantic`. Install with `pip install together pydantic`"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The _import_dependencies method uses global to import Together and BaseModel. While this works, it can make the code harder to understand and maintain. A better approach would be to assign these dependencies to class attributes or use them directly within the methods where they are needed. Consider refactoring this to avoid using global.

from together import Together
from pydantic import BaseModel

@chonk-lain chonk-lain self-requested a review January 21, 2026 19:11
Copilot AI review requested due to automatic review settings January 21, 2026 19:45
Copy link
Contributor

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 adds support for TogetherAI model integration by introducing a new TogetherGenie class, enabling both standard text generation and structured JSON outputs with pydantic schema validation.

Changes:

  • Added TogetherGenie class with support for text generation and JSON-mode responses
  • Defined a list of models that support JSON mode based on TogetherAI documentation
  • Integrated the new class into the genie module exports

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/chonkie/genie/together.py New file implementing TogetherGenie with generate() and generate_json() methods
src/chonkie/genie/init.py Added TogetherGenie to module imports and exports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import importlib.util as importutil
import os
from typing import TYPE_CHECKING, Any, Dict, Optional
import json
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The json module is imported but never used in this file. Consider removing this unused import to keep the code clean.

Suggested change
import json

Copilot uses AI. Check for mistakes.
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.

4 participants