6
6
7
7
use GeminiAPI \Enums \MimeType ;
8
8
use GeminiAPI \Enums \Role ;
9
+ use GeminiAPI \Resources \Parts \FilePart ;
9
10
use GeminiAPI \Traits \ArrayTypeValidator ;
10
11
use GeminiAPI \Resources \Parts \ImagePart ;
11
12
use GeminiAPI \Resources \Parts \PartInterface ;
@@ -40,6 +41,13 @@ public function addImage(MimeType $mimeType, string $image): self
40
41
return $ this ;
41
42
}
42
43
44
+ public function addFile (MimeType $ mimeType , string $ file ): self
45
+ {
46
+ $ this ->parts [] = new FilePart ($ mimeType , $ file );
47
+
48
+ return $ this ;
49
+ }
50
+
43
51
public static function text (
44
52
string $ text ,
45
53
Role $ role = Role::User,
@@ -65,6 +73,19 @@ public static function image(
65
73
);
66
74
}
67
75
76
+ public static function file (
77
+ MimeType $ mimeType ,
78
+ string $ file ,
79
+ Role $ role = Role::User
80
+ ): self {
81
+ return new self (
82
+ [
83
+ new FilePart ($ mimeType , $ file ),
84
+ ],
85
+ $ role ,
86
+ );
87
+ }
88
+
68
89
public static function textAndImage (
69
90
string $ text ,
70
91
MimeType $ mimeType ,
@@ -80,6 +101,21 @@ public static function textAndImage(
80
101
);
81
102
}
82
103
104
+ public static function textAndFile (
105
+ string $ text ,
106
+ MimeType $ mimeType ,
107
+ string $ file ,
108
+ Role $ role = Role::User,
109
+ ): self {
110
+ return new self (
111
+ [
112
+ new TextPart ($ text ),
113
+ new FilePart ($ mimeType , $ file ),
114
+ ],
115
+ $ role ,
116
+ );
117
+ }
118
+
83
119
/**
84
120
* @param array{
85
121
* parts: array<int, array{text?: string, inlineData?: array{mimeType: string, data: string}}>,
@@ -97,7 +133,7 @@ public static function fromArray(array $content): self
97
133
98
134
if (!empty ($ part ['inlineData ' ])) {
99
135
$ mimeType = MimeType::from ($ part ['inlineData ' ]['mimeType ' ]);
100
- $ parts [] = new ImagePart ($ mimeType , $ part ['inlineData ' ]['data ' ]);
136
+ $ parts [] = new FilePart ($ mimeType , $ part ['inlineData ' ]['data ' ]);
101
137
}
102
138
}
103
139
0 commit comments