Skip to content

Commit 9bd90fe

Browse files
committed
feat: use google genai
1 parent c9e2cbb commit 9bd90fe

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

Docker/Evaluate.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ RUN pip install \
5454
rich \
5555
accelerate \
5656
anthropic \
57-
google-generativeai \
57+
google-genai \
5858
mistralai \
5959
openai \
6060
e2b

bigcodebench/gen/util/google_request.py

+28-14
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,47 @@
11
import time
22

3-
import google.generativeai as genai
3+
from google import genai
44
from google.api_core.exceptions import GoogleAPICallError, ResourceExhausted
55

66

77
def make_request(
8-
client: genai.GenerativeModel,
8+
model: str,
9+
client: genai.Client,
910
message: str,
1011
temperature: float,
1112
n: int,
1213
max_new_tokens: int = 2048,
1314
) -> genai.types.GenerateContentResponse:
1415
kwargs = {"temperature": temperature, "max_output_tokens": max_new_tokens}
1516

16-
if "-thinking-" in client.model_name:
17+
if "-thinking-" in model:
1718
kwargs.pop("max_output_tokens")
18-
19-
response = client.generate_content(
20-
[{"role": "user", "parts": [message]}],
21-
generation_config=genai.types.GenerationConfig(
19+
20+
response = client.models.generate_content(
21+
model=model,
22+
contents=message,
23+
config=genai.types.GenerateContentConfig(
2224
candidate_count=n,
25+
safety_settings=[
26+
genai.types.SafetySetting(
27+
category='HARM_CATEGORY_DANGEROUS_CONTENT',
28+
threshold='BLOCK_NONE'
29+
),
30+
genai.types.SafetySetting(
31+
category='HARM_CATEGORY_SEXUALLY_EXPLICIT',
32+
threshold='BLOCK_NONE'
33+
),
34+
genai.types.SafetySetting(
35+
category='HARM_CATEGORY_HATE_SPEECH',
36+
threshold='BLOCK_NONE'
37+
),
38+
genai.types.SafetySetting(
39+
category='HARM_CATEGORY_HARASSMENT',
40+
threshold='BLOCK_NONE'
41+
),
42+
],
2343
**kwargs
24-
),
25-
safety_settings=[
26-
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
27-
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
28-
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
29-
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
30-
],
44+
),
3145
)
3246

3347
return response

bigcodebench/provider/google.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import List
33
from tqdm import tqdm
44

5-
import google.generativeai as genai
5+
from google import genai
66

77
from bigcodebench.provider.base import DecoderBase
88
from bigcodebench.gen.util.google_request import make_auto_request
@@ -12,8 +12,8 @@
1212
class GoogleDecoder(DecoderBase):
1313
def __init__(self, name: str, **kwargs):
1414
super().__init__(name, **kwargs)
15-
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
16-
self.client = genai.GenerativeModel(name)
15+
self.model = name
16+
self.client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
1717

1818
def codegen(
1919
self, prompts: List[str], do_sample: bool = True, num_samples: int = 200
@@ -34,7 +34,8 @@ def codegen(
3434
tokenizer=None,
3535
)
3636
ret = make_auto_request(
37-
self.client,
37+
model=self.model,
38+
client=self.client,
3839
message=message,
3940
n=num_samples,
4041
temperature=self.temperature,

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ install_requires =
3535
rich
3636
accelerate>=0.30.1
3737
anthropic>=0.26.1
38-
google-generativeai>=0.5.4
38+
google-genai
3939
mistralai>=0.2.0,<1.0.0
4040
openai>=1.11.1
4141
e2b

0 commit comments

Comments
 (0)