Improve provider-model match
Browse files- L3Score.py +9 -4
- app.py +2 -2
L3Score.py
CHANGED
|
@@ -128,25 +128,30 @@ class L3Score(evaluate.Metric):
|
|
| 128 |
client = openai.OpenAI(api_key=api_key)
|
| 129 |
model_names = set([model.id for model in client.models.list()])
|
| 130 |
if model not in model_names:
|
| 131 |
-
|
| 132 |
|
| 133 |
elif provider == "deepseek":
|
|
|
|
| 134 |
client = openai.OpenAI(api_key=api_key,base_url="https://api.deepseek.com")
|
| 135 |
model_names = [model.id for model in client.models.list()]
|
| 136 |
print(model_names)
|
| 137 |
if model not in model_names:
|
| 138 |
-
|
| 139 |
|
| 140 |
elif provider == "xai":
|
| 141 |
client = openai.OpenAI(api_key=api_key, base_url="https://api.xai.com")
|
| 142 |
model_names = [model.id for model in client.models.list()]
|
| 143 |
print(model_names)
|
| 144 |
if model not in model_names:
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
| 147 |
except openai.AuthenticationError as e:
|
| 148 |
message = e.body["message"]
|
| 149 |
return {"error": f"Authentication failed: {message}"}
|
|
|
|
|
|
|
| 150 |
|
| 151 |
assert len(questions) == len(predictions) == len(references), "Questions, predictions and references must have the same length"
|
| 152 |
|
|
|
|
| 128 |
client = openai.OpenAI(api_key=api_key)
|
| 129 |
model_names = set([model.id for model in client.models.list()])
|
| 130 |
if model not in model_names:
|
| 131 |
+
raise ValueError(f"Model {model} not found for provider {provider}, available models: {model_names}")
|
| 132 |
|
| 133 |
elif provider == "deepseek":
|
| 134 |
+
print("Checking DeepSeek model")
|
| 135 |
client = openai.OpenAI(api_key=api_key,base_url="https://api.deepseek.com")
|
| 136 |
model_names = [model.id for model in client.models.list()]
|
| 137 |
print(model_names)
|
| 138 |
if model not in model_names:
|
| 139 |
+
raise ValueError(f"Model {model} not found for provider {provider}, available models: {model_names}")
|
| 140 |
|
| 141 |
elif provider == "xai":
|
| 142 |
client = openai.OpenAI(api_key=api_key, base_url="https://api.xai.com")
|
| 143 |
model_names = [model.id for model in client.models.list()]
|
| 144 |
print(model_names)
|
| 145 |
if model not in model_names:
|
| 146 |
+
raise ValueError(f"Model {model} not found for provider {provider}, available models: {model_names}")
|
| 147 |
+
|
| 148 |
+
except ValueError as e:
|
| 149 |
+
return {"error": str(e)}
|
| 150 |
except openai.AuthenticationError as e:
|
| 151 |
message = e.body["message"]
|
| 152 |
return {"error": f"Authentication failed: {message}"}
|
| 153 |
+
except Exception as e:
|
| 154 |
+
return {"error": f"An error occurred when verifying the provider/model match: {e}"}
|
| 155 |
|
| 156 |
assert len(questions) == len(predictions) == len(references), "Questions, predictions and references must have the same length"
|
| 157 |
|
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import evaluate
|
| 3 |
-
from L3Score import L3Score
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def compute_l3score(api_key, provider, model, questions, predictions, references):
|
| 8 |
try:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import evaluate
|
|
|
|
| 3 |
|
| 4 |
+
|
| 5 |
+
l3score = evaluate.load("nhop/L3Score")
|
| 6 |
|
| 7 |
def compute_l3score(api_key, provider, model, questions, predictions, references):
|
| 8 |
try:
|