repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import logging |
| #2 | import os |
| #3 | from typing import Optional |
| #4 | |
| #5 | from embedchain.config import BaseLlmConfig |
| #6 | from embedchain.helpers.json_serializable import register_deserializable |
| #7 | from embedchain.llm.base import BaseLlm |
| #8 | |
| #9 | |
| #10 | @register_deserializable |
| #11 | class ClarifaiLlm(BaseLlm): |
| #12 | def __init__(self, config: Optional[BaseLlmConfig] = None): |
| #13 | super().__init__(config=config) |
| #14 | if not self.config.api_key and "CLARIFAI_PAT" not in os.environ: |
| #15 | raise ValueError("Please set the CLARIFAI_PAT environment variable.") |
| #16 | |
| #17 | def get_llm_model_answer(self, prompt): |
| #18 | return self._get_answer(prompt=prompt, config=self.config) |
| #19 | |
| #20 | @staticmethod |
| #21 | def _get_answer(prompt: str, config: BaseLlmConfig) -> str: |
| #22 | try: |
| #23 | from clarifai.client.model import Model |
| #24 | except ModuleNotFoundError: |
| #25 | raise ModuleNotFoundError( |
| #26 | "The required dependencies for Clarifai are not installed." |
| #27 | "Please install with `pip install clarifai==10.0.1`" |
| #28 | ) from None |
| #29 | |
| #30 | model_name = config.model |
| #31 | logging.info(f"Using clarifai LLM model: {model_name}") |
| #32 | api_key = config.api_key or os.getenv("CLARIFAI_PAT") |
| #33 | model = Model(url=model_name, pat=api_key) |
| #34 | params = config.model_kwargs |
| #35 | |
| #36 | try: |
| #37 | (params := {}) if config.model_kwargs is None else config.model_kwargs |
| #38 | predict_response = model.predict_by_bytes( |
| #39 | bytes(prompt, "utf-8"), |
| #40 | input_type="text", |
| #41 | inference_params=params, |
| #42 | ) |
| #43 | text = predict_response.outputs[0].data.text.raw |
| #44 | return text |
| #45 | |
| #46 | except Exception as e: |
| #47 | logging.error(f"Predict failed, exception: {e}") |
| #48 |