BredForCompanionship commited on
Commit
74f67ec
1 Parent(s): a54f06c

Update metric.py

Browse files
Files changed (1) hide show
  1. metric.py +17 -13
metric.py CHANGED
@@ -1,4 +1,4 @@
1
- import openai
2
  openai.api_key = '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'
3
 
4
  import pandas as pd
@@ -31,19 +31,23 @@ def compute(params):
31
 
32
  prompt=f"Give me a score from 1 to 10 (higher is better) judging how similar these two captions are. Caption one: {submitted_answer}. Caption two: {gt}\nScore:"
33
 
34
- response = openai.Completion.create(
35
- engine="text-davinci-003",
36
- prompt=prompt,
37
- temperature=0,
38
- max_tokens=1,
39
- )
 
 
 
 
 
 
40
 
41
- public_score = int(response.choices[0].text.strip())
42
  private_score = public_score
43
-
44
- metric_dict = {
45
- "public_score": {"metric1": public_score},
46
- "private_score": {"metric1": private_score}
47
- }
48
 
49
  return metric_dict
 
1
+ from openai import APIException, Completion
2
  openai.api_key = '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'
3
 
4
  import pandas as pd
 
31
 
32
  prompt=f"Give me a score from 1 to 10 (higher is better) judging how similar these two captions are. Caption one: {submitted_answer}. Caption two: {gt}\nScore:"
33
 
34
+ try:
35
+ response = Completion.create(
36
+ engine="text-davinci-003",
37
+ prompt=prompt,
38
+ temperature=0,
39
+ max_tokens=1,
40
+ )
41
+
42
+ public_score = int(response['choices'][0]['text'].strip())
43
+
44
+ except APIException as e:
45
+ print("Error:", e)
46
 
 
47
  private_score = public_score
48
+
49
+ metric_dict = {"public_score": {"metric1": public_score},
50
+ "private_score": {"metric1": private_score}
51
+ }
 
52
 
53
  return metric_dict