Repository: VinciGit00/Scrapegraph-ai
File: scrapegraphai/graphs/abstract_graph.py (Python)

Code before:
            try:
                self.model_token = models_tokens["ernie"][llm_params["model"]]
            except KeyError:
                print("model not found, using default token size (8192)")
                self.model_token = 8192
            return ErnieBotChat(llm_params)

        elif "oneapi" in llm_params["model"]:

            # take the model after the last dash
            llm_params["model"] = llm_params["model"].split("/")[-1]
            try:
                self.model_token = models_tokens["oneapi"][llm_params["model"]]
            except KeyError as exc:
                raise KeyError("Model not supported") from exc
            return OneApi(llm_params)

        elif "nvidia" in llm_params["model"]:

            try:
                self.model_token = models_tokens["nvidia"][llm_params["model"].split("/")[-1]]
                llm_params["model"] = "/".join(llm_params["model"].split("/")[1:])
            except KeyError as exc:
                raise KeyError("Model not supported") from exc
            return ChatNVIDIA(llm_params)
        else:
            model_name = llm_params["model"].split("/")[-1]
            return handle_model(model_name, llm_params["model"], model_name)

        raise ValueError("Model provided by the configuration not supported")


    def get_state(self, key=None) -> dict:
        """ ""
        Get the final state of the graph.

        Args:
            key (str, optional): The key of the final state to retrieve.

        Returns:
            dict: The final state of the graph.
        """

        if key is not None:
            return self.final_state[key]
        return self.final_state

    def append_node(self, node):
        """
        Add a node to the graph.


Review comment (suggestion):
`handle_model` may raise unhandled errors if provided with unsupported models and providers. It should be enclosed in a `try/except` block, and / or a specific condition (`if model_name...` with the remaining four providers) should be added

Code after:
                    self.model_token = models_tokens["deepseek"][llm_params["model"]]
                except KeyError:
                    print("model not found, using default token size (8192)")
                    self.model_token = 8192
                return DeepSeek(llm_params)

            elif "ernie" in llm_params["model"]:
                try:
                    self.model_token = models_tokens["ernie"][llm_params["model"]]
                except KeyError:
                    print("model not found, using default token size (8192)")
                    self.model_token = 8192
                return ErnieBotChat(llm_params)

            elif "oneapi" in llm_params["model"]:
                # take the model after the last dash
                llm_params["model"] = llm_params["model"].split("/")[-1]
                try:
                    self.model_token = models_tokens["oneapi"][llm_params["model"]]
                except KeyError:
                    raise KeyError("Model not supported")
                return OneApi(llm_params)

            elif "nvidia" in llm_params["model"]:
                try:
                    self.model_token = models_tokens["nvidia"][llm_params["model"].split("/")[-1]]
                    llm_params["model"] = "/".join(llm_params["model"].split("/")[1:])
                except KeyError:
                    raise KeyError("Model not supported")
                return ChatNVIDIA(llm_params)

            else:
                model_name = llm_params["model"].split("/")[-1]
                return handle_model(model_name, llm_params["model"], model_name)

        except KeyError as e:
            print(f"Model not supported: {e}")


    def get_state(self, key=None) -> dict:
        """ ""
        Get the final state of the graph.

        Args:
            key (str, optional): The key of the final state to retrieve.

        Returns:
            dict: The final state of the graph.
        """

        if key is not None: