Add Anthropic model component
This commit is contained in:
parent
2d30edc13d
commit
0325c4168a
1 changed files with 52 additions and 0 deletions
52
src/backend/langflow/components/models/Anthropic.py
Normal file
52
src/backend/langflow/components/models/Anthropic.py
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from langchain_community.llms.anthropic import Anthropic
|
||||||
|
from pydantic.v1 import SecretStr
|
||||||
|
|
||||||
|
from langflow import CustomComponent
|
||||||
|
from langflow.field_typing import BaseLanguageModel, NestedDict
|
||||||
|
|
||||||
|
|
||||||
|
class AnthropicComponent(CustomComponent):
|
||||||
|
display_name = "Anthropic Model"
|
||||||
|
description = "Anthropic large language models."
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
return {
|
||||||
|
"anthropic_api_key": {
|
||||||
|
"display_name": "Anthropic API Key",
|
||||||
|
"type": str,
|
||||||
|
"password": True,
|
||||||
|
},
|
||||||
|
"anthropic_api_url": {
|
||||||
|
"display_name": "Anthropic API URL",
|
||||||
|
"type": str,
|
||||||
|
},
|
||||||
|
"model_kwargs": {
|
||||||
|
"display_name": "Model Kwargs",
|
||||||
|
"field_type": "NestedDict",
|
||||||
|
"advanced": True,
|
||||||
|
},
|
||||||
|
"temperature": {
|
||||||
|
"display_name": "Temperature",
|
||||||
|
"field_type": "float",
|
||||||
|
},
|
||||||
|
"inputs": {"display_name": "Input"},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def build(
|
||||||
|
self,
|
||||||
|
anthropic_api_key: str,
|
||||||
|
anthropic_api_url: str,
|
||||||
|
model_kwargs: NestedDict = {},
|
||||||
|
temperature: Optional[float] = None,
|
||||||
|
inputs: str = None,
|
||||||
|
) -> BaseLanguageModel:
|
||||||
|
llm = Anthropic(
|
||||||
|
anthropic_api_key=SecretStr(anthropic_api_key),
|
||||||
|
anthropic_api_url=anthropic_api_url,
|
||||||
|
model_kwargs=model_kwargs,
|
||||||
|
temperature=temperature,
|
||||||
|
)
|
||||||
|
return llm.invoke(input=inputs)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue