@ -1,110 +0,0 @@
|
||||
import { createAction, option } from '@typebot.io/forge'
|
||||
import { isDefined } from '@typebot.io/lib'
|
||||
import { ZemanticAiResponse } from '../types'
|
||||
import ky from 'ky'
|
||||
import { apiBaseUrl } from '../constants'
|
||||
import { auth } from '../auth'
|
||||
import { baseOptions } from '../baseOptions'
|
||||
|
||||
export const searchDocuments = createAction({
|
||||
baseOptions,
|
||||
auth,
|
||||
name: 'Search documents',
|
||||
options: option.object({
|
||||
query: option.string.layout({
|
||||
label: 'Query',
|
||||
placeholder: 'Content',
|
||||
moreInfoTooltip:
|
||||
'The question you want to ask or search against the documents in the project.',
|
||||
}),
|
||||
maxResults: option.number.layout({
|
||||
label: 'Max results',
|
||||
placeholder: 'i.e. 3',
|
||||
defaultValue: 3,
|
||||
moreInfoTooltip:
|
||||
'The maximum number of document chunk results to return from your search.',
|
||||
}),
|
||||
systemPrompt: option.string.layout({
|
||||
accordion: 'Advanced settings',
|
||||
label: 'System prompt',
|
||||
moreInfoTooltip:
|
||||
'System prompt to send to the summarization LLM. This is prepended to the prompt and helps guide system behavior.',
|
||||
inputType: 'textarea',
|
||||
}),
|
||||
prompt: option.string.layout({
|
||||
accordion: 'Advanced settings',
|
||||
label: 'Prompt',
|
||||
moreInfoTooltip: 'Prompt to send to the summarization LLM.',
|
||||
inputType: 'textarea',
|
||||
}),
|
||||
responseMapping: option
|
||||
.saveResponseArray([
|
||||
'Summary',
|
||||
'Document IDs',
|
||||
'Texts',
|
||||
'Scores',
|
||||
] as const)
|
||||
.layout({
|
||||
accordion: 'Save response',
|
||||
}),
|
||||
}),
|
||||
getSetVariableIds: ({ responseMapping }) =>
|
||||
responseMapping?.map((r) => r.variableId).filter(isDefined) ?? [],
|
||||
run: {
|
||||
server: async ({
|
||||
credentials: { apiKey },
|
||||
options: {
|
||||
maxResults,
|
||||
projectId,
|
||||
prompt,
|
||||
query,
|
||||
responseMapping,
|
||||
systemPrompt,
|
||||
},
|
||||
variables,
|
||||
}) => {
|
||||
const res = await ky
|
||||
.post(apiBaseUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
json: {
|
||||
projectId,
|
||||
query,
|
||||
maxResults,
|
||||
summarize: true,
|
||||
summaryOptions: {
|
||||
system_prompt: systemPrompt,
|
||||
prompt: prompt,
|
||||
},
|
||||
},
|
||||
})
|
||||
.json<ZemanticAiResponse>()
|
||||
|
||||
responseMapping?.forEach((mapping) => {
|
||||
if (!mapping.variableId || !mapping.item) return
|
||||
|
||||
if (mapping.item === 'Document IDs')
|
||||
variables.set(
|
||||
mapping.variableId,
|
||||
res.results.map((r) => r.documentId)
|
||||
)
|
||||
|
||||
if (mapping.item === 'Texts')
|
||||
variables.set(
|
||||
mapping.variableId,
|
||||
res.results.map((r) => r.text)
|
||||
)
|
||||
|
||||
if (mapping.item === 'Scores')
|
||||
variables.set(
|
||||
mapping.variableId,
|
||||
res.results.map((r) => r.score)
|
||||
)
|
||||
|
||||
if (mapping.item === 'Summary')
|
||||
variables.set(mapping.variableId, res.summary)
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
@ -1,17 +0,0 @@
|
||||
import { AuthDefinition, option } from '@typebot.io/forge'
|
||||
|
||||
export const auth = {
|
||||
type: 'encryptedCredentials',
|
||||
name: 'Zemantic AI account',
|
||||
schema: option.object({
|
||||
apiKey: option.string.layout({
|
||||
label: 'API key',
|
||||
isRequired: true,
|
||||
placeholder: 'ze...',
|
||||
inputType: 'password',
|
||||
helperText:
|
||||
'You can generate an API key [here](https://zemantic.ai/dashboard/settings).',
|
||||
isDebounceDisabled: true,
|
||||
}),
|
||||
}),
|
||||
} satisfies AuthDefinition
|
@ -1,8 +0,0 @@
|
||||
import { option } from '@typebot.io/forge'
|
||||
|
||||
export const baseOptions = option.object({
|
||||
projectId: option.string.layout({
|
||||
placeholder: 'Select a project',
|
||||
fetcher: 'fetchProjects',
|
||||
}),
|
||||
})
|
@ -1 +0,0 @@
|
||||
export const apiBaseUrl = 'https://api.zemantic.ai/v1/search-documents'
|
@ -1,45 +0,0 @@
|
||||
import { createBlock } from '@typebot.io/forge'
|
||||
import { ZemanticAiLogo } from './logo'
|
||||
import ky from 'ky'
|
||||
import { searchDocuments } from './actions/searchDocuments'
|
||||
import { auth } from './auth'
|
||||
import { baseOptions } from './baseOptions'
|
||||
|
||||
export const zemanticAiBlock = createBlock({
|
||||
id: 'zemantic-ai',
|
||||
name: 'Zemantic AI',
|
||||
tags: [],
|
||||
LightLogo: ZemanticAiLogo,
|
||||
auth,
|
||||
options: baseOptions,
|
||||
fetchers: [
|
||||
{
|
||||
id: 'fetchProjects',
|
||||
dependencies: [],
|
||||
fetch: async ({ credentials }) => {
|
||||
if (!credentials?.apiKey) return []
|
||||
|
||||
const url = 'https://api.zemantic.ai/v1/projects'
|
||||
|
||||
const response = await ky
|
||||
.get(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${credentials.apiKey}`,
|
||||
},
|
||||
})
|
||||
.json()
|
||||
|
||||
const projectsData = response as {
|
||||
id: string
|
||||
name: string
|
||||
}[]
|
||||
|
||||
return projectsData.map((project) => ({
|
||||
label: project.name,
|
||||
value: project.id,
|
||||
}))
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: [searchDocuments],
|
||||
})
|
@ -1,21 +0,0 @@
|
||||
/** @jsxImportSource react */
|
||||
|
||||
export const ZemanticAiLogo = (props: React.SVGProps<SVGSVGElement>) => (
|
||||
<svg viewBox="0 0 24 24" {...props}>
|
||||
<g transform="matrix(.049281 0 0 .064343 -.27105 -3.4424)">
|
||||
<path
|
||||
d="m99.5 205.5v221h-94v-373h94v152z"
|
||||
fill="#8771b1"
|
||||
opacity=".991"
|
||||
/>
|
||||
<path
|
||||
d="m284.5 426.5v-221-152h94v373h-94z"
|
||||
fill="#f05b4e"
|
||||
opacity=".99"
|
||||
/>
|
||||
<path d="m99.5 205.5h93v221h-93v-221z" fill="#ec9896" />
|
||||
<path d="m192.5 205.5h92v221h-92v-221z" fill="#efe894" />
|
||||
<path d="m398.5 298.5h94v128h-94v-128z" fill="#46bb91" opacity=".989" />
|
||||
</g>
|
||||
</svg>
|
||||
)
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "@typebot.io/zemantic-ai-block",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.ts",
|
||||
"keywords": [],
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"devDependencies": {
|
||||
"@typebot.io/forge": "workspace:*",
|
||||
"@typebot.io/tsconfig": "workspace:*",
|
||||
"@types/react": "18.2.15",
|
||||
"typescript": "5.4.5",
|
||||
"@typebot.io/lib": "workspace:*",
|
||||
"ky": "1.2.4"
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
// Do not edit this file manually
|
||||
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
|
||||
import { zemanticAiBlock } from '.'
|
||||
import { auth } from './auth'
|
||||
|
||||
export const zemanticAiBlockSchema = parseBlockSchema(zemanticAiBlock)
|
||||
export const zemanticAiCredentialsSchema = parseBlockCredentials(
|
||||
zemanticAiBlock.id,
|
||||
auth.schema
|
||||
)
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"extends": "@typebot.io/tsconfig/base.json",
|
||||
"include": ["**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"],
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "react"
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
export type ZemanticAiResponse = {
|
||||
results: { documentId: string; text: string; score: number }[]
|
||||
summary: string
|
||||
}
|
@ -3,7 +3,6 @@ import { ForgedBlock } from './types'
|
||||
|
||||
export const forgedBlockIds = [
|
||||
'openai',
|
||||
'zemantic-ai',
|
||||
'cal-com',
|
||||
'chat-node',
|
||||
'qr-code',
|
||||
|
@ -14,14 +14,11 @@ import { openAIBlock } from '@typebot.io/openai-block'
|
||||
import { openAICredentialsSchema } from '@typebot.io/openai-block/schemas'
|
||||
import { togetherAiBlock } from '@typebot.io/together-ai-block'
|
||||
import { togetherAiCredentialsSchema } from '@typebot.io/together-ai-block/schemas'
|
||||
import { zemanticAiBlock } from '@typebot.io/zemantic-ai-block'
|
||||
import { zemanticAiCredentialsSchema } from '@typebot.io/zemantic-ai-block/schemas'
|
||||
import { nocodbBlock } from '@typebot.io/nocodb-block'
|
||||
import { nocodbCredentialsSchema } from '@typebot.io/nocodb-block/schemas'
|
||||
|
||||
export const forgedCredentialsSchemas = {
|
||||
[openAIBlock.id]: openAICredentialsSchema,
|
||||
[zemanticAiBlock.id]: zemanticAiCredentialsSchema,
|
||||
[chatNodeBlock.id]: chatNodeCredentialsSchema,
|
||||
[difyAiBlock.id]: difyAiCredentialsSchema,
|
||||
[mistralBlock.id]: mistralCredentialsSchema,
|
||||
|
@ -8,13 +8,11 @@ import { mistralBlock } from '@typebot.io/mistral-block'
|
||||
import { qrCodeBlock } from '@typebot.io/qrcode-block'
|
||||
import { chatNodeBlock } from '@typebot.io/chat-node-block'
|
||||
import { calComBlock } from '@typebot.io/cal-com-block'
|
||||
import { zemanticAiBlock } from '@typebot.io/zemantic-ai-block'
|
||||
import { openAIBlock } from '@typebot.io/openai-block'
|
||||
import { nocodbBlock } from '@typebot.io/nocodb-block'
|
||||
|
||||
export const forgedBlocks = {
|
||||
[openAIBlock.id]: openAIBlock,
|
||||
[zemanticAiBlock.id]: zemanticAiBlock,
|
||||
[calComBlock.id]: calComBlock,
|
||||
[chatNodeBlock.id]: chatNodeBlock,
|
||||
[qrCodeBlock.id]: qrCodeBlock,
|
||||
|
@ -8,7 +8,6 @@
|
||||
"devDependencies": {
|
||||
"@typebot.io/forge": "workspace:*",
|
||||
"@typebot.io/openai-block": "workspace:*",
|
||||
"@typebot.io/zemantic-ai-block": "workspace:*",
|
||||
"@typebot.io/cal-com-block": "workspace:*",
|
||||
"@typebot.io/chat-node-block": "workspace:*",
|
||||
"@typebot.io/qrcode-block": "workspace:*",
|
||||
|
@ -19,14 +19,11 @@ import { qrCodeBlock } from '@typebot.io/qrcode-block'
|
||||
import { qrCodeBlockSchema } from '@typebot.io/qrcode-block/schemas'
|
||||
import { togetherAiBlock } from '@typebot.io/together-ai-block'
|
||||
import { togetherAiBlockSchema } from '@typebot.io/together-ai-block/schemas'
|
||||
import { zemanticAiBlock } from '@typebot.io/zemantic-ai-block'
|
||||
import { zemanticAiBlockSchema } from '@typebot.io/zemantic-ai-block/schemas'
|
||||
import { nocodbBlock } from '@typebot.io/nocodb-block'
|
||||
import { nocodbBlockSchema } from '@typebot.io/nocodb-block/schemas'
|
||||
|
||||
export const forgedBlockSchemas = {
|
||||
[openAIBlock.id]: openAIBlockSchema,
|
||||
[zemanticAiBlock.id]: zemanticAiBlockSchema,
|
||||
[calComBlock.id]: calComBlockSchema,
|
||||
[chatNodeBlock.id]: chatNodeBlockSchema,
|
||||
[qrCodeBlock.id]: qrCodeBlockSchema,
|
||||
|
Reference in New Issue
Block a user