Parse the config object
(self, provider_cfg)
| 73 | self.provider_cfg = self._parse_config(provider_cfg) |
| 74 | |
| 75 | def _parse_config(self, provider_cfg) -> dict: |
| 76 | """Parse the config object""" |
| 77 | |
| 78 | conf_dict = dict() |
| 79 | |
| 80 | if isinstance(provider_cfg, dict): |
| 81 | conf_dict = provider_cfg |
| 82 | |
| 83 | key_var_name = conf_dict[PROVIDER_SETTING_KEY_VAR] |
| 84 | |
| 85 | if conf_dict[PROVIDER_SETTING_IS_AZURE]: |
| 86 | |
| 87 | key = os.getenv(key_var_name) |
| 88 | endpoint_var_name = conf_dict[PROVIDER_SETTING_BASE_VAR] |
| 89 | endpoint = os.getenv(endpoint_var_name) |
| 90 | |
| 91 | self.client = AzureOpenAI( |
| 92 | api_key = key, |
| 93 | api_version = conf_dict[PROVIDER_SETTING_API_VERSION], |
| 94 | azure_endpoint = endpoint |
| 95 | ) |
| 96 | else: |
| 97 | key = os.getenv(key_var_name) |
| 98 | self.client = OpenAI(api_key=key) |
| 99 | |
| 100 | self.embedding_model = conf_dict[PROVIDER_SETTING_EMB_MODEL] |
| 101 | self.llm_model = conf_dict[PROVIDER_SETTING_COMP_MODEL] |
| 102 | |
| 103 | try: |
| 104 | self.encoding = tiktoken.encoding_for_model(self.llm_model) |
| 105 | except KeyError: |
| 106 | self.encoding = tiktoken.get_encoding("cl100k_base") |
| 107 | |
| 108 | return conf_dict |
| 109 | |
| 110 | @property |
| 111 | def _emb_invocation_params(self) -> Dict: |