The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Fix fine-tuned replicate models with faster cold boot (#10512)
Taqi Jaffri21fbbe83a7ad
diff --git a/libs/langchain/langchain/llms/replicate.py b/libs/langchain/langchain/llms/replicate.pyindex 9fa2807b4e..c5b8a8da6a 100644--- a/libs/langchain/langchain/llms/replicate.py+++ b/libs/langchain/langchain/llms/replicate.py@@ -33,6 +33,7 @@ class Replicate(LLM):input: Dict[str, Any] = Field(default_factory=dict)model_kwargs: Dict[str, Any] = Field(default_factory=dict)replicate_api_token: Optional[str] = None+ prompt_key: Optional[str] = Nonestreaming: bool = Field(default=False)"""Whether to stream the results."""@@ -114,15 +115,18 @@ class Replicate(LLM):model = replicate_python.models.get(model_str)version = model.versions.get(version_str)- # sort through the openapi schema to get the name of the first input- input_properties = sorted(- version.openapi_schema["components"]["schemas"]["Input"][- "properties"- ].items(),- key=lambda item: item[1].get("x-order", 0),- )- first_input_name = input_properties[0][0]- inputs = {first_input_name: prompt, **self.input}+ if not self.prompt_key:+ # sort through the openapi schema to get the name of the first input+ input_properties = sorted(+ version.openapi_schema["components"]["schemas"]["Input"][+ "properties"+ ].items(),+ key=lambda item: item[1].get("x-order", 0),+ )++ self.prompt_key = input_properties[0][0]++ inputs = {self.prompt_key: prompt, **self.input}prediction = replicate_python.predictions.create(version=version, input={**inputs, **kwargs}