mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-06 01:45:27 +03:00
3.5 KiB
3.5 KiB
In [1]:
from langchain.llms.base import LLM
from typing import Optional, List, Mapping, AnyIn [2]:
class CustomLLM(LLM):
n: int
@property
def _llm_type(self) -> str:
return "custom"
def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:
if stop is not None:
raise ValueError("stop kwargs are not permitted.")
return prompt[:self.n]
@property
def _identifying_params(self) -> Mapping[str, Any]:
"""Get the identifying parameters."""
return {"n": self.n}In [3]:
llm = CustomLLM(n=10)In [4]:
llm("This is a foobar thing")Out [4]:
'This is a '
In [5]:
print(llm)[1mCustomLLM[0m
Params: {'n': 10}
In [ ]: