@@ -84,7 +84,7 @@ class OpenAIClient(LightevalModel):
84
84
85
85
def __init__ (self , config : OpenAIModelConfig , env_config ) -> None :
86
86
api_key = os .environ ["OPENAI_API_KEY" ]
87
- self .client = OpenAI (api_key = api_key )
87
+ self .client = OpenAI (api_key = api_key , base_url = os . getenv ( "OPENAI_BASE_URL" ) )
88
88
self .generation_parameters = config .generation_parameters
89
89
self .sampling_params = self .generation_parameters .to_vllm_openai_dict ()
90
90
@@ -99,7 +99,19 @@ def __init__(self, config: OpenAIModelConfig, env_config) -> None:
99
99
self .API_RETRY_MULTIPLIER = 2
100
100
self .CONCURENT_CALLS = 100
101
101
self .model = config .model
102
- self ._tokenizer = tiktoken .encoding_for_model (self .model )
102
+ try :
103
+ self ._tokenizer = tiktoken .encoding_for_model (self .model )
104
+ except KeyError :
105
+ if "TOKENIZER_PATH" in os .environ :
106
+ from transformers import AutoTokenizer
107
+
108
+ self ._tokenizer = AutoTokenizer .from_pretrained (os .getenv ("TOKENIZER_PATH" ))
109
+ elif os .path .exists (self .model ) and os .path .isdir (self .model ):
110
+ from transformers import AutoTokenizer
111
+
112
+ self ._tokenizer = AutoTokenizer .from_pretrained (self .model )
113
+ else :
114
+ raise
103
115
self .pairwise_tokenization = False
104
116
105
117
def __call_api (self , prompt , return_logits , max_new_tokens , num_samples , logit_bias ):
0 commit comments