-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai.php
More file actions
115 lines (101 loc) · 3.24 KB
/
ai.php
File metadata and controls
115 lines (101 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?
error_reporting(E_ERROR | E_PARSE);
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
require_once($_SERVER['DOCUMENT_ROOT']."/shared_functions.php");
// Initialise le login
$connected=checklogin();
?>
<html>
<head>
<?writeHeadContent("EasyQR - ".T_("Gardez les liens"));?>
<style>
.showsource {color:#00A; cursor:pointer;}
.showsource:hover {text-decoration:underline;}
.source {display:none}
</style>
</head>
<body>
<?php
echo "<div style='position:fixed; top:0px; left:0px; right:0px; height:110px; padding:10px; background:#eee;'>";
echo "<form method='POST' style='text-align:center;'>";
echo "<input name='question' id='question' style='margin:auto;display:block; width:80%; padding:10px; border:1px solid #aaa; border-radius:10px;'>";
echo "<button style='padding:5px; margin-top:10px;'>Poser votre question</button>";
echo "</form>";
echo "</div>";
echo "<div style='padding:10px;padding-top:120px;'>";
if (isset($_POST["question"])) {
echo "<h3>Votre question:</h3>";
echo "<b>".$_POST["question"]."</b>";
// URL de l'API
$url = 'https://api.afforai.com/api/api_completion';
// Données à envoyer
$data = array(
'apiKey' => '2169c853-859c-4ae6-bd67-0d2fb7b9d36d',
'sessionID' => '65bce2ddd802e36355b8eb36',
'history' => array(
array(
'role' => 'user',
'content' => $_POST["question"]
)
),
'powerful' => true,
'google' => false
);
// Options pour la requête
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($data)
)
);
// Création du contexte de la requête
$context = stream_context_create($options);
// Exécution de la requête et récupération de la réponse
$response = json_decode(file_get_contents($url, false, $context));
echo "<h3>Ma réponse:</h3>";
// Affichage de la réponse
if ($response->success) {
$result = $response->output->completion;
// Remplacement des éléments en gras par les balises HTML correspondantes
$result = preg_replace('/\*\*(.*?)\*\*/', '<b>$1</b>', $result);
$result = preg_replace( '/【(\d+)†source】/', " <span class='showsource' data-src='$1'>(source<sup>$1</sup>)</span>", $result);
$result = str_replace("\n","<br>",$result);
echo $result;
echo "<h4>Sources:</h4>";
$old="";
foreach ($response->output->file_citations as $citation) {
if ($citation->name!=$old) {
if ($old!="") echo ", ";
echo $citation->name;
$old=$citation->name;
}
}
$i=1;
foreach ($response->output->file_citations as $citation) {
echo "<div id='source_".$i."' class='source'>";
echo "<div style='font-size:100%; font-weight:bold; margin-top:10px;'>".$i.". ".$citation->name."</div>";
echo "<div style='border:1px solid #aaa; padding:10px; font-size:80%'><b>Page ".$citation->page." : </b><br>".str_replace("\n","<br>",$citation->content)."</div>";
$i++;
echo "</div>";
}
foreach ($response->output->google_citations as $citation) {
echo "<div style=''><a href='".$citation->url."'>".$citation->name."</a></div>";
}
}
echo "<br><br>";
echo "<!--";
print_r ($response);
}
echo "-->";
?>
<script>
$(function() {
$(".showsource").click(function() {
$("#source_"+$(this).attr("data-src")).show();
});
});
</script>
</div>
</body>
</html>