From d930a46e648e6e78a08b4fe5828e3f6796c09b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 24 Oct 2024 12:57:46 -0700 Subject: [PATCH] services(together): fix together AI InputParams --- src/pipecat/services/openai.py | 3 +++ src/pipecat/services/together.py | 41 ++------------------------------ 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/src/pipecat/services/openai.py b/src/pipecat/services/openai.py index e12744fcd..598240bd5 100644 --- a/src/pipecat/services/openai.py +++ b/src/pipecat/services/openai.py @@ -99,6 +99,9 @@ class BaseOpenAILLMService(LLMService): ) seed: Optional[int] = Field(default_factory=lambda: NOT_GIVEN, ge=0) temperature: Optional[float] = Field(default_factory=lambda: NOT_GIVEN, ge=0.0, le=2.0) + # Note: top_k is currently not supported by the OpenAI client library, + # so top_k is ignore right now. + top_k: Optional[int] = Field(default=None, ge=0) top_p: Optional[float] = Field(default_factory=lambda: NOT_GIVEN, ge=0.0, le=1.0) max_tokens: Optional[int] = Field(default_factory=lambda: NOT_GIVEN, ge=1) max_completion_tokens: Optional[int] = Field(default_factory=lambda: NOT_GIVEN, ge=1) diff --git a/src/pipecat/services/together.py b/src/pipecat/services/together.py index 1bf74e508..e2aed4da1 100644 --- a/src/pipecat/services/together.py +++ b/src/pipecat/services/together.py @@ -4,11 +4,8 @@ # SPDX-License-Identifier: BSD 2-Clause License # -from typing import Any, Dict, Optional -import httpx from loguru import logger -from pydantic import BaseModel, Field from pipecat.services.openai import OpenAILLMService @@ -27,50 +24,16 @@ except ModuleNotFoundError as e: class TogetherLLMService(OpenAILLMService): """This class implements inference with Together's Llama 3.1 models""" - class InputParams(BaseModel): - frequency_penalty: Optional[float] = Field(default=None, ge=-2.0, le=2.0) - max_tokens: Optional[int] = Field(default=4096, ge=1) - presence_penalty: Optional[float] = Field(default=None, ge=-2.0, le=2.0) - temperature: Optional[float] = Field(default=None, ge=0.0, le=1.0) - # Note: top_k is currently not supported by the OpenAI client library, - # so top_k is ignore right now. - top_k: Optional[int] = Field(default=None, ge=0) - top_p: Optional[float] = Field(default=None, ge=0.0, le=1.0) - extra: Optional[Dict[str, Any]] = Field(default_factory=dict) - seed: Optional[int] = Field(default=None) - def __init__( self, *, api_key: str, base_url: str = "https://api.together.xyz/v1", model: str = "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo", - params: InputParams = InputParams(), **kwargs, ): - super().__init__(api_key=api_key, base_url=base_url, model=model, params=params, **kwargs) - self.set_model_name(model) - self._settings = { - "max_tokens": params.max_tokens, - "frequency_penalty": params.frequency_penalty, - "presence_penalty": params.presence_penalty, - "seed": params.seed, - "temperature": params.temperature, - "top_p": params.top_p, - "extra": params.extra if isinstance(params.extra, dict) else {}, - } - - def can_generate_metrics(self) -> bool: - return True + super().__init__(api_key=api_key, base_url=base_url, model=model, **kwargs) def create_client(self, api_key=None, base_url=None, **kwargs): logger.debug(f"Creating Together.ai client with api {base_url}") - return AsyncOpenAI( - api_key=api_key, - base_url=base_url, - http_client=DefaultAsyncHttpxClient( - limits=httpx.Limits( - max_keepalive_connections=100, max_connections=1000, keepalive_expiry=None - ) - ), - ) + return super().create_client(api_key, base_url, **kwargs)