Skip to content

Commit

Permalink
🚧 Telegram integration(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryhamon committed May 3, 2024
1 parent e8bd174 commit 9beac87
Show file tree
Hide file tree
Showing 22 changed files with 499 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
iris:
environment:
- OPENAPI_KEY=${OPENAPI_KEY}
- TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
- TELEGRAM_TOKEN=7194686883:AAHGvYjsfPqjUjdfekwnDdfYZ0uvwH2ERjI
build:
context: .
dockerfile: Dockerfile
Expand Down
14 changes: 14 additions & 0 deletions module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@
<Name>telegram-adapter</Name>
<Version>*</Version>
</ModuleReference>
<ModuleReference>
<Name>iris-openai</Name>
<Version>*</Version>
</ModuleReference>
<ModuleReference>
<Name>iris-tripleSlash</Name>
<Version>*</Version>
</ModuleReference>
</Dependencies>
<Resource Name="dc.irisMediCopilot.PKG"/>
<SystemRequirements Version=">=2024.1" Interoperability="enabled" />
<Default Name="Token" Value="Telegram Token" />
<Default Name="OpenAIKey" Value="OpenAI Key" />
<Invoke Class="dc.irisMediCopilot.util.Setup" Method="Init" >
<Arg>${Token}</Arg>
<Arg>${OpenAIKey}</Arg>
</Invoke>
</Module>
</Document>
</Export>
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# numpy==1.23.4
# pandas==1.5.0
# pandas==1.5.0
requests==2.31.0
43 changes: 38 additions & 5 deletions src/dc/irisMediCopilot/interop/Production.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,47 @@ XData ProductionDefinition
<Item Name="Telegram.BusinessService" Category="" ClassName="Telegram.LongPollingService" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
<Setting Target="Adapter" Name="SSLConfig">tg</Setting>
<Setting Target="Adapter" Name="CallInterval">5</Setting>
<Setting Target="Host" Name="Target">MessageRouting</Setting>
<Setting Target="Adapter" Name="FilesMimeTypes">image/png</Setting>
<Setting Target="Host" Name="Target">Message.Router</Setting>
<Setting Target="Adapter" Name="FilesMimeTypes">audio/ogg</Setting>
<Setting Target="Adapter" Name="FilesPath">/irisdev/app/images</Setting>
<Setting Target="Adapter" Name="FilesSave">file,thumbnail</Setting>
<Setting Target="Adapter" Name="FilesSave">file</Setting>
<Setting Target="Adapter" Name="Token">Token</Setting>
</Item>
<Item Name="MessageRouting" Category="" ClassName="EnsLib.MsgRouter.RoutingEngine" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
<Setting Target="Host" Name="BusinessRuleName">dc.irisMediCopilot.interop.FilterMessageRule</Setting>
<Item Name="Message.Router" Category="" ClassName="EnsLib.MsgRouter.RoutingEngine" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
<Setting Target="Host" Name="BusinessRuleName">dc.irisMediCopilot.interop.rule.FilterMessage</Setting>
</Item>
<Item Name="SpeechToText.Process" Category="" ClassName="dc.irisMediCopilot.interop.bp.Speach" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="true" Schedule="">
</Item>

<Item Name="TelegramVoice.Process" Category="" ClassName="dc.irisMediCopilot.interop.bp.Voice" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="true" Schedule="">
<Setting Target="Host" Name="BusinessRuleName">dc.irisMediCopilot.interop.rule.SpeechToText</Setting>
<Setting Target="Host" Name="ResponseTargetConfigNames">SpeechToText.Router</Setting>
</Item>

<Item Name="VoiceFile.Router" Category="" ClassName="EnsLib.MsgRouter.RoutingEngine" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
<Setting Target="Host" Name="BusinessRuleName">dc.irisMediCopilot.interop.rule.VoiceFile</Setting>
<Setting Target="Host" Name="ResponseFrom">VoiceFile.BusinessOperation</Setting>
</Item>
<Item Name="SpeechToText.Router" Category="" ClassName="EnsLib.MsgRouter.RoutingEngine" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
<Setting Target="Host" Name="BusinessRuleName">dc.irisMediCopilot.interop.rule.SpeechToText</Setting>
<Setting Target="Host" Name="RuleLogging">a</Setting>
<Setting Target="Host" Name="AlertOnBadMessage">1</Setting>
<Setting Target="Host" Name="ResponseFrom">OpenAi.BusinessOperation</Setting>
</Item>

<Item Name="VoiceFile.BusinessOperation" Category="" ClassName="dc.irisMediCopilot.interop.operation.VoiceFile" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="true" Schedule="">
<Setting Target="Adapter" Name="SSLConfig">tg</Setting>
<Setting Target="Adapter" Name="Token">Token</Setting>
</Item>

<Item Name="Telegram.BusinessOperation" Category="" ClassName="Telegram.BusinessOperation" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="true" Schedule="">
<Setting Target="Adapter" Name="SSLConfig">tg</Setting>
<Setting Target="Adapter" Name="Token">Token</Setting>
</Item>
<Item Name="OpenAi.BusinessOperation" Category="" ClassName="St.OpenAi.BO.Api.Connect" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
<Setting Target="Host" Name="ApiKey">Key</Setting>
<Setting Target="Host" Name="Organization"></Setting>
<Setting Target="Adapter" Name="SSLConfig">tg</Setting>
</Item>
</Production>
}
Expand Down
22 changes: 0 additions & 22 deletions src/dc/irisMediCopilot/interop/VoiceTransform.cls

