66
77use GeminiAPI \Enums \MimeType ;
88use GeminiAPI \Enums \Role ;
9+ use GeminiAPI \Resources \Parts \FilePart ;
910use GeminiAPI \Traits \ArrayTypeValidator ;
1011use GeminiAPI \Resources \Parts \ImagePart ;
1112use GeminiAPI \Resources \Parts \PartInterface ;
@@ -40,6 +41,13 @@ public function addImage(MimeType $mimeType, string $image): self
4041 return $ this ;
4142 }
4243
44+ public function addFile (MimeType $ mimeType , string $ file ): self
45+ {
46+ $ this ->parts [] = new FilePart ($ mimeType , $ file );
47+
48+ return $ this ;
49+ }
50+
4351 public static function text (
4452 string $ text ,
4553 Role $ role = Role::User,
@@ -65,6 +73,19 @@ public static function image(
6573 );
6674 }
6775
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+
6889 public static function textAndImage (
6990 string $ text ,
7091 MimeType $ mimeType ,
@@ -80,6 +101,21 @@ public static function textAndImage(
80101 );
81102 }
82103
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+
83119 /**
84120 * @param array{
85121 * parts: array<int, array{text?: string, inlineData?: array{mimeType: string, data: string}}>,
@@ -97,7 +133,7 @@ public static function fromArray(array $content): self
97133
98134 if (!empty ($ part ['inlineData ' ])) {
99135 $ mimeType = MimeType::from ($ part ['inlineData ' ]['mimeType ' ]);
100- $ parts [] = new ImagePart ($ mimeType , $ part ['inlineData ' ]['data ' ]);
136+ $ parts [] = new FilePart ($ mimeType , $ part ['inlineData ' ]['data ' ]);
101137 }
102138 }
103139
0 commit comments