@@ -104,62 +104,35 @@ <h4 style="font-size: 18px; margin: 0; color: #c0c0ff;">🤖 Forum AI: ChatGPT A
104
104
</ style >
105
105
106
106
< script >
107
- const apiKey = "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" ; // Your provided API key
108
-
109
- document . getElementById ( "askButton" ) . addEventListener ( "click" , async function ( ) {
107
+ document . getElementById ( "askButton" ) . addEventListener ( "click" , async function ( ) {
110
108
const query = document . getElementById ( "userQuery" ) . value ;
111
109
if ( query . trim ( ) === "" ) {
112
- alert ( "Please ask a question!" ) ;
113
- return ;
110
+ alert ( "Please ask a question!" ) ;
111
+ return ;
114
112
}
115
113
116
114
document . getElementById ( "responseBox" ) . style . display = "block" ;
117
115
document . getElementById ( "responseContent" ) . textContent = "Processing..." ;
118
116
119
117
try {
120
- const res = await fetch ( "https://api.openai.com/v1/chat/completions" , { // Updated endpoint for GPT-4 or GPT-3.5
121
- method : "POST" ,
122
- headers : {
123
- "Content-Type" : "application/json" ,
124
- "Authorization" : `Bearer ${ apiKey } ` ,
125
- } ,
126
- body : JSON . stringify ( {
127
- model : "gpt-4" , // or "gpt-3.5-turbo"
128
- messages : [ { role : "user" , content : query } ] ,
129
- max_tokens : 100 ,
130
- temperature : 0.7 ,
131
- } ) ,
132
- } ) ;
133
-
134
- const data = await res . json ( ) ;
135
- const answer = data . choices [ 0 ] . message . content . trim ( ) ;
136
- document . getElementById ( "responseContent" ) . textContent = answer ;
137
-
118
+ const res = await fetch ( "https://api.pollinations.ai/" , {
119
+ method : "POST" ,
120
+ headers : {
121
+ "Content-Type" : "application/json" ,
122
+ } ,
123
+ body : JSON . stringify ( {
124
+ model : "openai-large" , // or other available models if specified by Pollinations
125
+ messages : [ { role : "user" , content : query } ] ,
126
+ } ) ,
127
+ } ) ;
128
+
129
+ const data = await res . json ( ) ;
130
+ const answer = data . choices [ 0 ] . message . content . trim ( ) ;
131
+ document . getElementById ( "responseContent" ) . textContent = answer ;
138
132
} catch ( err ) {
139
- console . error ( err ) ;
140
- document . getElementById ( "responseContent" ) . textContent = "Oops, something went wrong!" ;
133
+ console . error ( err ) ;
134
+ document . getElementById ( "responseContent" ) . textContent = "Oops, something went wrong!" ;
141
135
}
142
- } ) ;
143
-
144
- document . addEventListener ( 'DOMContentLoaded' , function ( ) {
145
- const floatingButton = document . getElementById ( 'floatingButton' ) ;
146
- const widgetContainer = document . getElementById ( 'widgetContainer' ) ;
147
- const closeWidgetButton = document . getElementById ( 'closeWidgetButton' ) ;
148
-
149
- floatingButton . addEventListener ( 'click' , function ( ) {
150
- widgetContainer . style . display = 'block' ; // Show the widget
151
- } ) ;
152
-
153
- closeWidgetButton . addEventListener ( 'click' , function ( ) {
154
- widgetContainer . style . display = 'none' ; // Hide the widget
155
- } ) ;
156
-
157
- // Optional: Close the widget if the user clicks outside of it
158
- window . addEventListener ( 'click' , function ( event ) {
159
- if ( event . target === widgetContainer ) {
160
- widgetContainer . style . display = 'none' ;
161
- }
162
- } ) ;
163
136
} ) ;
164
-
137
+
165
138
</ script >
0 commit comments