MCPcopy
hub / github.com/langroid/langroid / create

Method create

langroid/language_models/base.py:494–530  ·  view source on GitHub ↗

Create a language model. Args: config: configuration for language model Returns: instance of language model

(config: Optional[LLMConfig])

Source from the content-addressed store, hash-verified

492
493 @staticmethod
494 def create(config: Optional[LLMConfig]) -> Optional["LanguageModel"]:
495 """
496 Create a language model.
497 Args:
498 config: configuration for language model
499 Returns: instance of language model
500 """
501 if type(config) is LLMConfig:
502 raise ValueError(
503 """
504 Cannot create a Language Model object from LLMConfig.
505 Please specify a specific subclass of LLMConfig e.g.,
506 OpenAIGPTConfig. If you are creating a ChatAgent from
507 a ChatAgentConfig, please specify the `llm` field of this config
508 as a specific subclass of LLMConfig, e.g., OpenAIGPTConfig.
509 """
510 )
511 from langroid.language_models.azure_openai import AzureGPT
512 from langroid.language_models.mock_lm import MockLM, MockLMConfig
513 from langroid.language_models.openai_gpt import OpenAIGPT
514
515 if config is None or config.type is None:
516 return None
517
518 if config.type == "mock":
519 return MockLM(cast(MockLMConfig, config))
520
521 openai: Union[Type[AzureGPT], Type[OpenAIGPT]]
522
523 if config.type == "azure":
524 openai = AzureGPT
525 else:
526 openai = OpenAIGPT
527 cls = dict(
528 openai=openai,
529 ).get(config.type, openai)
530 return cls(config) # type: ignore
531
532 @staticmethod
533 def user_assistant_pairs(lst: List[str]) -> List[Tuple[str, str]]:

Callers

nothing calls this directly

Calls 2

MockLMClass · 0.90
getMethod · 0.80

Tested by

no test coverage detected