(&self, request: ChatRequest)
| 149 | } |
| 150 | |
| 151 | fn convert_request(&self, request: ChatRequest) -> CopilotRequest { |
| 152 | let messages: Vec<CopilotMessage> = request |
| 153 | .messages |
| 154 | .into_iter() |
| 155 | .map(|msg| CopilotMessage { |
| 156 | role: match msg.role { |
| 157 | Role::System => "system".to_string(), |
| 158 | Role::User => "user".to_string(), |
| 159 | Role::Assistant => "assistant".to_string(), |
| 160 | Role::Tool => "user".to_string(), |
| 161 | }, |
| 162 | content: match msg.content { |
| 163 | Content::Text(t) => CopilotContent::Text(t), |
| 164 | Content::Parts(parts) => { |
| 165 | let contents: Vec<CopilotContentPart> = parts |
| 166 | .into_iter() |
| 167 | .filter_map(|p| { |
| 168 | if let Some(text) = p.text { |
| 169 | Some(CopilotContentPart { |
| 170 | content_type: "text".to_string(), |
| 171 | text: Some(text), |
| 172 | image_url: p |
| 173 | .image_url |
| 174 | .map(|iu| CopilotImageUrl { url: iu.url }), |
| 175 | }) |
| 176 | } else if p.image_url.is_some() { |
| 177 | Some(CopilotContentPart { |
| 178 | content_type: "image_url".to_string(), |
| 179 | text: None, |
| 180 | image_url: p |
| 181 | .image_url |
| 182 | .map(|iu| CopilotImageUrl { url: iu.url }), |
| 183 | }) |
| 184 | } else { |
| 185 | None |
| 186 | } |
| 187 | }) |
| 188 | .collect(); |
| 189 | CopilotContent::Parts(contents) |
| 190 | } |
| 191 | }, |
| 192 | }) |
| 193 | .collect(); |
| 194 | |
| 195 | CopilotRequest { |
| 196 | model: request.model, |
| 197 | messages, |
| 198 | max_tokens: request.max_tokens, |
| 199 | temperature: request.temperature, |
| 200 | top_p: request.top_p, |
| 201 | stream: false, |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | fn responses_url(base_url: Option<&str>, path: &str) -> String { |
| 206 | let path = path.trim_start_matches('/'); |
no outgoing calls
no test coverage detected