together_client

Classes

TogetherClient([api_key, ...])

A minimal Together client that inherits from OpenAIClient.

class TogetherClient(api_key: str | None = None, non_streaming_chat_completion_parser: Callable[[Completion], Any] = None, streaming_chat_completion_parser: Callable[[Completion], Any] = None, input_type: Literal['text', 'messages'] = 'text', base_url: str | None = None, env_api_key_name: str = 'TOGETHER_API_KEY')[source]

Bases: OpenAIClient

A minimal Together client that inherits from OpenAIClient.

This client is designed to work with the Together API by overriding the init_sync_client method from OpenAIClient. It leverages the official Together SDK to initialize both synchronous and asynchronous client instances.

References: - To get an API key, sign up at https://www.together.ai/ - To list available models, use the command: together models list. For setup instructions, see:

Example usage with the AdalFlow Generator:

from adalflow.core import Generator
from adalflow.components.model_client.together_client import TogetherClient
from adalflow.utils import setup_env

setup_env()

generator = Generator(
    model_client=TogetherClient(),
    model_kwargs={
        "model": "deepseek-ai/DeepSeek-R1",
        "temperature": 0.7,
        "max_tokens": 2000,
    },
    output_processors=your_output_processor_function,
)

prompt_kwargs = {"input_str": "Hi from AdalFlow! Summarize generative AI briefly."}

response = generator(prompt_kwargs)
init_sync_client()[source]

Initialize and return a synchronous Together client instance.

Retrieves the API key from the provided value or from the environment variable, and returns a Together client initialized with the proper base URL.

init_async_client()[source]

Initialize and return an asynchronous Together client instance.

If the Together SDK supports asynchronous operations, this method returns an instance of the async client.