Skip to content

Commit 05bfb7f

Browse files
authored
Add tuned_models samples (#409)
* Add tuned_models samples Change-Id: I4b85a0179d2e7e4c112ed6250a7e602de57787c4 * format Change-Id: I19e37673d0451fbb243f5041abf40a961dd03a2f * fix tests and debug Change-Id: I8a71ea707f1ec9229d7ea1aee8b8fac25835c296 * format Change-Id: I0514cff86d043c088aa70e2f10f0815326ed3d09 * revert -q Change-Id: I4f2dfabd14777182f01038d608c2c0b65f43d02f
1 parent 630318b commit 05bfb7f

File tree

4 files changed

+357
-1
lines changed

4 files changed

+357
-1
lines changed

google/generativeai/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from google.generativeai.types.generation_types import *
2222
from google.generativeai.types.helper_types import *
2323
from google.generativeai.types.model_types import *
24+
from google.generativeai.types.permission_types import *
2425
from google.generativeai.types.safety_types import *
2526
from google.generativeai.types.text_types import *
2627

google/generativeai/types/permission_types.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from google.generativeai.utils import flatten_update_paths
2929
from google.generativeai import string_utils
3030

31+
__all__ = ["Permission", "Permissions"]
3132

3233
GranteeType = protos.Permission.GranteeType
3334
Role = protos.Permission.Role
@@ -89,7 +90,7 @@ def valid_id(name: str) -> bool:
8990

9091

9192
@string_utils.prettyprint
92-
@dataclasses.dataclass
93+
@dataclasses.dataclass(init=False)
9394
class Permission:
9495
"""
9596
A permission to access a resource.
@@ -100,6 +101,24 @@ class Permission:
100101
grantee_type: Optional[GranteeType]
101102
email_address: Optional[str] = None
102103

104+
def __init__(
105+
self,
106+
name: str,
107+
role: RoleOptions,
108+
grantee_type: Optional[GranteeTypeOptions] = None,
109+
email_address: Optional[str] = None,
110+
):
111+
self.name = name
112+
if role is None:
113+
self.role = None
114+
else:
115+
self.role = to_role(role)
116+
if grantee_type is None:
117+
self.grantee_type = None
118+
else:
119+
self.grantee_type = to_grantee_type(grantee_type)
120+
self.email_address = email_address
121+
103122
def delete(
104123
self,
105124
client: glm.PermissionServiceClient | None = None,
@@ -279,6 +298,12 @@ def _make_create_permission_request(
279298
f"Invalid operation: An 'email_address' must be provided when 'grantee_type' is not set to 'EVERYONE'. Currently, 'grantee_type' is set to '{grantee_type}' and 'email_address' is '{email_address if email_address else 'not provided'}'."
280299
)
281300

301+
if email_address and grantee_type is None:
302+
if email_address.endswith("googlegroups.com"):
303+
grantee_type = GranteeType.GROUP
304+
else:
305+
grantee_type = GranteeType.USER
306+
282307
permission = protos.Permission(
283308
role=role,
284309
grantee_type=grantee_type,
@@ -367,6 +392,9 @@ def list(
367392
permission = type(permission).to_dict(permission)
368393
yield Permission(**permission)
369394

395+
def __iter__(self):
396+
return self.list()
397+
370398
async def list_async(
371399
self,
372400
page_size: Optional[int] = None,
@@ -385,6 +413,35 @@ async def list_async(
385413
permission = type(permission).to_dict(permission)
386414
yield Permission(**permission)
387415

416+
async def __aiter__(self):
417+
return self.list_async()
418+
419+
@classmethod
420+
def get(cls, name: str) -> Permission:
421+
"""
422+
Get information about a specific permission.
423+
424+
Args:
425+
name: The name of the permission to get.
426+
427+
Returns:
428+
Requested permission as an instance of `Permission`.
429+
"""
430+
return Permission.get(name)
431+
432+
@classmethod
433+
async def get_async(cls, name: str) -> Permission:
434+
"""
435+
Get information about a specific permission.
436+
437+
Args:
438+
name: The name of the permission to get.
439+
440+
Returns:
441+
Requested permission as an instance of `Permission`.
442+
"""
443+
return await Permission.get_async(name)
444+
388445
def transfer_ownership(
389446
self,
390447
email_address: str,

samples/increment_tuning_data.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"text_input": "1",
4+
"output": "2"
5+
},
6+
{
7+
"text_input": "3",
8+
"output": "4"
9+
},
10+
{
11+
"text_input": "-3",
12+
"output": "-2"
13+
},
14+
{
15+
"text_input": "twenty two",
16+
"output": "twenty three"
17+
},
18+
{
19+
"text_input": "two hundred",
20+
"output": "two hundred one"
21+
},
22+
{
23+
"text_input": "ninety nine",
24+
"output": "one hundred"
25+
},
26+
{
27+
"text_input": "8",
28+
"output": "9"
29+
},
30+
{
31+
"text_input": "-98",
32+
"output": "-97"
33+
},
34+
{
35+
"text_input": "1,000",
36+
"output": "1,001"
37+
},
38+
{
39+
"text_input": "10,100,000",
40+
"output": "10,100,001"
41+
},
42+
{
43+
"text_input": "thirteen",
44+
"output": "fourteen"
45+
},
46+
{
47+
"text_input": "eighty",
48+
"output": "eighty one"
49+
},
50+
{
51+
"text_input": "one",
52+
"output": "two"
53+
},
54+
{
55+
"text_input": "three",
56+
"output": "four"
57+
},
58+
{
59+
"text_input": "seven",
60+
"output": "eight"
61+
}
62+
]

0 commit comments

Comments
 (0)