@@ -63,7 +63,7 @@ public function getEmbeddingsEndpoint(?string $model = null) : string
6363 throw new Exception ("Missing Gemini Token " );
6464 }
6565
66- return "https://generativelanguage.googleapis.com/ " . $ this ->getVersion () . "/models/ " . $ this ->getModel ($ model ) . ":embedText ?key= {$ apiKey }" ;
66+ return "https://generativelanguage.googleapis.com/ " . $ this ->getVersion () . "/models/ " . $ this ->getModel ($ model ) . ":embedContent ?key= {$ apiKey }" ;
6767 }
6868
6969 public function prepareRequest (array $ payload ) : array
@@ -84,7 +84,6 @@ public function formatUserMessage(string $prompt): array
8484 ];
8585 }
8686
87-
8887 public function formatAssistantMessage (mixed $ message , ?string $ messageType = null ): array
8988 {
9089 return [
@@ -119,33 +118,25 @@ public function buildConversation(array $previousMessages, string $prompt, ?stri
119118 ];
120119 }
121120
122- public function normalizeResponse (array $ raw ): array
121+ public function normalizeCompletionsResponse (array $ raw ): array
123122 {
124123 $ assistantText = null ;
125124 $ functionCalls = [];
126125 $ rawFunctionMessages = [];
127126
128127 if (!empty ($ raw ['candidates ' ]) && is_array ($ raw ['candidates ' ])) {
129-
130128 foreach ($ raw ['candidates ' ] as $ candidate ) {
131-
132- // Gemini mette sempre role/parts qui
133129 if (!isset ($ candidate ['content ' ]['parts ' ])) {
134130 continue ;
135131 }
136132
137133 foreach ($ candidate ['content ' ]['parts ' ] as $ part ) {
138134
139- //
140- // 1) function_call (nome ufficiale) oppure functionCall (variante)
141- //
142135 $ fc = $ part ['function_call ' ]
143136 ?? $ part ['functionCall ' ]
144137 ?? null ;
145138
146139 if ($ fc ) {
147-
148- // normalizza args (stringa JSON → array)
149140 $ args = $ fc ['args ' ] ?? ($ fc ['arguments ' ] ?? []);
150141 if (is_string ($ args )) {
151142 $ decoded = json_decode ($ args , true );
@@ -154,23 +145,17 @@ public function normalizeResponse(array $raw): array
154145 }
155146 }
156147
157- // normalizzazione functionCalls per l'orchestrator
158148 $ functionCalls [] = [
159149 'name ' => $ fc ['name ' ] ?? null ,
160150 'args ' => $ args ?? []
161151 ];
162152
163- // 2) SALVO IL MESSAGGIO ORIGINALE (importantissimo)
164- // questo è ciò che Gemini vuole a history invariata
165153 $ rawFunctionMessages [] = [
166154 'role ' => 'model ' ,
167- 'parts ' => [$ part ] // il part contiene function_call originale
155+ 'parts ' => [$ part ]
168156 ];
169157 }
170158
171- //
172- // 3) assistant text
173- //
174159 if (isset ($ part ['text ' ])) {
175160 $ assistantText .= $ part ['text ' ];
176161 }
@@ -239,7 +224,19 @@ public function buildEmbeddingRequest(string $input, ?string $model = null): arr
239224 {
240225 return [
241226 'model ' => $ this ->getModel ($ model ),
242- 'text ' => $ input
227+ 'content ' => [
228+ 'parts ' => [[
229+ 'text ' => $ input
230+ ]]
231+ ]
232+ ];
233+ }
234+
235+ public function normalizeEmbeddingsResponse (array $ raw ) : array
236+ {
237+ return [
238+ 'embedding ' => $ raw ['embedding ' ]['values ' ] ?? [],
239+ 'raw ' => $ raw
243240 ];
244241 }
245242
0 commit comments