kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: add HackerNewsClient; bump deps
rodzic
555f9d54f8
commit
98f7e6dab3
14
package.json
14
package.json
|
@ -101,24 +101,24 @@
|
||||||
"zod-to-json-schema": "^3.23.1"
|
"zod-to-json-schema": "^3.23.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@aws-sdk/client-sso-oidc": "^3.600.0",
|
"@aws-sdk/client-sso-oidc": "^3.606.0",
|
||||||
"@browserbasehq/sdk": "^1.4.2",
|
"@browserbasehq/sdk": "^1.4.2",
|
||||||
"@dexaai/dexter": "^2.0.3",
|
"@dexaai/dexter": "^2.0.3",
|
||||||
"@e2b/code-interpreter": "^0.0.8",
|
"@e2b/code-interpreter": "^0.0.8",
|
||||||
"@fisch0920/eslint-config": "^1.3.3",
|
"@fisch0920/eslint-config": "^1.3.3",
|
||||||
"@genkit-ai/ai": "^0.5.3",
|
"@genkit-ai/ai": "^0.5.4",
|
||||||
"@langchain/core": "^0.2.10",
|
"@langchain/core": "^0.2.11",
|
||||||
"@nangohq/node": "^0.40.6",
|
"@nangohq/node": "^0.40.7",
|
||||||
"@total-typescript/ts-reset": "^0.5.1",
|
"@total-typescript/ts-reset": "^0.5.1",
|
||||||
"@types/node": "^20.14.9",
|
"@types/node": "^20.14.9",
|
||||||
"ai": "^3.2.11",
|
"ai": "^3.2.15",
|
||||||
"del-cli": "^5.1.0",
|
"del-cli": "^5.1.0",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"husky": "^9.0.11",
|
"husky": "^9.0.11",
|
||||||
"lint-staged": "^15.2.7",
|
"lint-staged": "^15.2.7",
|
||||||
"llamaindex": "^0.4.6",
|
"llamaindex": "^0.4.6",
|
||||||
"mathjs": "^13.0.0",
|
"mathjs": "^13.0.1",
|
||||||
"np": "^10.0.6",
|
"np": "^10.0.6",
|
||||||
"npm-run-all2": "^6.2.0",
|
"npm-run-all2": "^6.2.0",
|
||||||
"only-allow": "^1.2.1",
|
"only-allow": "^1.2.1",
|
||||||
|
@ -127,7 +127,7 @@
|
||||||
"restore-cursor": "^5.0.0",
|
"restore-cursor": "^5.0.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"tsup": "^8.1.0",
|
"tsup": "^8.1.0",
|
||||||
"tsx": "^4.15.7",
|
"tsx": "^4.16.0",
|
||||||
"twitter-api-sdk": "^1.2.1",
|
"twitter-api-sdk": "^1.2.1",
|
||||||
"typescript": "^5.5.2",
|
"typescript": "^5.5.2",
|
||||||
"vitest": "2.0.0-beta.3"
|
"vitest": "2.0.0-beta.3"
|
||||||
|
|
1449
pnpm-lock.yaml
1449
pnpm-lock.yaml
Plik diff jest za duży
Load Diff
|
@ -138,6 +138,7 @@ Depending on the AI SDK and tool you want to use, you'll also need to install th
|
||||||
| [E2B](https://e2b.dev) | `e2b` | Hosted Python code intrepreter sandbox which is really useful for data analysis, flexible code execution, and advanced reasoning on-the-fly. |
|
| [E2B](https://e2b.dev) | `e2b` | Hosted Python code intrepreter sandbox which is really useful for data analysis, flexible code execution, and advanced reasoning on-the-fly. |
|
||||||
| [Exa](https://docs.exa.ai) | `ExaClient` | Web search tailored for LLMs. |
|
| [Exa](https://docs.exa.ai) | `ExaClient` | Web search tailored for LLMs. |
|
||||||
| [Firecrawl](https://www.firecrawl.dev) | `FirecrawlClient` | Website scraping and sanitization. |
|
| [Firecrawl](https://www.firecrawl.dev) | `FirecrawlClient` | Website scraping and sanitization. |
|
||||||
|
| [HackerNews](https://github.com/HackerNews/API) | `HackerNewsClient` | Official HackerNews API. |
|
||||||
| [Hunter](https://hunter.io) | `HunterClient` | Email finder, verifier, and enrichment. |
|
| [Hunter](https://hunter.io) | `HunterClient` | Email finder, verifier, and enrichment. |
|
||||||
| [Midjourney](https://www.imagineapi.dev) | `MidjourneyClient` | Unofficial Midjourney client for generative images. |
|
| [Midjourney](https://www.imagineapi.dev) | `MidjourneyClient` | Unofficial Midjourney client for generative images. |
|
||||||
| [Novu](https://novu.co) | `NovuClient` | Sending notifications (email, SMS, in-app, push, etc). |
|
| [Novu](https://novu.co) | `NovuClient` | Sending notifications (email, SMS, in-app, push, etc). |
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
import defaultKy, { type KyInstance } from 'ky'
|
||||||
|
|
||||||
|
import { AIFunctionsProvider } from '../fns.js'
|
||||||
|
import { assert, getEnv } from '../utils.js'
|
||||||
|
|
||||||
|
export namespace hackernews {
|
||||||
|
export type ItemType =
|
||||||
|
| 'story'
|
||||||
|
| 'comment'
|
||||||
|
| 'ask'
|
||||||
|
| 'job'
|
||||||
|
| 'poll'
|
||||||
|
| 'pollopt'
|
||||||
|
|
||||||
|
export interface Item {
|
||||||
|
id: number
|
||||||
|
type: ItemType
|
||||||
|
by: string
|
||||||
|
time: number
|
||||||
|
score: number
|
||||||
|
title?: string
|
||||||
|
url?: string
|
||||||
|
text?: string
|
||||||
|
descendants?: number
|
||||||
|
parent?: number
|
||||||
|
kids?: number[]
|
||||||
|
parts?: number[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
id: string
|
||||||
|
created: number
|
||||||
|
about: string
|
||||||
|
karma: number
|
||||||
|
submitted: number[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic client for the official Hacker News API.
|
||||||
|
*
|
||||||
|
* Note that the [HN Algolia API](https://hn.algolia.com/api) seems to no
|
||||||
|
* longer be available, so we can't add search without quite a bit of overhead.
|
||||||
|
*
|
||||||
|
* @see https://github.com/HackerNews/API
|
||||||
|
*/
|
||||||
|
export class HackerNewsClient extends AIFunctionsProvider {
|
||||||
|
protected readonly ky: KyInstance
|
||||||
|
protected readonly apiBaseUrl: string
|
||||||
|
protected readonly apiUserAgent: string
|
||||||
|
|
||||||
|
constructor({
|
||||||
|
apiBaseUrl = getEnv('HACKER_NEWS_API_BASE_URL') ??
|
||||||
|
'https://hacker-news.firebaseio.com',
|
||||||
|
apiUserAgent = getEnv('HACKER_NEWS_API_USER_AGENT') ??
|
||||||
|
'Agentic (https://github.com/transitive-bullshit/agentic)',
|
||||||
|
ky = defaultKy
|
||||||
|
}: {
|
||||||
|
apiBaseUrl?: string
|
||||||
|
apiUserAgent?: string
|
||||||
|
ky?: KyInstance
|
||||||
|
} = {}) {
|
||||||
|
assert(apiBaseUrl, 'HackerNewsClient missing required "apiBaseUrl"')
|
||||||
|
super()
|
||||||
|
|
||||||
|
this.apiBaseUrl = apiBaseUrl
|
||||||
|
this.apiUserAgent = apiUserAgent
|
||||||
|
|
||||||
|
this.ky = ky.extend({
|
||||||
|
prefixUrl: apiBaseUrl,
|
||||||
|
headers: {
|
||||||
|
'user-agent': apiUserAgent
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async getItem(id: string | number) {
|
||||||
|
return this.ky.get(`v0/item/${id}.json`).json<hackernews.Item>()
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTopStories() {
|
||||||
|
return this.ky.get('v0/topstories.json').json<number[]>()
|
||||||
|
}
|
||||||
|
|
||||||
|
async getNewStories() {
|
||||||
|
return this.ky.get('v0/newstories.json').json<number[]>()
|
||||||
|
}
|
||||||
|
|
||||||
|
async getBestStories() {
|
||||||
|
return this.ky.get('v0/beststories.json').json<number[]>()
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,7 @@ export * from './dexa-client.js'
|
||||||
export * from './diffbot-client.js'
|
export * from './diffbot-client.js'
|
||||||
export * from './exa-client.js'
|
export * from './exa-client.js'
|
||||||
export * from './firecrawl-client.js'
|
export * from './firecrawl-client.js'
|
||||||
|
export * from './hacker-news-client.js'
|
||||||
export * from './hunter-client.js'
|
export * from './hunter-client.js'
|
||||||
export * from './midjourney-client.js'
|
export * from './midjourney-client.js'
|
||||||
export * from './novu-client.js'
|
export * from './novu-client.js'
|
||||||
|
|
Ładowanie…
Reference in New Issue