Anthropic/OpenAI: Add country codes for territories (#17089)

- Cloudflare provides ISO-3166-1 country code for protectorates. Expand our allowlist to include the territories of countries on the allowlist (US, UK, France, Australia, New Zealand). 
- Also include the country_code in the error message when we block. 

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
Peter Tripp 2024-08-29 15:32:29 +00:00 committed by GitHub
parent 7db8d80c30
commit 4d6bb52d1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 2 deletions

View file

@ -85,7 +85,9 @@ fn authorize_access_for_country(
if !is_country_supported_by_provider {
Err(Error::http(
StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS,
format!("access to {provider:?} models is not available in your region"),
format!(
"access to {provider:?} models is not available in your region ({country_code})"
),
))?
}
@ -195,7 +197,7 @@ mod tests {
.to_vec();
assert_eq!(
String::from_utf8(response_body).unwrap(),
format!("access to {provider:?} models is not available in your region")
format!("access to {provider:?} models is not available in your region ({country_code})")
);
}
}