fix: back to top button, side navigation
This commit is contained in:
1 parent
762a2d0f66
commit
9eeb82ed89
6 files changed
+744
-186
No files matched your search
+25
-10
@@ -122,30 +122,44 @@ $systemPrompt .= "4. Do not make up facts or external projects not listed in the
|
||||
$systemPrompt .= "5. Format your output using simple markdown (like bolding or bullet points) to make it readable.\n";
|
||||
|
||||
// Map chat history
|
||||
// Map chat history and prepend system instructions to the first user message
|
||||
$contents = [];
|
||||
if (isset($inputData['history']) && is_array($inputData['history'])) {
|
||||
foreach ($inputData['history'] as $msg) {
|
||||
$firstMsgPrepended = false;
|
||||
|
||||
if (isset($inputData['history']) && is_array($inputData['history']) && !empty($inputData['history'])) {
|
||||
foreach ($inputData['history'] as $index => $msg) {
|
||||
if (isset($msg['role']) && isset($msg['text'])) {
|
||||
$role = ($msg['role'] === 'user') ? 'user' : 'model';
|
||||
$text = $msg['text'];
|
||||
|
||||
// Prepend system prompt to the first user message in history
|
||||
if (!$firstMsgPrepended && $role === 'user') {
|
||||
$text = "System Context & Instructions:\n" . $systemPrompt . "\n\nUser Message: " . $text;
|
||||
$firstMsgPrepended = true;
|
||||
}
|
||||
|
||||
$contents[] = [
|
||||
'role' => $role,
|
||||
'parts' => [['text' => $msg['text']]]
|
||||
'parts' => [['text' => $text]]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add the current user message
|
||||
|
||||
// Add the current user message (prepend system instructions if history was empty)
|
||||
$currentUserText = $userMessage;
|
||||
if (!$firstMsgPrepended) {
|
||||
$currentUserText = "System Context & Instructions:\n" . $systemPrompt . "\n\nUser Message: " . $userMessage;
|
||||
}
|
||||
|
||||
$contents[] = [
|
||||
'role' => 'user',
|
||||
'parts' => [['text' => $userMessage]]
|
||||
'parts' => [['text' => $currentUserText]]
|
||||
];
|
||||
|
||||
// Setup request body
|
||||
// Setup request body without systemInstruction key
|
||||
$requestPayload = [
|
||||
'contents' => $contents,
|
||||
'systemInstruction' => [
|
||||
'parts' => [['text' => $systemPrompt]]
|
||||
],
|
||||
'generationConfig' => [
|
||||
'temperature' => 0.7,
|
||||
'maxOutputTokens' => 800
|
||||
@@ -153,7 +167,7 @@ $requestPayload = [
|
||||
];
|
||||
|
||||
// Call Gemini API via cURL
|
||||
$url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=" . urlencode($apiKey);
|
||||
$url = "https://generativelanguage.googleapis.com/v1/models/gemini-3.5-flash:generateContent?key=" . urlencode($apiKey);
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
@@ -161,6 +175,7 @@ curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestPayload));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
Reference in new issue
Block a user