(&self, request: ChatRequest)
| 98 | } |
| 99 | |
| 100 | fn convert_request(&self, request: ChatRequest) -> GoogleRequest { |
| 101 | let mut contents = Vec::new(); |
| 102 | let mut system_instruction = None; |
| 103 | |
| 104 | for msg in request.messages { |
| 105 | match msg.role { |
| 106 | Role::System => { |
| 107 | if let Content::Text(text) = msg.content { |
| 108 | system_instruction = Some(GoogleContent { |
| 109 | parts: vec![GooglePart::text(&text)], |
| 110 | role: "user".to_string(), |
| 111 | }); |
| 112 | } |
| 113 | } |
| 114 | Role::User => { |
| 115 | let text_content = match &msg.content { |
| 116 | Content::Text(t) => t.clone(), |
| 117 | Content::Parts(parts) => parts |
| 118 | .iter() |
| 119 | .filter_map(|p| p.text.clone()) |
| 120 | .collect::<Vec<_>>() |
| 121 | .join(" "), |
| 122 | }; |
| 123 | contents.push(GoogleContent { |
| 124 | parts: vec![GooglePart::text(&text_content)], |
| 125 | role: "user".to_string(), |
| 126 | }); |
| 127 | } |
| 128 | Role::Assistant => { |
| 129 | let text_content = match &msg.content { |
| 130 | Content::Text(t) => t.clone(), |
| 131 | Content::Parts(parts) => parts |
| 132 | .iter() |
| 133 | .filter_map(|p| p.text.clone()) |
| 134 | .collect::<Vec<_>>() |
| 135 | .join(" "), |
| 136 | }; |
| 137 | contents.push(GoogleContent { |
| 138 | parts: vec![GooglePart::text(&text_content)], |
| 139 | role: "model".to_string(), |
| 140 | }); |
| 141 | } |
| 142 | Role::Tool => {} |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | GoogleRequest { |
| 147 | contents, |
| 148 | system_instruction, |
| 149 | generation_config: Some(GenerationConfig { |
| 150 | max_output_tokens: request.max_tokens, |
| 151 | temperature: request.temperature, |
| 152 | }), |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | #[async_trait] |
no test coverage detected