-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathasticaGPT_sample.html
More file actions
199 lines (168 loc) · 11.3 KB
/
Copy pathasticaGPT_sample.html
File metadata and controls
199 lines (168 loc) · 11.3 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<html>
<head>
<title>asticaGPT: NLP Generate - Javascript Client API</title>
<link rel="apple-touch-icon" sizes="180x180" href="asset/img/favi/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="asset/img/favi/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="asset/img/favi/favicon-16x16.png">
<!-- include astica javascript api sdk version 2024-01-31 -->
<script src="https://astica.ai/javascript-sdk/2024-01-31/astica.api.js"></script>
</head>
<body>
<h1><a href="https://astica.ai/?fr=gpt-jsapi"><img src="asset/img/icon.png" id="astica_icon_head"></a> asticaVoice: GPT-S Generate - Javascript Client API</h1>
<a href="https://astica.ai/code-examples/javascript-API/asticaVision_sample.html" title="asticaVision - Describe Images" class="explore_astica">asticaVision</a>
<a href="https://astica.ai/code-examples/javascript-API/asticaDesign_sample.html" title="asticaDesign - Generate Images" class="explore_astica">asticaDesign</a>
<a href="https://astica.ai/code-examples/javascript-API/asticaListen_sample.html" title="asticListen - Speech to Text" class="explore_astica">asticaListen</a>
<a href="https://astica.ai/code-examples/javascript-API/asticaVoice_sample.html" title="asticVoice - Text to Speech" class="explore_astica">asticaVoice</a>
<a href="https://astica.ai/code-examples/javascript-API/asticaGPT_sample.html" title="asticGPT - NLP GPT-S" class="explore_astica explore_astica_active">asticaGPT</a>
<hr style="margin-top:15px;">
<label for="astica_ML_apikey"><b>Step 1:</b> API Key <a href="https://astica.ai/" target="_blank" title="Get API Key" style="font-size:12px; margin-left: 15px;">Obtain your API Key</a></label>
<input type="text" id="astica_ML_apikey" placeholder="Enter your API Key" value="">
<label for="astica_ML_apikey"><b>Step 2:</b> Choose Model Version</label>
<select id="astica_ML_version">
<option value="GPT-S2">GPT-S</option>
</select>
<label for=""><b>Step 3:</b> Parameters </label>
<div class="col-sm-6" style="">
<label class="bs-tooltip" title="Determines how much content asticaGPT will produce" style="font-weight:bold;">Response Length <sup><i class="fa fa-question-circle"></i></sup></label>
<div class="input-group mb-4 ">
<input id="astica_ML_tokens_max" onchange="asticaGPT_ChangeSlider('tokens_max');" oninput="asticaGPT_ChangeSlider('tokens_max');" class="" min="20" max="1000" value="55" step="10" type="range" />
<output class="astica_ML_tokens_max_label" for="astica_ML_tokens_max"><span>55 Max Tokens</span></output>
</div>
</div>
<div class="col-sm-6" style="">
<label class="bs-tooltip" title="Determines how much content asticaGPT will produce" style="font-weight:bold;">Temperature <sup><i class="fa fa-question-circle"></i></sup></label>
<div class="input-group mb-4 ">
<input id="astica_ML_temperature" onchange="asticaGPT_ChangeSlider('temperature');" oninput="asticaGPT_ChangeSlider('temperature');" class="" min="0" max="1.5" value="0.7" step="0.1" type="range" />
<output class="astica_ML_temperature_label" for="astica_ML_temperature"><span>0.7 Temperature</span></output>
</div>
</div>
<div class="col-sm-6" style="">
<label class="bs-tooltip" title="Determines how much content asticaGPT will produce" style="font-weight:bold;">Top P <sup><i class="fa fa-question-circle"></i></sup></label>
<div class="input-group mb-4 ">
<input id="astica_ML_top_p" onchange="asticaGPT_ChangeSlider('top_p');" oninput="asticaGPT_ChangeSlider('top_p');" class="" min="0" max="1.5" value="0.35" step="0.1" type="range" />
<output class="astica_ML_top_p_label" for="astica_ML_top_p"><span>0.35 Top P</span></output>
</div>
</div>
<label for="astica_ML_think_pass">Number of Think Pass</label>
<select id="astica_ML_think_pass" style="max-width:90px;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label for="astica_ML_stream_output">Stream Output (real-time generation)</label>
<select id="astica_ML_stream_output" style="max-width:90px;">
<option value="0">0</option>
<option value="1" selected>1</option>
</select>
<label for="astica_ML_stop_sequence">Stop Sequence <small>(Comma separated)</small></label>
<input type="text" id="astica_ML_stop_sequence" placeholder="Human:,AI:" value="">
<label for="astica_ML_gpt_instruction"><b>Step 4:</b> Optional Instruction</label>
<textarea id="astica_ML_gpt_instruction" style="min-height:55px;" placeholder="Optional context for prompt"></textarea>
<label for="astica_ML_gpt_input"><b>Step 5:</b> Enter Prompt</label>
<textarea id="astica_ML_gpt_input" style="min-height:45px;" placeholder="Enter your GPT-S prompt here..">Write a sentence about the iphone 12:</textarea>
<button id="astica_demoSubmit" onclick="asticaGPT_Example();">Generate</button>
<label for="astica_ML_gpt_output"><b>GPT-S Output:</b></label>
<textarea id="astica_ML_gpt_output" style="min-height:75px;width:550px;" placeholder="Result of your GPT prompt will appear here.."></textarea>
<script>
function asticaGPT_Example() {
if(document.getElementById("astica_ML_apikey").value == '') {
alert("Please provide your astica.org API key");
return;
}
asticaAPI_start(document.getElementById("astica_ML_apikey").value); //only needs to be called once
$('#astica_ML_gpt_output').val('Loading..')
var asticaGPT_params = {
instruction:document.getElementById("astica_ML_gpt_instruction").value,
temperature:document.getElementById("astica_ML_temperature").value,
top_p:document.getElementById("astica_ML_top_p").value,
think_pass:document.getElementById("astica_ML_think_pass").value,
stop_sequence:document.getElementById("astica_ML_stop_sequence").value,
stream_output: document.getElementById("astica_ML_stream_output").value
}
asticaGPT(
document.getElementById("astica_ML_version").value,
document.getElementById("astica_ML_gpt_input").value,
document.getElementById("astica_ML_tokens_max").value,
asticaGPT_params
);
document.getElementById("astica_demoSubmit").disabled = true;
setTimeout(function() {
document.getElementById("astica_demoSubmit").disabled = false;
}, 2000);
}
function asticaGPT_generateComplete(data){
console.log(data);
if(typeof data.error != 'undefined') { alert(data.error); return; }
$('#astica_ML_gpt_output').val(data.output)
}
function asticaGPT_generatePreview(data){
console.log(data);
if(typeof data.error != 'undefined') { alert(data.error); }
$('#astica_ML_gpt_output').val(data.output)
}
//for demo ui
function asticaGPT_ChangeSlider(input_title) {
var postFix = '';
if(input_title == 'tokens_max') { postFix = ' Max Tokens';}
if(input_title == 'temperature') { postFix = ' Temperature';}
if(input_title == 'top_p') { postFix = ' Top P';}
$('.astica_ML_'+input_title+'_label').html($('#astica_ML_'+input_title).val()+''+postFix);
}
</script>
<hr><h2 style="margin-top:40px;"><h2>asticaGPT - NLP Usage:</h2>
<div style="margin-bottom:5px;">
<a href="https://astica.ai/nlp/documentation/" target="_blank" title="astica GPT-S API Documentation" style="font-size:16px;">View astica GPT-S API Documentation</a>
</div>
<pre><script src="<span class="color-lightblue bold">https://astica.ai/javascript-sdk/2024-01-31/astica.api.js</span>"></script>
<script>
asticaAPI_start('API KEY HERE'); //only needs to be called once.
//Simple Usage:
asticaGPT("Write a sentence about apples:")
//With Token Limit:
asticaGPT("Write a sentence about apples:", 10)
//Advanced:
var asticaGPT_params = {
instruction:document.getElementById("astica_ML_temperature").value,
temperature:document.getElementById("astica_ML_temperature").value,
top_p:document.getElementById("astica_ML_top_p").value,
think_pass:document.getElementById("astica_ML_think_pass").value,
stop_sequence:document.getElementById("astica_ML_stop_sequence").value,
stream_output: document.getElementById("astica_ML_stream_output").value
}
asticaGPT(
document.getElementById("astica_ML_version").value,
document.getElementById("astica_ML_gpt_input").value,
document.getElementById("astica_ML_tokens_max").value,
asticaGPT_params
);
//default asticaGPT callbacks
function asticaGPT_generateComplete(data){
console.log(data);
if(typeof data.error != 'undefined') { alert(data.error); }
$('#your_div').val(data.output)
//optional text to speech with asticaVoice:
asticaVoice(data.output);
}
function asticaGPT_generatePreview(data){
console.log(data);
if(typeof data.error != 'undefined') { alert(data.error); return; }
$('#your_div').val(data.output)
}
//Plug and play example:
function asticaGPT_example(string, tokens) {
asticaGPT(string, tokens)
}
setTimeout(function() {
asticaAPI_start('API KEY HERE'); //only needs to be called once.
asticaGPT_example('Write a sentence about apples:', 55); //max 55 tokens
}, 1000);
</script>
</pre>
<!--- Demo assets; non-API related --->
<link href="https://fonts.googleapis.com/css?family=Quicksand:400,500,600,700&display=swap" rel="stylesheet">
<a href="https://www.astica.org/?fr=voice-speak"><img src="asset/img/icon.png" id="astica_icon"></a>
<link href="asset/css/style.css" rel="stylesheet">
<link href="asset/js/demo.js" rel="stylesheet">
</body>
</html>