88from langchain_community .embeddings import HuggingFaceHubEmbeddings , OllamaEmbeddings
99from langchain_google_genai import GoogleGenerativeAIEmbeddings
1010from ..helpers import models_tokens
11- from ..models import AzureOpenAI , Bedrock , Gemini , Groq , HuggingFace , Ollama , OpenAI , Anthropic , DeepSeek
11+ from ..models import AzureOpenAI , Bedrock , Gemini , Groq , HuggingFace , Ollama , OpenAI , Anthropic
1212from langchain_google_genai .embeddings import GoogleGenerativeAIEmbeddings
1313
14- from ..helpers import models_tokens
15- from ..models import AzureOpenAI , Bedrock , Gemini , Groq , HuggingFace , Ollama , OpenAI , Anthropic , DeepSeek
16-
17-
1814class AbstractGraph (ABC ):
1915 """
2016 Scaffolding class for creating a graph representation and executing it.
2117
2218 prompt (str): The prompt for the graph.
2319 source (str): The source of the graph.
2420 config (dict): Configuration parameters for the graph.
25- schema (str): The schema for the graph output.
2621 llm_model: An instance of a language model client, configured for generating answers.
2722 embedder_model: An instance of an embedding model client,
2823 configured for generating embeddings.
@@ -33,7 +28,6 @@ class AbstractGraph(ABC):
3328 prompt (str): The prompt for the graph.
3429 config (dict): Configuration parameters for the graph.
3530 source (str, optional): The source of the graph.
36- schema (str, optional): The schema for the graph output.
3731
3832 Example:
3933 >>> class MyGraph(AbstractGraph):
@@ -45,42 +39,34 @@ class AbstractGraph(ABC):
4539 >>> result = my_graph.run()
4640 """
4741
48- def __init__ (self , prompt : str , config : dict , source : Optional [str ] = None , schema : Optional [ str ] = None ):
42+ def __init__ (self , prompt : str , config : dict , source : Optional [str ] = None ):
4943
5044 self .prompt = prompt
5145 self .source = source
5246 self .config = config
53- self .schema = schema
5447 self .llm_model = self ._create_llm (config ["llm" ], chat = True )
5548 self .embedder_model = self ._create_default_embedder (llm_config = config ["llm" ]
5649 ) if "embeddings" not in config else self ._create_embedder (
5750 config ["embeddings" ])
58- self .verbose = False if config is None else config .get (
59- "verbose" , False )
60- self .headless = True if config is None else config .get (
61- "headless" , True )
62- self .loader_kwargs = config .get ("loader_kwargs" , {})
6351
6452 # Create the graph
6553 self .graph = self ._create_graph ()
6654 self .final_state = None
6755 self .execution_info = None
6856
6957 # Set common configuration parameters
58+
7059 self .verbose = False if config is None else config .get (
7160 "verbose" , False )
7261 self .headless = True if config is None else config .get (
7362 "headless" , True )
7463 self .loader_kwargs = config .get ("loader_kwargs" , {})
7564
76- common_params = {
77- "headless" : self .headless ,
78- "verbose" : self .verbose ,
79- "loader_kwargs" : self .loader_kwargs ,
80- "llm_model" : self .llm_model ,
81- "embedder_model" : self .embedder_model
82- }
83-
65+ common_params = {"headless" : self .headless ,
66+
67+ "loader_kwargs" : self .loader_kwargs ,
68+ "llm_model" : self .llm_model ,
69+ "embedder_model" : self .embedder_model }
8470 self .set_common_params (common_params , overwrite = False )
8571
8672 def set_common_params (self , params : dict , overwrite = False ):
@@ -93,7 +79,7 @@ def set_common_params(self, params: dict, overwrite=False):
9379
9480 for node in self .graph .nodes :
9581 node .update_config (params , overwrite )
96-
82+
9783 def _set_model_token (self , llm ):
9884
9985 if 'Azure' in str (type (llm )):
@@ -171,7 +157,7 @@ def _create_llm(self, llm_config: dict, chat=False) -> object:
171157 raise KeyError ("Model not supported" ) from exc
172158 return Anthropic (llm_params )
173159 elif "ollama" in llm_params ["model" ]:
174- llm_params ["model" ] = llm_params ["model" ].split ("ollama /" )[- 1 ]
160+ llm_params ["model" ] = llm_params ["model" ].split ("/" )[- 1 ]
175161
176162 # allow user to set model_tokens in config
177163 try :
@@ -245,8 +231,6 @@ def _create_default_embedder(self, llm_config=None) -> object:
245231 model = "models/embedding-001" )
246232 if isinstance (self .llm_model , OpenAI ):
247233 return OpenAIEmbeddings (api_key = self .llm_model .openai_api_key )
248- elif isinstance (self .llm_model , DeepSeek ):
249- return OpenAIEmbeddings (api_key = self .llm_model .openai_api_key )
250234 elif isinstance (self .llm_model , AzureOpenAIEmbeddings ):
251235 return self .llm_model
252236 elif isinstance (self .llm_model , AzureOpenAI ):
@@ -282,31 +266,30 @@ def _create_embedder(self, embedder_config: dict) -> object:
282266 if 'model_instance' in embedder_config :
283267 return embedder_config ['model_instance' ]
284268 # Instantiate the embedding model based on the model name
285- if "openai" in embedder_config ["model" ]. split ( "/" )[ 0 ] :
269+ if "openai" in embedder_config ["model" ]:
286270 return OpenAIEmbeddings (api_key = embedder_config ["api_key" ])
287271 elif "azure" in embedder_config ["model" ]:
288272 return AzureOpenAIEmbeddings ()
289- elif "ollama" in embedder_config ["model" ].split ("/" )[0 ]:
290- print ("ciao" )
291- embedder_config ["model" ] = embedder_config ["model" ].split ("ollama/" )[- 1 ]
273+ elif "ollama" in embedder_config ["model" ]:
274+ embedder_config ["model" ] = embedder_config ["model" ].split ("/" )[- 1 ]
292275 try :
293276 models_tokens ["ollama" ][embedder_config ["model" ]]
294277 except KeyError as exc :
295278 raise KeyError ("Model not supported" ) from exc
296279 return OllamaEmbeddings (** embedder_config )
297- elif "hugging_face" in embedder_config ["model" ]. split ( "/" )[ 0 ] :
280+ elif "hugging_face" in embedder_config ["model" ]:
298281 try :
299282 models_tokens ["hugging_face" ][embedder_config ["model" ]]
300283 except KeyError as exc :
301284 raise KeyError ("Model not supported" )from exc
302285 return HuggingFaceHubEmbeddings (model = embedder_config ["model" ])
303- elif "gemini" in embedder_config ["model" ]. split ( "/" )[ 0 ] :
286+ elif "gemini" in embedder_config ["model" ]:
304287 try :
305288 models_tokens ["gemini" ][embedder_config ["model" ]]
306289 except KeyError as exc :
307290 raise KeyError ("Model not supported" )from exc
308291 return GoogleGenerativeAIEmbeddings (model = embedder_config ["model" ])
309- elif "bedrock" in embedder_config ["model" ]. split ( "/" )[ 0 ] :
292+ elif "bedrock" in embedder_config ["model" ]:
310293 embedder_config ["model" ] = embedder_config ["model" ].split ("/" )[- 1 ]
311294 client = embedder_config .get ('client' , None )
312295 try :
0 commit comments