Skip to content

Commit

Permalink
🐛 Fix chat validation about new chatgpt
Browse files Browse the repository at this point in the history
  • Loading branch information
luoshuijs committed Mar 27, 2024
1 parent d784741 commit 8927ec3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
25 changes: 23 additions & 2 deletions crates/openai/src/serve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use std::str::FromStr;
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tower_http::trace;
use tracing::Level;
use tracing::{Instrument, Level};
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

Expand Down Expand Up @@ -185,7 +185,8 @@ impl Serve {
.route("/auth/revoke_token", post(post_revoke_token))
.route("/auth/refresh_session", post(post_refresh_session))
.route("/auth/sess_token", post(post_sess_token))
.route("/auth/billing", post(post_billing));
.route("/auth/billing", post(post_billing))
.route("/v2/*path", any(arkos_static));

let router = router::config(
// Enable arkose token endpoint proxy
Expand Down Expand Up @@ -509,3 +510,23 @@ async fn check_wan_address() {
}
}
}

async fn arkos_static(path: Path<String>) -> Result<Response<Body>, ResponseError> {
let client = with_context!(api_client);
let data = client
.get(format!(
"{}/v2/{}",
arkose::Type::GPT4.origin_url(),
path.0.as_str()
))
.send()
.await?;
let mut builder = Response::builder().status(data.status());
for (key, value) in data.headers().iter() {
builder = builder.header(key, value);
}
let content = data.bytes().await?;
builder
.body(content.into())
.map_err(ResponseError::InternalServerError)
}
3 changes: 3 additions & 0 deletions crates/openai/src/serve/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ pub(crate) fn header_convert(
.map_err(ResponseError::InternalServerError)?,
);

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

jar.iter()
.filter(|c| {
let name = c.name().to_lowercase();
Expand Down
10 changes: 6 additions & 4 deletions crates/openai/src/serve/proxy/req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde_json::{json, Value};
use crate::arkose::{ArkoseContext, ArkoseToken, Type};
use crate::constant::{ARKOSE_TOKEN, EMPTY, MODEL, NULL, PUID};
use crate::gpt_model::GPTModel;
use crate::{arkose, info, warn, with_context};
use crate::{arkose, debug, warn, with_context};

use super::ext::{RequestExt, ResponseExt, SendRequestExt};
use super::header_convert;
Expand Down Expand Up @@ -127,9 +127,11 @@ async fn handle_conv_request(req: &mut RequestExt) -> Result<(), ResponseError>
header::HeaderValue::from_str(chat_requirements_token.as_str())
.map_err(ResponseError::BadRequest)?,
);
info!("Chat requirements token: {}", chat_requirements_token.as_str())
}
else {
debug!(
"Chat requirements token: {}",
chat_requirements_token.as_str()
)
} else {
warn!("Chat requirements token not found")
}

Expand Down

0 comments on commit 8927ec3

Please sign in to comment.