This file was deleted.

32 changes: 32 additions & 0 deletions src/dc/irisMediCopilot/interop/bp/Speach.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Class dc.irisMediCopilot.interop.bp.Speach Extends Ens.BusinessProcessBPL
{

/// BPL Definition
XData BPL [ XMLNamespace = "http://www.intersystems.com/bpl" ]
{
<process language='objectscript' request='Telegram.Request' response='dc.irisMediCopilot.interop.msg.resp.Audio' height='2000' width='2000' >
<context>
<property name='audioRequest' type='St.OpenAi.Msg.Audio.AudioRequest' instantiate='0' />
<property name='audioResponse' type='St.OpenAi.Msg.Audio.AudioResponse' instantiate='0' />
</context>
<sequence xend='200' yend='650' >

<call name='Call API' target='OpenAi.BusinessOperation' async='1' xpos='200' ypos='350' >
<request type='St.OpenAi.Msg.Audio.AudioRequest' >
<assign property="callrequest" value="context.audioRequest" action="set" />
</request>
<response type='St.OpenAi.Msg.Audio.AudioResponse' >
<assign property="context.audioResponse" value="callresponse" action="set" />
</response>
</call>
<sync name='Wait Call APi' calls='Call API' type='all' xpos='200' ypos='450' />
</sequence>
</process>
}

Storage Default
{
<Type>%Storage.Persistent</Type>
}

}
29 changes: 29 additions & 0 deletions src/dc/irisMediCopilot/interop/bp/Voice.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Class dc.irisMediCopilot.interop.bp.Voice Extends Ens.BusinessProcessBPL
{

/// BPL Definition
XData BPL [ XMLNamespace = "http://www.intersystems.com/bpl" ]
{
<process language='objectscript' request='Telegram.Request' response='St.OpenAi.Msg.Audio.AudioResponse' height='2000' width='2000' >
<context>
<property name='voiceResponse' type='dc.irisMediCopilot.interop.msg.resp.Voice' instantiate='0' />
<property name='audioRequest' type='St.OpenAi.Msg.Audio.AudioRequest' instantiate='0' />
</context>
<sequence xend='200' yend='650' >
<call name='Get Voice' target='VoiceFile.BusinessOperation' async='1' xpos='200' ypos='250' >
<request type='Telegram.Request' >
<assign property="callrequest" value="request" action="set" />
</request>
<response type='dc.irisMediCopilot.interop.msg.resp.Voice' >
</response>
</call>
</sequence>
</process>
}

Storage Default
{
<Type>%Storage.Persistent</Type>
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Class dc.irisMediCopilot.interop.MessageTransformDTL Extends Ens.DataTransformDTL [ DependsOn = (Telegram.JSONContainer, Telegram.Request) ]
Class dc.irisMediCopilot.interop.dtl.MessageTransform Extends Ens.DataTransformDTL [ DependsOn = (Telegram.JSONContainer, Telegram.Request) ]
{

Parameter IGNOREMISSINGSOURCE = 1;
Expand Down
20 changes: 20 additions & 0 deletions src/dc/irisMediCopilot/interop/dtl/VoiceToOpenAi.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Class dc.irisMediCopilot.interop.dtl.VoiceToOpenAi Extends Ens.DataTransformDTL [ DependsOn = (dc.irisMediCopilot.interop.msg.resp.Voice, St.OpenAi.Msg.Audio.AudioRequest) ]
{

Parameter IGNOREMISSINGSOURCE = 1;

Parameter REPORTERRORS = 1;

Parameter TREATEMPTYREPEATINGFIELDASNULL = 0;

XData DTL [ XMLNamespace = "http://www.intersystems.com/dtl" ]
{
<transform sourceClass='dc.irisMediCopilot.interop.msg.resp.Voice' targetClass='St.OpenAi.Msg.Audio.AudioRequest' create='new' language='objectscript' >
<assign value='source.Audio' property='target.Audio' action='set' />
<assign value='source.Type' property='target.Type' action='set' />
<assign value='"transcription"' property='target.Operation' action='set' />
<assign value='"json"' property='target.ResponseFormat' action='set' />
</transform>
}

}
20 changes: 20 additions & 0 deletions src/dc/irisMediCopilot/interop/dtl/VoiceTransform.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Class dc.irisMediCopilot.interop.dtl.VoiceTransform Extends Ens.DataTransformDTL [ DependsOn = (Telegram.JSONContainer, Telegram.Request) ]
{

Parameter IGNOREMISSINGSOURCE = 1;

Parameter REPORTERRORS = 1;

Parameter TREATEMPTYREPEATINGFIELDASNULL = 0;

XData DTL [ XMLNamespace = "http://www.intersystems.com/dtl" ]
{
<transform sourceClass='Telegram.JSONContainer' targetClass='Telegram.Request' create='new' language='objectscript' >
<assign value='{}' property='target.Data' action='set' />
<assign value='source.Data.message.chat.id' property='target.Data."chat_id"' action='set' />
<assign value='source.Data.message.voice."file_id" ' property='target.Data."file_id"' action='set' />
<assign value='source.Data.message."message_id"' property='target.Data."reply_to_message_id"' action='set' />
</transform>
}

}
52 changes: 52 additions & 0 deletions src/dc/irisMediCopilot/interop/msg/req/Audio.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Class dc.irisMediCopilot.interop.msg.req.Audio Extends (Ens.Request, %JSON.Adaptor)
{

/// File id of the audio voice on Telegram
Property FileId As %String(%JSONFIELDNAME = "fileId");

/// Base64 of the audio to transcript/translate
Property Audio As %String(%JSONFIELDNAME = "audio", MAXLEN = "");

/// Type of file. (flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.)
Property Type As %String(%JSONFIELDNAME = "type", MAXLEN = "", VALUELIST = ",flac,mp3,mp4,mpeg,mpga,m4a,ogg,wav,webm") [ Required ];

/// Language to translate the audio
Property Language As %String(%JSONFIELDNAME = "lang", MAXLEN = 3);

/// Retrieve all the info about the audio or only the text
Property FullInfo As %Boolean(%JSONFIELDNAME = "fullInfo");

/// Operation
Property Operation As %String(%JSONINCLUDE = "none") [ InitialExpression = "transcription" ];

Storage Default
{
<Data name="AudioRequestDefaultData">
<Subscript>"AudioRequest"</Subscript>
<Value name="1">
<Value>Audio</Value>
</Value>
<Value name="2">
<Value>Language</Value>
</Value>
<Value name="3">
<Value>FullInfo</Value>
</Value>
<Value name="4">
<Value>Operation</Value>
</Value>
<Value name="5">
<Value>FileName</Value>
</Value>
<Value name="6">
<Value>Type</Value>
</Value>
<Value name="7">
<Value>FileId</Value>
</Value>
</Data>
<DefaultData>AudioRequestDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
}

}
28 changes: 28 additions & 0 deletions src/dc/irisMediCopilot/interop/msg/req/Prompt.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Class dc.irisMediCopilot.interop.msg.req.Prompt Extends (Ens.Request, %JSON.Adaptor)
{

Property Prompt As %String(%JSONFIELDNAME = "prompt", MAXLEN = "");

Property MaxTokens As %Integer(%JSONFIELDNAME = "max_tokens");

Property Model As %String(%JSONFIELDNAME = "model", MAXLEN = "");

Storage Default
{
<Data name="ChatRequestDefaultData">
<Subscript>"ChatRequest"</Subscript>
<Value name="1">
<Value>Prompt</Value>
</Value>
<Value name="2">
<Value>MaxTokens</Value>
</Value>
<Value name="3">
<Value>Model</Value>
</Value>
</Data>
<DefaultData>ChatRequestDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
}

}
37 changes: 37 additions & 0 deletions src/dc/irisMediCopilot/interop/msg/req/Voice.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Class dc.irisMediCopilot.interop.msg.req.Voice Extends (Ens.Request, %JSON.Adaptor)
{

/// Telgram Chat Id
Property ChatId As %Integer(%JSONFIELDNAME = "chat_id");

/// File id of the audio voice on Telegram
Property FileId As %String(%JSONFIELDNAME = "file_id", MAXLEN = 1000);

/// Telegram Token
Property Token As %String(%JSONFIELDNAME = "token", MAXLEN = 1000);

/// File type. (flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm.) Default: "ogg"
Property Type As %String(%JSONFIELDNAME = "type", MAXLEN = "", VALUELIST = ",flac,mp3,mp4,mpeg,mpga,m4a,ogg,wav,webm") [ InitialExpression = "ogg" ];

Storage Default
{
<Data name="VoiceDefaultData">
<Subscript>"Voice"</Subscript>
<Value name="1">
<Value>FileId</Value>
</Value>
<Value name="2">
<Value>Token</Value>
</Value>
<Value name="3">
<Value>ChatId</Value>
</Value>
<Value name="4">
<Value>Type</Value>
</Value>
</Data>
<DefaultData>VoiceDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
}

}
33 changes: 33 additions & 0 deletions src/dc/irisMediCopilot/interop/msg/resp/Audio.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Class dc.irisMediCopilot.interop.msg.resp.Audio Extends (Ens.Response, %JSON.Adaptor)
{

Property Task As %String(%JSONFIELDNAME = "task", MAXLEN = "");

Property Language As %String(%JSONFIELDNAME = "language", MAXLEN = "");

Property Duration As %Decimal(%JSONFIELDNAME = "duration");

Property Text As %String(%JSONFIELDNAME = "text", MAXLEN = "");

Storage Default
{
<Data name="AudioResponseDefaultData">
<Subscript>"AudioResponse"</Subscript>
<Value name="1">
<Value>Task</Value>
</Value>
<Value name="2">
<Value>Language</Value>
</Value>
<Value name="3">
<Value>Duration</Value>
</Value>
<Value name="4">
<Value>Text</Value>
</Value>
</Data>
<DefaultData>AudioResponseDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
}

}
18 changes: 18 additions & 0 deletions src/dc/irisMediCopilot/interop/msg/resp/Prompt.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Class dc.irisMediCopilot.interop.msg.resp.Prompt Extends (Ens.Response, %JSON.Adaptor)
{

Property Content As %String(%JSONFIELDNAME = "content", MAXLEN = "");

Storage Default
{
<Data name="ChatResponseDefaultData">
<Subscript>"ChatResponse"</Subscript>
<Value name="1">
<Value>Content</Value>
</Value>
</Data>
<DefaultData>ChatResponseDefaultData</DefaultData>
<Type>%Storage.Persistent</Type>
}

}
Loading

0 comments on commit 9beac87

Please sign in to comment.