Skip to content

Commit

Permalink
🐛 Fix arkose token
Browse files Browse the repository at this point in the history
  • Loading branch information
luoshuijs committed Mar 27, 2024
1 parent 8927ec3 commit 0c5ae5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/openai/src/serve/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ pub(crate) fn header_convert(

h.get("openai-sentinel-chat-requirements-token")
.map(|v| headers.insert("openai-sentinel-chat-requirements-token", v.clone()));
h.get("openai-sentinel-arkose-token")
.map(|v| headers.insert("openai-sentinel-arkose-token", v.clone()));

jar.iter()
.filter(|c| {
Expand Down
16 changes: 15 additions & 1 deletion crates/openai/src/serve/proxy/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,15 @@ async fn handle_conv_request(req: &mut RequestExt) -> Result<(), ResponseError>
let condition = match body.get(ARKOSE_TOKEN) {
Some(s) => {
let s = s.as_str().unwrap_or(EMPTY);
s.is_empty() || s.eq(NULL)
let is_empty = s.is_empty() || s.eq(NULL);
if !is_empty {
req.headers.insert(
header::HeaderName::from_static("openai-sentinel-arkose-token"),
header::HeaderValue::from_str(s).map_err(ResponseError::BadRequest)?,
);
debug!("Sentinel arkose token: {}", s)
}
is_empty
}
None => true,
};
Expand All @@ -162,6 +170,12 @@ async fn handle_conv_request(req: &mut RequestExt) -> Result<(), ResponseError>
req.body = Some(Bytes::from(
serde_json::to_vec(&json).map_err(ResponseError::BadRequest)?,
));
req.headers.insert(
header::HeaderName::from_static("openai-sentinel-arkose-token"),
header::HeaderValue::from_str(arkose_token.value())
.map_err(ResponseError::BadRequest)?,
);
debug!("Sentinel arkose token: {}", arkose_token.value())
}
}

Expand Down

0 comments on commit 0c5ae5f

Please sign in to comment.