Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,20 @@ function handleVoiceCommand(command) {
const POLLINATIONS_TEXT_URL = 'https://text.pollinations.ai/openai';
const UNITY_REFERRER = 'https://www.unityailab.com/';

function shouldUseUnityReferrer() {
if (typeof window === 'undefined') {
return true;
}

try {
const unityOrigin = new URL(UNITY_REFERRER).origin;
return window.location.origin === unityOrigin;
} catch (error) {
console.error('Failed to parse UNITY_REFERRER:', error);
return false;
}
}

async function getAIResponse(userInput) {
console.log(`Sending to AI: ${userInput}`);

Expand All @@ -434,6 +448,20 @@ async function getAIResponse(userInput) {
try {
const messages = [{ role: 'system', content: systemPrompt }, ...chatHistory];

const pollinationsPayload = JSON.stringify({
messages,
model: 'unity'
});

const useUnityReferrer = shouldUseUnityReferrer();

if (!useUnityReferrer) {
console.warn(
'Pollinations referrer header disabled because the app is not '
+ 'being served from https://www.unityailab.com/'
);
}

const textResponse = await fetch(POLLINATIONS_TEXT_URL, {
method: 'POST',
headers: {
Expand All @@ -444,10 +472,13 @@ async function getAIResponse(userInput) {
// approved web client even when running the app from localhost.
referrer: UNITY_REFERRER,
referrerPolicy: 'strict-origin-when-cross-origin',
body: JSON.stringify({
messages,
model: 'unity'
})
body: pollinationsPayload,
...(useUnityReferrer
? {}
: {
referrer: 'no-referrer',
referrerPolicy: 'no-referrer'
})
});

if (!textResponse.ok) {
Expand Down
2 changes: 2 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
}

#background {
Expand Down