Skip to content
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

Adds groq inference adapter. #517

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions llama_stack/providers/registry/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,16 @@ def available_providers() -> List[ProviderSpec]:
config_class="llama_stack.providers.remote.inference.nvidia.NVIDIAConfig",
),
),
remote_provider_spec(
api=Api.inference,
adapter=AdapterSpec(
adapter_type="groq",
pip_packages=[
"openai",
],
module="llama_stack.providers.remote.inference.groq",
config_class="llama_stack.providers.remote.inference.groq.GroqImplConfig",
provider_data_validator="llama_stack.providers.remote.inference.groq.GroqProviderDataValidator",
),
),
]
24 changes: 24 additions & 0 deletions llama_stack/providers/remote/inference/groq/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

from pydantic import BaseModel

from .config import GroqImplConfig


class GroqProviderDataValidator(BaseModel):
groq_api_key: str


async def get_adapter_impl(config: GroqImplConfig, _deps):
from .groq import GroqInferenceAdapter

assert isinstance(
config, GroqImplConfig
), f"Unexpected config type: {type(config)}"
impl = GroqInferenceAdapter(config)
await impl.initialize()
return impl
29 changes: 29 additions & 0 deletions llama_stack/providers/remote/inference/groq/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

from typing import Any, Dict, Optional

from llama_models.schema_utils import json_schema_type
from pydantic import BaseModel, Field


@json_schema_type
class GroqImplConfig(BaseModel):
url: str = Field(
default="https://api.groq.com/openai/v1",
description="The URL for the Groq API server",
)
api_key: Optional[str] = Field(
default=None,
description="The Groq API Key",
)

@classmethod
def sample_run_config(cls, **kwargs) -> Dict[str, Any]:
return {
"url": "https://api.groq.com/openai/v1",
"api_key": "${env.GROQ_API_KEY}",
}
Loading