kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
old-agentic-v1^2
rodzic
92ba811e93
commit
97536de2ec
|
@ -164,7 +164,7 @@ export interface Request {
|
||||||
version: number
|
version: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DiffbotSearchKnowledgeGraphOptions {
|
export interface DiffbotKnowledgeGraphSearchOptions {
|
||||||
type?: 'query' | 'text' | 'queryTextFallback' | 'crawl'
|
type?: 'query' | 'text' | 'queryTextFallback' | 'crawl'
|
||||||
query: string
|
query: string
|
||||||
col?: string
|
col?: string
|
||||||
|
@ -186,18 +186,47 @@ export interface DiffbotSearchKnowledgeGraphOptions {
|
||||||
report?: boolean
|
report?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DiffbotSearchKnowledgeGraphResponse {
|
export interface DiffbotKnowledgeGraphEnhanceOptions {
|
||||||
|
type: 'Person' | 'Organization'
|
||||||
|
|
||||||
|
id?: string
|
||||||
|
name?: string
|
||||||
|
url?: string
|
||||||
|
phone?: string
|
||||||
|
email?: string
|
||||||
|
employer?: string
|
||||||
|
title?: string
|
||||||
|
school?: string
|
||||||
|
location?: string
|
||||||
|
ip?: string
|
||||||
|
customId?: string
|
||||||
|
|
||||||
|
size?: number
|
||||||
|
threshold?: number
|
||||||
|
|
||||||
|
refresh?: boolean
|
||||||
|
search?: boolean
|
||||||
|
useCache?: boolean
|
||||||
|
|
||||||
|
filter?: string
|
||||||
|
jsonmode?: 'extended' | 'id'
|
||||||
|
nonCanonicalFacts?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DiffbotKnowledgeGraphSearchResponse {
|
||||||
|
data: DiffbotKnowledgeGraphNode[]
|
||||||
version: number
|
version: number
|
||||||
hits: number
|
hits: number
|
||||||
results: number
|
results: number
|
||||||
kgversion: string
|
kgversion: string
|
||||||
diffbot_type: string
|
diffbot_type: string
|
||||||
facet: boolean
|
facet?: boolean
|
||||||
data: DiffbotKnowledgeGraphNode[]
|
errors?: any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DiffbotKnowledgeGraphNode {
|
export interface DiffbotKnowledgeGraphNode {
|
||||||
score: number
|
score: number
|
||||||
|
esscore?: number
|
||||||
entity: DiffbotKnowledgeGraphEntity
|
entity: DiffbotKnowledgeGraphEntity
|
||||||
entity_ctx: any
|
entity_ctx: any
|
||||||
errors: string[]
|
errors: string[]
|
||||||
|
@ -211,10 +240,71 @@ export interface DiffbotKnowledgeGraphNode {
|
||||||
|
|
||||||
export interface DiffbotKnowledgeGraphEntity {
|
export interface DiffbotKnowledgeGraphEntity {
|
||||||
id: string
|
id: string
|
||||||
images: DiffbotImage[]
|
|
||||||
diffbotUri: string
|
diffbotUri: string
|
||||||
|
type?: string
|
||||||
name: string
|
name: string
|
||||||
|
images: DiffbotImage[]
|
||||||
origins: string[]
|
origins: string[]
|
||||||
|
nbOrigins?: number
|
||||||
|
|
||||||
|
gender?: DiffbotGender
|
||||||
|
githubUri?: string
|
||||||
|
importance?: number
|
||||||
|
description?: string
|
||||||
|
homepageUri?: string
|
||||||
|
allNames?: string[]
|
||||||
|
skills?: DiffbotSkill[]
|
||||||
|
crawlTimestamp?: number
|
||||||
|
summary?: string
|
||||||
|
image?: string
|
||||||
|
types?: string[]
|
||||||
|
nbIncomingEdges?: number
|
||||||
|
allUris?: string[]
|
||||||
|
employments?: DiffbotEmployment[]
|
||||||
|
locations?: DiffbotLocation[]
|
||||||
|
location?: DiffbotLocation
|
||||||
|
allOriginHashes?: string[]
|
||||||
|
nameDetail?: DiffbotNameDetail
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DiffbotEmployment {
|
||||||
|
employer: Entity
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Entity {
|
||||||
|
image?: string
|
||||||
|
types?: string[]
|
||||||
|
name: string
|
||||||
|
diffbotUri?: string
|
||||||
|
type: EntityType
|
||||||
|
summary?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type EntityType = 'Organization' | 'Place'
|
||||||
|
|
||||||
|
interface DiffbotGender {
|
||||||
|
normalizedValue: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DiffbotLocation {
|
||||||
|
country: Entity
|
||||||
|
isCurrent: boolean
|
||||||
|
address: string
|
||||||
|
latitude: number
|
||||||
|
precision: number
|
||||||
|
surfaceForm: string
|
||||||
|
region: Entity
|
||||||
|
longitude: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DiffbotNameDetail {
|
||||||
|
firstName: string
|
||||||
|
lastName: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DiffbotSkill {
|
||||||
|
name: string
|
||||||
|
diffbotUri: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DiffbotClient {
|
export class DiffbotClient {
|
||||||
|
@ -290,7 +380,7 @@ export class DiffbotClient {
|
||||||
return this._extract<DiffbotExtractArticleResponse>('v3/article', options)
|
return this._extract<DiffbotExtractArticleResponse>('v3/article', options)
|
||||||
}
|
}
|
||||||
|
|
||||||
async searchKnowledgeGraph(options: DiffbotSearchKnowledgeGraphOptions) {
|
async knowledgeGraphSearch(options: DiffbotKnowledgeGraphSearchOptions) {
|
||||||
return this.apiKnowledgeGraph
|
return this.apiKnowledgeGraph
|
||||||
.get('kg/v3/dql', {
|
.get('kg/v3/dql', {
|
||||||
searchParams: {
|
searchParams: {
|
||||||
|
@ -298,6 +388,17 @@ export class DiffbotClient {
|
||||||
token: this.apiKey
|
token: this.apiKey
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.json<DiffbotSearchKnowledgeGraphResponse>()
|
.json<DiffbotKnowledgeGraphSearchResponse>()
|
||||||
|
}
|
||||||
|
|
||||||
|
async knowledgeGraphEnhance(options: DiffbotKnowledgeGraphEnhanceOptions) {
|
||||||
|
return this.apiKnowledgeGraph
|
||||||
|
.get('kg/v3/enhance', {
|
||||||
|
searchParams: {
|
||||||
|
...options,
|
||||||
|
token: this.apiKey
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.json<DiffbotKnowledgeGraphSearchResponse>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { DiffbotClient } from '@/services'
|
||||||
|
|
||||||
import { isCI, ky } from '../_utils'
|
import { isCI, ky } from '../_utils'
|
||||||
|
|
||||||
test('Diffbot.analyze', async (t) => {
|
test('Diffbot.extractAnalyze', async (t) => {
|
||||||
if (!process.env.DIFFBOT_API_KEY || isCI) {
|
if (!process.env.DIFFBOT_API_KEY || isCI) {
|
||||||
return t.pass()
|
return t.pass()
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ test('Diffbot.analyze', async (t) => {
|
||||||
t.is(result.objects?.length, 1)
|
t.is(result.objects?.length, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Diffbot.article', async (t) => {
|
test('Diffbot.extractArticle', async (t) => {
|
||||||
if (!process.env.DIFFBOT_API_KEY || isCI) {
|
if (!process.env.DIFFBOT_API_KEY || isCI) {
|
||||||
return t.pass()
|
return t.pass()
|
||||||
}
|
}
|
||||||
|
@ -35,3 +35,38 @@ test('Diffbot.article', async (t) => {
|
||||||
// console.log(JSON.stringify(result, null, 2))
|
// console.log(JSON.stringify(result, null, 2))
|
||||||
t.is(result.objects[0].type, 'article')
|
t.is(result.objects[0].type, 'article')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.only('Diffbot.knowledgeGraphSearch', async (t) => {
|
||||||
|
if (!process.env.DIFFBOT_API_KEY || isCI) {
|
||||||
|
return t.pass()
|
||||||
|
}
|
||||||
|
|
||||||
|
t.timeout(2 * 60 * 1000)
|
||||||
|
const client = new DiffbotClient({ ky })
|
||||||
|
|
||||||
|
const result = await client.knowledgeGraphSearch({
|
||||||
|
type: 'query',
|
||||||
|
query: 'Brown University',
|
||||||
|
size: 10
|
||||||
|
})
|
||||||
|
// console.log(JSON.stringify(result, null, 2))
|
||||||
|
t.true(Array.isArray(result.data))
|
||||||
|
t.is(result.data.length, 10)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Diffbot.knowledgeGraphEnhance', async (t) => {
|
||||||
|
if (!process.env.DIFFBOT_API_KEY || isCI) {
|
||||||
|
return t.pass()
|
||||||
|
}
|
||||||
|
|
||||||
|
t.timeout(2 * 60 * 1000)
|
||||||
|
const client = new DiffbotClient({ ky })
|
||||||
|
|
||||||
|
const result = await client.knowledgeGraphEnhance({
|
||||||
|
type: 'Person',
|
||||||
|
name: 'Travis Fischer',
|
||||||
|
url: 'https://transitivebullsh.it'
|
||||||
|
})
|
||||||
|
// console.log(JSON.stringify(result, null, 2))
|
||||||
|
t.is(result.data[0]?.entity?.githubUri, 'github.com/transitive-bullshit')
|
||||||
|
})
|
||||||
|
|
Ładowanie…
Reference in New Issue