-
-
Notifications
You must be signed in to change notification settings - Fork 24.3k
feat: add Telnyx chat, embeddings, audio, and telecom integrations #6392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gbattistel
wants to merge
6
commits into
FlowiseAI:main
Choose a base branch
from
team-telnyx:feat/telnyx-flowise-tools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfa5c38
feat(tools): add Telnyx messaging, lookup, and verify integrations
gbattistel b08dedb
feat(models): add Telnyx chat and embeddings providers
gbattistel 5e49542
feat(audio): add Telnyx STT and TTS providers
gbattistel 688c4bb
fix(tools): correct Telnyx verify check endpoint
gbattistel abf0c64
Merge branch 'main' into feat/telnyx-flowise-tools
gbattistel 8a34d4a
fix: address review feedback for Telnyx integrations
gbattistel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { INodeParams, INodeCredential } from '../src/Interface' | ||
|
|
||
| class TelnyxApi implements INodeCredential { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Telnyx API' | ||
| this.name = 'telnyxApi' | ||
| this.version = 1.0 | ||
| this.inputs = [ | ||
| { | ||
| label: 'API Key', | ||
| name: 'apiKey', | ||
| type: 'password' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| module.exports = { credClass: TelnyxApi } |
136 changes: 136 additions & 0 deletions
136
packages/components/nodes/chatmodels/ChatTelnyx/ChatTelnyx.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import { ChatOpenAI, ChatOpenAIFields } from '@langchain/openai' | ||
| import { BaseCache } from '@langchain/core/caches' | ||
| import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface' | ||
| import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' | ||
| import { secureFetch } from '../../../src/httpSecurity' | ||
|
|
||
| const TELNYX_OPENAI_BASE = 'https://api.telnyx.com/v2/ai/openai' | ||
| const TELNYX_CHAT_MODELS_URL = 'https://api.telnyx.com/v2/ai/openai/models' | ||
|
|
||
| const fetchTelnyxModels = async (apiKey: string) => { | ||
| const response = await secureFetch(TELNYX_CHAT_MODELS_URL, { | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Failed to fetch Telnyx models: ${response.status} ${response.statusText}`) | ||
| } | ||
|
|
||
| const json = await response.json() | ||
| return json.data || [] | ||
| } | ||
|
|
||
| class ChatTelnyx_ChatModels implements INode { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| type: string | ||
| icon: string | ||
| category: string | ||
| description: string | ||
| baseClasses: string[] | ||
| credential: INodeParams | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Telnyx Chat' | ||
| this.name = 'chatTelnyx' | ||
| this.version = 1.1 | ||
| this.type = 'ChatTelnyx' | ||
| this.icon = 'telnyx.png' | ||
| this.category = 'Chat Models' | ||
| this.description = 'Use Telnyx OpenAI-compatible chat completions as a native Flowise chat model' | ||
| this.baseClasses = [this.type, ...getBaseClasses(ChatOpenAI)] | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['telnyxApi'], | ||
| refresh: true | ||
| } | ||
| this.inputs = [ | ||
| { label: 'Cache', name: 'cache', type: 'BaseCache', optional: true }, | ||
| { label: 'Model Name', name: 'modelName', type: 'asyncOptions', loadMethod: 'listModels', default: 'openai/gpt-4o', refresh: true }, | ||
| { label: 'Temperature', name: 'temperature', type: 'number', step: 0.1, default: 0.9, optional: true }, | ||
| { label: 'Streaming', name: 'streaming', type: 'boolean', default: true, optional: true, additionalParams: true }, | ||
| { label: 'Max Tokens', name: 'maxTokens', type: 'number', step: 1, optional: true, additionalParams: true }, | ||
| { label: 'Top Probability', name: 'topP', type: 'number', step: 0.1, optional: true, additionalParams: true }, | ||
| { label: 'Frequency Penalty', name: 'frequencyPenalty', type: 'number', step: 0.1, optional: true, additionalParams: true }, | ||
| { label: 'Presence Penalty', name: 'presencePenalty', type: 'number', step: 0.1, optional: true, additionalParams: true }, | ||
| { label: 'Timeout', name: 'timeout', type: 'number', step: 1, optional: true, additionalParams: true } | ||
| ] | ||
| } | ||
|
|
||
| //@ts-ignore | ||
| loadMethods = { | ||
| async listModels(nodeData: INodeData, options: ICommonObject): Promise<INodeOptionsValue[]> { | ||
| const credentialId = nodeData.credential || nodeData.inputs?.credentialId | ||
| if (!credentialId) { | ||
| return [{ label: 'Select a Telnyx API credential to load models', name: 'openai/gpt-4o' }] | ||
| } | ||
|
|
||
| try { | ||
| const credentialData = await getCredentialData(credentialId as string, options) | ||
| const apiKey = getCredentialParam('apiKey', credentialData, nodeData) | ||
| const models = await fetchTelnyxModels(apiKey) | ||
|
|
||
| return models | ||
| .map((model: any) => ({ | ||
| label: model.id, | ||
| name: model.id, | ||
| description: [model.task, model.context_length ? `context ${model.context_length}` : '', model.tier || ''] | ||
| .filter(Boolean) | ||
| .join(' • ') | ||
| })) | ||
| } catch (error) { | ||
| console.warn('Falling back to static Telnyx chat model list:', error) | ||
| return [{ label: 'openai/gpt-4o', name: 'openai/gpt-4o' }] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| const temperature = nodeData.inputs?.temperature as string | ||
| const modelName = nodeData.inputs?.modelName as string | ||
| const maxTokens = nodeData.inputs?.maxTokens as string | ||
| const topP = nodeData.inputs?.topP as string | ||
| const frequencyPenalty = nodeData.inputs?.frequencyPenalty as string | ||
| const presencePenalty = nodeData.inputs?.presencePenalty as string | ||
| const timeout = nodeData.inputs?.timeout as string | ||
| const streaming = nodeData.inputs?.streaming as boolean | ||
| const cache = nodeData.inputs?.cache as BaseCache | ||
|
|
||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const apiKey = getCredentialParam('apiKey', credentialData, nodeData) | ||
|
|
||
| const parsedTemperature = temperature ? parseFloat(temperature) : 0.9 | ||
| if (Number.isNaN(parsedTemperature)) { | ||
| throw new Error('Temperature must be a valid number') | ||
| } | ||
|
|
||
| const obj: ChatOpenAIFields = { | ||
| temperature: parsedTemperature, | ||
| modelName, | ||
| openAIApiKey: apiKey, | ||
| apiKey, | ||
| streaming: streaming ?? true, | ||
| configuration: { | ||
| baseURL: TELNYX_OPENAI_BASE | ||
| } | ||
| } | ||
|
|
||
| if (maxTokens) obj.maxTokens = parseInt(maxTokens, 10) | ||
| if (topP) obj.topP = parseFloat(topP) | ||
| if (frequencyPenalty) obj.frequencyPenalty = parseFloat(frequencyPenalty) | ||
| if (presencePenalty) obj.presencePenalty = parseFloat(presencePenalty) | ||
| if (timeout) obj.timeout = parseInt(timeout, 10) | ||
| if (cache) obj.cache = cache | ||
|
|
||
| return new ChatOpenAI(obj) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: ChatTelnyx_ChatModels } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Telnyx Chat Model | ||
|
|
||
| Telnyx Chat Model integration for Flowise | ||
|
|
||
| ## 🌱 Env Variables | ||
|
|
||
| | Variable | Description | Type | Default | | ||
| | --------------- | ----------------------------------------------------- | ------ | ------- | | ||
| | TELNYX_API_KEY | Default `credential.apiKey` for the Telnyx API | String | | | ||
|
|
||
| ## License | ||
|
|
||
| Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions
13
packages/components/nodes/embeddings/TelnyxEmbedding/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Telnyx Embedding Model | ||
|
|
||
| Telnyx Embedding Model integration for Flowise | ||
|
|
||
| ## 🌱 Env Variables | ||
|
|
||
| | Variable | Description | Type | Default | | ||
| | --------------- | ----------------------------------------------------- | ------ | ------- | | ||
| | TELNYX_API_KEY | Default `credential.apiKey` for the Telnyx API | String | | | ||
|
|
||
| ## License | ||
|
|
||
| Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). |
120 changes: 120 additions & 0 deletions
120
packages/components/nodes/embeddings/TelnyxEmbedding/TelnyxEmbedding.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { ClientOptions, OpenAIEmbeddings, OpenAIEmbeddingsParams } from '@langchain/openai' | ||
| import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface' | ||
| import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' | ||
| import { secureFetch } from '../../../src/httpSecurity' | ||
|
|
||
| const TELNYX_OPENAI_BASE = 'https://api.telnyx.com/v2/ai/openai' | ||
| const TELNYX_EMBEDDINGS_MODELS_URL = 'https://api.telnyx.com/v2/ai/embeddings/models' | ||
|
|
||
| const fetchTelnyxModels = async (apiKey: string) => { | ||
| const response = await secureFetch(TELNYX_EMBEDDINGS_MODELS_URL, { | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}`, | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`Failed to fetch Telnyx models: ${response.status} ${response.statusText}`) | ||
| } | ||
|
|
||
| const json = await response.json() | ||
| return json.data || [] | ||
| } | ||
|
|
||
| class TelnyxEmbedding_Embeddings implements INode { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| type: string | ||
| icon: string | ||
| category: string | ||
| description: string | ||
| baseClasses: string[] | ||
| credential: INodeParams | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Telnyx Embeddings' | ||
| this.name = 'telnyxEmbeddings' | ||
| this.version = 1.1 | ||
| this.type = 'TelnyxEmbeddings' | ||
| this.icon = 'telnyx.png' | ||
| this.category = 'Embeddings' | ||
| this.description = 'Use Telnyx OpenAI-compatible embeddings as a native Flowise embeddings node' | ||
| this.baseClasses = [this.type, ...getBaseClasses(OpenAIEmbeddings)] | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['telnyxApi'], | ||
| refresh: true | ||
| } | ||
| this.inputs = [ | ||
| { label: 'Model Name', name: 'modelName', type: 'asyncOptions', loadMethod: 'listModels', default: 'text-embedding-3-small', refresh: true }, | ||
| { label: 'Strip New Lines', name: 'stripNewLines', type: 'boolean', optional: true, additionalParams: true }, | ||
| { label: 'Batch Size', name: 'batchSize', type: 'number', optional: true, additionalParams: true }, | ||
| { label: 'Timeout', name: 'timeout', type: 'number', optional: true, additionalParams: true }, | ||
| { label: 'Dimensions', name: 'dimensions', type: 'number', optional: true, additionalParams: true }, | ||
| { label: 'Encoding Format', name: 'encodingFormat', type: 'options', options: [{ label: 'float', name: 'float' }, { label: 'base64', name: 'base64' }], optional: true, additionalParams: true } | ||
| ] | ||
| } | ||
|
|
||
| //@ts-ignore | ||
| loadMethods = { | ||
| async listModels(nodeData: INodeData, options: ICommonObject): Promise<INodeOptionsValue[]> { | ||
| const credentialId = nodeData.credential || nodeData.inputs?.credentialId | ||
| if (!credentialId) { | ||
| return [{ label: 'Select a Telnyx API credential to load models', name: 'text-embedding-3-small' }] | ||
| } | ||
|
|
||
| try { | ||
| const credentialData = await getCredentialData(credentialId as string, options) | ||
| const apiKey = getCredentialParam('apiKey', credentialData, nodeData) | ||
| const models = await fetchTelnyxModels(apiKey) | ||
|
|
||
| return models | ||
| .map((model: any) => ({ | ||
| label: model.id, | ||
| name: model.id, | ||
| description: [model.task, model.context_length ? `context ${model.context_length}` : '', model.tier || ''] | ||
| .filter(Boolean) | ||
| .join(' • ') | ||
| })) | ||
| } catch (error) { | ||
| console.warn('Falling back to static Telnyx embeddings model list:', error) | ||
| return [{ label: 'text-embedding-3-small', name: 'text-embedding-3-small' }] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| const stripNewLines = nodeData.inputs?.stripNewLines as boolean | ||
| const batchSize = nodeData.inputs?.batchSize as string | ||
| const timeout = nodeData.inputs?.timeout as string | ||
| const modelName = nodeData.inputs?.modelName as string | ||
| const dimensions = nodeData.inputs?.dimensions as string | ||
| const encodingFormat = nodeData.inputs?.encodingFormat as 'float' | 'base64' | undefined | ||
|
|
||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const apiKey = getCredentialParam('apiKey', credentialData, nodeData) | ||
|
|
||
| const obj: Partial<OpenAIEmbeddingsParams> & { openAIApiKey?: string; configuration?: ClientOptions } = { | ||
| openAIApiKey: apiKey, | ||
| modelName, | ||
| configuration: { | ||
| baseURL: TELNYX_OPENAI_BASE | ||
| } | ||
| } | ||
|
|
||
| if (stripNewLines) obj.stripNewLines = stripNewLines | ||
| if (batchSize) obj.batchSize = parseInt(batchSize, 10) | ||
| if (timeout) obj.timeout = parseInt(timeout, 10) | ||
| if (dimensions) obj.dimensions = parseInt(dimensions, 10) | ||
| if (encodingFormat) obj.encodingFormat = encodingFormat | ||
|
|
||
| return new OpenAIEmbeddings(obj) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: TelnyxEmbedding_Embeddings } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.