hoarder-app / hoarder

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
https://hoarder.app
GNU Affero General Public License v3.0
6.56k stars 236 forks source link

Feature request: Perplexity.ai API support #74

Open eplusg opened 7 months ago

eplusg commented 7 months ago

Hi, Thank you for developing this amazing software.

I am currently using Perplexity PRO, which provides each user with $5 in API credits on a monthy basis. It would be great to use this as an OpenAI API alternative.

Keep up the good work!

MohamedBassem commented 7 months ago

Hi, looking at preplexity’s api docs, it seems that they have an openai compatible. This means that hoarder will support it out of the box. Just set ‘OPENAI_BASE_URL=https://api.perplexity.ai’ and you’re probably good to go. I’m interested if this works (to add it to the docs), please give it a try and let me know how it goes :)

MohamedBassem commented 7 months ago

I'll close this for now and don't hesitate to reopen if you faced any issues.

firefoot007 commented 1 month ago

Hi, thanks for the awesome hoarding tool. I also have perplexity pro. While I tried this but it was not working. Below is the error I am getting:

2024-10-24T14:32:47.772Z info: [inference][1518] Starting an inference job for bookmark with id "ds63wmjiy5x75v4ejnz7zruw" 2024-10-24T14:32:47.839Z info: [inference][1518] Starting an inference job for bookmark with id "ds63wmjiy5x75v4ejnz7zruw" 2024-10-24T14:32:47.890Z info: [inference][1518] Starting an inference job for bookmark with id "ds63wmjiy5x75v4ejnz7zruw" 2024-10-24T14:32:47.941Z info: [inference][1518] Starting an inference job for bookmark with id "ds63wmjiy5x75v4ejnz7zruw" 2024-10-24T14:32:47.974Z error: [inference][1518] inference job failed: Error: 400 ["At body -> response_format -> ResponseFormatText -> type: Input should be 'text'", "At body -> response_format -> ResponseFormatJSONSchema -> type: Input should be 'json_schema'", "At body -> response_format -> ResponseFormatJSONSchema -> json_schema: Field required", "At body -> response_format -> ResponseFormatRegex -> type: Input should be 'regex'", "At body -> response_format -> ResponseFormatRegex -> regex: Field required"] Error: 400 ["At body -> response_format -> ResponseFormatText -> type: Input should be 'text'", "At body -> response_format -> ResponseFormatJSONSchema -> type: Input should be 'json_schema'", "At body -> response_format -> ResponseFormatJSONSchema -> json_schema: Field required", "At body -> response_format -> ResponseFormatRegex -> type: Input should be 'regex'", "At body -> response_format -> ResponseFormatRegex -> regex: Field required"] at APIError.generate (/app/apps/workers/node_modules/.pnpm/openai@4.67.1_zod@3.22.4/node_modules/openai/error.js:45:20) at OpenAI.makeStatusError (/app/apps/workers/node_modules/.pnpm/openai@4.67.1_zod@3.22.4/node_modules/openai/core.js:291:33) at OpenAI.makeRequest (/app/apps/workers/node_modules/.pnpm/openai@4.67.1_zod@3.22.4/node_modules/openai/core.js:335:30) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async OpenAIInferenceClient.inferFromText (/app/apps/workers/inference.ts:2:1934) at async inferTagsFromText (/app/apps/workers/openaiWorker.ts:6:3111) at async inferTags (/app/apps/workers/openaiWorker.ts:6:3334) at async Object.runOpenAI [as run] (/app/apps/workers/openaiWorker.ts:6:6764) at async Runner.runOnce (/app/apps/workers/node_modules/.pnpm/@hoarder+queue@file+packages+queue/node_modules/@hoarder/queue/runner.ts:2:2567)

sparkyfen commented 2 weeks ago

https://www.perplexity.ai/hub/blog/introducing-pplx-api - looks like the example doesn't include response_format in the request so this would need to be optionally removed from the call if the provider is Perplexity. (P.S. I've having the same issue as @firefoot007)