The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[patch]: Fix error in `LlamaCpp` community LLM with Configurable Fields, 'grammar' custom type not available (#16995)
François Paupier929f07151374
diff --git a/libs/community/langchain_community/llms/llamacpp.py b/libs/community/langchain_community/llms/llamacpp.pyindex c29ca74ef7..d46d741e7b 100644--- a/libs/community/langchain_community/llms/llamacpp.py+++ b/libs/community/langchain_community/llms/llamacpp.py@@ -2,7 +2,7 @@ from __future__ import annotationsimport loggingfrom pathlib import Path-from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union+from typing import Any, Dict, Iterator, List, Optional, Unionfrom langchain_core.callbacks import CallbackManagerForLLMRunfrom langchain_core.language_models.llms import LLM@@ -11,9 +11,6 @@ from langchain_core.pydantic_v1 import Field, root_validatorfrom langchain_core.utils import get_pydantic_field_namesfrom langchain_core.utils.utils import build_extra_kwargs-if TYPE_CHECKING:- from llama_cpp import LlamaGrammar-logger = logging.getLogger(__name__)@@ -126,7 +123,7 @@ class LlamaCpp(LLM):to force the model to generate valid JSON or to speak exclusively in emojis. At mostone of grammar_path and grammar should be passed in."""- grammar: Optional[Union[str, LlamaGrammar]] = None+ grammar: Optional[Union[str, Any]] = None"""grammar: formal grammar for constraining model outputs. For instance, the grammarcan be used to force the model to generate valid JSON or to speak exclusively in