Skip to content
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

Feature/sonix ai audio loader #1169

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@
},
"engines": {
"node": ">=18.15.0"
},
"dependencies": {
uvamsi76 marked this conversation as resolved.
Show resolved Hide resolved
"sonix-speech-recognition": "^2.1.1"
}
}
23 changes: 23 additions & 0 deletions packages/components/credentials/SonixAiApi.credential.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { INodeParams, INodeCredential } from '../src/Interface'

class SonixAIApi implements INodeCredential {
label: string
name: string
version: number
inputs: INodeParams[]

constructor() {
this.label = 'SonixAI API'
this.name = 'sonixAIApi'
this.version = 1.0
this.inputs = [
{
label: 'SonixAI Api Key',
name: 'sonixAIApiKey',
type: 'password'
}
]
}
}

module.exports = { credClass: SonixAIApi }
132 changes: 132 additions & 0 deletions packages/components/nodes/chatmodels/SonixAi/SonixAi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ChatOpenAI, OpenAIChatInput } from 'langchain/chat_models/openai'
import { SonixAudioTranscriptionLoader } from "langchain/document_loaders/web/sonix_audio";
import {SupportedLanguage} from 'sonix-speech-recognition/lib/types'
import { BaseCache } from 'langchain/schema'
import { BaseLLMParams } from 'langchain/llms/base'

class SonixAi 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 = 'SonixAi'
this.name = 'SonixAi'
this.version = 1.0
this.type = 'SonixAi'
this.icon = 'sonixAi.svg'
this.category = 'Chat Models'
this.description = 'Converts audio to transcription'
this.baseClasses = [this.type, ...getBaseClasses(SonixAudioTranscriptionLoader)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['sonixAIApi']
}
this.inputs = [
{
label: 'Cache',
uvamsi76 marked this conversation as resolved.
Show resolved Hide resolved
name: 'cache',
type: 'BaseCache',
optional: true
},
{
label: 'Audio File',
name: 'audio_File',
type: 'file',
fileType: '.*'
},{
label: 'Audio File Name',
uvamsi76 marked this conversation as resolved.
Show resolved Hide resolved
name: 'audio_File_name',
type: 'string'
},
{
label: 'Language',
name: 'language',
type: 'options',
options: [
{
label: 'English',
name: 'en'
}
],
default: 'en',
optional: true
}
]
}

async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
const temperature = nodeData.inputs?.temperature as string

type SonixAiInput = {
sonixAuthKey?: string,
cache?:BaseCache,
request: {
audioFilePath?: string,
fileName?:string,
language?: SupportedLanguage,

}}
const audiofilepath = nodeData.inputs?.audio_File as string
const audiofilename = nodeData.inputs?.audio_File_name as string
const language = nodeData.inputs?.language as SupportedLanguage

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 basePath = nodeData.inputs?.basepath as string
const baseOptions = nodeData.inputs?.baseOptions

const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const sonixAuthKey = getCredentialParam('sonixAIApiKey', credentialData, nodeData)
if(!sonixAuthKey) return
const cache = nodeData.inputs?.cache as BaseCache

// const obj: Partial<SonixAiInput> = {
Copy link
Contributor

@HenryHengZJ HenryHengZJ Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant commented codes?

Copy link
Author

@uvamsi76 uvamsi76 Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all redundant code and comments in the next commit.
Thank you for the review. This is my first open source contribution so please suggest me anything that i have to change to improve my open source journey.

// sonixAuthKey:sonixAuthKey || '',
// request:{
// audioFilePath:audiofilepath,
// fileName:audiofilename,
// language:language
// }
// }

// if (cache) obj.cache = cache

const loader = new SonixAudioTranscriptionLoader({
sonixAuthKey: sonixAuthKey,
request: {
audioFilePath: audiofilepath,
fileName: audiofilename,
language: language,
}});

const docs = await loader.load();

return docs

// const model = new ChatOpenAI(obj, {
// basePath,
// baseOptions: parsedBaseOptions
// })
// return model
}
}

module.exports = { nodeClass: SonixAi }
11 changes: 11 additions & 0 deletions packages/components/nodes/chatmodels/SonixAi/sonixAi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.