Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/thatstupidcomputer / packages/discovery/providers/perplexity/answers.ts |
| Date | Not specified in source |
| Repository | Janady13/thatstupidcomputer |
| Revision | 57555cde46910102dd25d6c1c1fb2c359e9655bd |
| Branch | main |
| Path or archive member | packages/discovery/providers/perplexity/answers.ts |
| Original SHA-256 | b572c91f23f8ba1616cc54570f61b0ac02ebf286a4e761ba1c123b3a81dbb31a |
| Git blob SHA | 851408e2c2e8b4361f8cd8f2abb9ed0bc1d9a656 |
| Reading-copy SHA-256 | b572c91f23f8ba1616cc54570f61b0ac02ebf286a4e761ba1c123b3a81dbb31a |
Recovered source transcript
Download complete source text ↓13 lines · 0.9 KB
import {record,records,citationUrl,type AnswerAdapter} from '../../protocol.ts';
export const perplexityAnswers:AnswerAdapter={
endpoint:'https://api.perplexity.ai/v1/sonar',auth:'bearer',
build:(model,query)=>({model,messages:[{role:'user',content:query}],max_tokens:1200,stream:false}),
parse:value=>{
if(!record(value)||!Array.isArray(value.choices)||!Array.isArray(value.citations))return;
const choice=records(value.choices)[0];if(!choice||choice.finish_reason!=='stop'||!record(choice.message)||typeof choice.message.content!=='string'||!choice.message.content.trim())return;
// Native citations are sources used in generation; search_results is only retrieved context.
const citations=value.citations.map(citationUrl).filter((url):url is string=>Boolean(url)).map(url=>({url}));
return {text:choice.message.content,citations,searchExecuted:true,...(typeof value.model==='string'?{responseModel:value.model}:{})};
},
};