Deploy 14a0f86 from main
This commit is contained in:
@@ -90,15 +90,15 @@ class PSA_OpenRouter {
|
||||
array(
|
||||
'timeout' => 120,
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $api_key,
|
||||
'HTTP-Referer' => $site_url,
|
||||
'X-Title' => $site_name,
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $api_key,
|
||||
'HTTP-Referer' => $site_url,
|
||||
'X-Title' => $site_name,
|
||||
),
|
||||
'body' => wp_json_encode(
|
||||
'body' => wp_json_encode(
|
||||
array(
|
||||
'model' => $model,
|
||||
'messages' => array(
|
||||
'model' => $model,
|
||||
'messages' => array(
|
||||
array(
|
||||
'role' => 'system',
|
||||
'content' => 'You are a scientific database assistant. Return only valid JSON.',
|
||||
@@ -108,8 +108,8 @@ class PSA_OpenRouter {
|
||||
'content' => $prompt,
|
||||
),
|
||||
),
|
||||
'max_tokens' => $max_tokens,
|
||||
'temperature' => 0.3,
|
||||
'max_tokens' => $max_tokens,
|
||||
'temperature' => 0.3,
|
||||
)
|
||||
),
|
||||
)
|
||||
@@ -147,10 +147,10 @@ class PSA_OpenRouter {
|
||||
}
|
||||
|
||||
// Log API call with token usage.
|
||||
$response_text = $body['choices'][0]['message']['content'];
|
||||
$prompt_tokens = (int) ( $body['usage']['prompt_tokens'] ?? 0 );
|
||||
$response_text = $body['choices'][0]['message']['content'];
|
||||
$prompt_tokens = (int) ( $body['usage']['prompt_tokens'] ?? 0 );
|
||||
$completion_tokens = (int) ( $body['usage']['completion_tokens'] ?? 0 );
|
||||
$token_source = 'api';
|
||||
$token_source = 'api';
|
||||
|
||||
// Diagnostic: log the raw usage structure once per model so we can verify
|
||||
// whether the provider returns token counts. Remove after confirming.
|
||||
@@ -172,14 +172,14 @@ class PSA_OpenRouter {
|
||||
|
||||
PSA_Cost_Tracker::log_api_call(
|
||||
array(
|
||||
'provider' => 'openrouter',
|
||||
'model' => $model,
|
||||
'prompt_tokens' => $prompt_tokens,
|
||||
'completion_tokens' => $completion_tokens,
|
||||
'request_type' => $request_type,
|
||||
'peptide_name' => $peptide_name,
|
||||
'success' => true,
|
||||
'token_source' => $token_source,
|
||||
'provider' => 'openrouter',
|
||||
'model' => $model,
|
||||
'prompt_tokens' => $prompt_tokens,
|
||||
'completion_tokens' => $completion_tokens,
|
||||
'request_type' => $request_type,
|
||||
'peptide_name' => $peptide_name,
|
||||
'success' => true,
|
||||
'token_source' => $token_source,
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user