MCPcopy Create free account
hub / github.com/TransluceAI/observatory / get_explainer

Function get_explainer

lib/explanations/explanations/explainer.py:121–153  ·  view source on GitHub ↗
(
    model_name: str,
    max_new_tokens: int,
    temperature: float = 1.0,
    top_p: float = 1.0,
    add_special_tokens: bool = True,
)

Source from the content-addressed store, hash-verified

119
120
121def get_explainer(
122 model_name: str,
123 max_new_tokens: int,
124 temperature: float = 1.0,
125 top_p: float = 1.0,
126 add_special_tokens: bool = True,
127) -> Explainer:
128 if "gpt" in model_name or "o1" in model_name:
129 explainer = OpenAIExplainer(
130 client=get_openai_client_async(),
131 model_name=model_name,
132 max_new_tokens=max_new_tokens,
133 temperature=temperature,
134 )
135 elif "claude" in model_name:
136 explainer = AnthropicExplainer(
137 client=get_anthropic_client_async(),
138 model_name=model_name,
139 max_new_tokens=max_new_tokens,
140 temperature=temperature,
141 )
142 else:
143 llm = LLM(model=model_name)
144 explainer = VLLMExplainer(
145 model_name=model_name,
146 max_new_tokens=max_new_tokens,
147 model=llm,
148 tokenizer=get_tokenizer(model_name, add_special_tokens=add_special_tokens),
149 sampling_params=SamplingParams(
150 temperature=temperature, max_tokens=max_new_tokens, top_p=top_p
151 ),
152 )
153 return explainer

Callers 1

initialize_explainerMethod · 0.90

Calls 6

get_openai_client_asyncFunction · 0.90
get_tokenizerFunction · 0.90
OpenAIExplainerClass · 0.85
AnthropicExplainerClass · 0.85
VLLMExplainerClass · 0.85

Tested by

no test coverage detected