| 58 | ] |
| 59 | ) |
| 60 | def __init__( |
| 61 | self, |
| 62 | model_type: Union[ModelType, str], |
| 63 | model_config_dict: Optional[Dict[str, Any]] = None, |
| 64 | api_key: Optional[str] = None, |
| 65 | url: Optional[str] = None, |
| 66 | token_counter: Optional[BaseTokenCounter] = None, |
| 67 | ) -> None: |
| 68 | if model_config_dict is None: |
| 69 | model_config_dict = YiConfig().as_dict() |
| 70 | api_key = api_key or os.environ.get("YI_API_KEY") |
| 71 | url = url or os.environ.get( |
| 72 | "YI_API_BASE_URL", "https://api.lingyiwanwu.com/v1" |
| 73 | ) |
| 74 | super().__init__( |
| 75 | model_type, model_config_dict, api_key, url, token_counter |
| 76 | ) |
| 77 | self._client = OpenAI( |
| 78 | timeout=180, |
| 79 | max_retries=3, |
| 80 | api_key=self._api_key, |
| 81 | base_url=self._url, |
| 82 | ) |
| 83 | |
| 84 | def run( |
| 85 | self, |