Skip to content
Draft
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ public/env-ob.json

Used for obfuscated environment configuration.

Because this is a static browser application, `API_KEY` must be a publishable
Pollinations key beginning with `pk_`. Never place an `sk_` secret key in this
file or any other client-side asset.

If modifying environment handling, see:

```
Expand Down
20 changes: 14 additions & 6 deletions src/pages/SimpleCite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { createSignal, Show, onMount, For } from 'solid-js';
import type { Component } from 'solid-js';
import { db } from '../db';
import type { Citation } from '../db';
import { getPollinationsApiKey, POLLINATIONS_TEXT_ENDPOINT } from '../utils/env';
import {
getPollinationsApiKey,
POLLINATIONS_TEXT_ENDPOINT,
POLLINATIONS_TEXT_MODEL,
} from '../utils/env';
import styles from './SimpleCite.module.css';

type Guideline = 'apa7' | 'mla9' | 'ieee' | 'chicago17';
Expand Down Expand Up @@ -743,12 +747,17 @@ const fetchMetadataViaAi = async (
if (!apiKey) {
throw new Error('Missing API key');
}
const query = new URLSearchParams({
model: POLLINATIONS_TEXT_MODEL,
json: 'true',
});
const llm = await fetch(
`${POLLINATIONS_TEXT_ENDPOINT}/${encodeURIComponent(prompt)}=gemini-fast?key=${
apiKey
}`,
`${POLLINATIONS_TEXT_ENDPOINT}/${encodeURIComponent(prompt)}?${query}`,
{
headers: { Accept: 'text/plain' },
headers: {
Accept: 'application/json',
Authorization: `Bearer ${apiKey}`,
},
},
);
if (!llm.ok) {
Expand Down Expand Up @@ -1684,4 +1693,3 @@ const SimpleCite: Component = () => {
export default SimpleCite;



18 changes: 14 additions & 4 deletions src/pages/SimpleSuite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { Editor } from 'mini-canvas-editor';
import 'mini-canvas-editor/css/editor.css';
import { db } from '../db';
import type { Drawing } from '../db';
import { getPollinationsApiKey, POLLINATIONS_TEXT_ENDPOINT } from '../utils/env';
import {
getPollinationsApiKey,
POLLINATIONS_TEXT_ENDPOINT,
POLLINATIONS_TEXT_MODEL,
} from '../utils/env';
import styles from './SimpleSuite.module.css';

export type SuiteTab = 'text' | 'files' | 'human' | 'draw';
Expand Down Expand Up @@ -303,12 +307,19 @@ ${localPass}`;
if (!apiKey) {
throw new Error('Missing API key');
}
const query = new URLSearchParams({ model: POLLINATIONS_TEXT_MODEL });
const response = await fetch(
`${POLLINATIONS_TEXT_ENDPOINT}/${encoded}=gemini-fast?key=${apiKey}`,
`${POLLINATIONS_TEXT_ENDPOINT}/${encoded}?${query}`,
{
headers: { Accept: 'text/plain' },
headers: {
Accept: 'text/plain',
Authorization: `Bearer ${apiKey}`,
},
},
);
if (!response.ok) {
throw new Error(`Pollinations request failed (${response.status})`);
}
const result = await response.text();
let trimmed = result.trim();

Expand Down Expand Up @@ -905,4 +916,3 @@ export const SimpleSuite: Component<SimpleSuiteProps> = (props) => {

export default SimpleSuite;


7 changes: 6 additions & 1 deletion src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare global {
}

export const POLLINATIONS_TEXT_ENDPOINT = 'https://gen.pollinations.ai/text';
export const POLLINATIONS_TEXT_MODEL = 'gemini-fast';

let envCache: Promise<Record<string, unknown>> | null = null;

Expand Down Expand Up @@ -34,7 +35,11 @@ export const getPollinationsApiKey = async () => {
try {
const env = await loadEnv();
const apiKey = env.API_KEY;
return typeof apiKey === 'string' ? apiKey : '';
if (typeof apiKey === 'string' && apiKey.startsWith('pk_')) {
return apiKey;
}
console.warn('Pollinations API key must be a browser-safe publishable key');
return '';
} catch (error) {
console.warn('Failed to load API key', error);
return '';
Expand Down