Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

add enum util (#1882)

Echob88f9c0c55b4
diff --git a/camel/types/enums.py b/camel/types/enums.py
index ada14dd7e..6602eb9ae 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -217,6 +217,14 @@ class ModelType(UnifiedModelType, Enum):
def __new__(cls, value) -> "ModelType":
return cast("ModelType", UnifiedModelType.__new__(cls, value))
+ @classmethod
+ def from_name(cls, name):
+ r"""Returns the ModelType enum value from a string."""
+ for model_type in cls:
+ if model_type.value == name:
+ return model_type
+ raise ValueError(f"Unknown ModelType name: {name}")
+
@property
def value_for_tiktoken(self) -> str:
if self.is_openai:
@@ -895,6 +903,14 @@ class ModelPlatformType(Enum):
AIML = "aiml"
VOLCANO = "volcano"
+ @classmethod
+ def from_name(cls, name):
+ r"""Returns the ModelPlatformType enum value from a string."""
+ for model_platfrom_type in cls:
+ if model_platfrom_type.value == name:
+ return model_platfrom_type
+ raise ValueError(f"Unknown ModelPlatformType name: {name}")
+
@property
def is_openai(self) -> bool:
r"""Returns whether this platform is openai."""