├── docs ├── audio.md ├── chat.md ├── files.md ├── image.md ├── models.md ├── moderations.md ├── assets │ └── apl385.ttf ├── img │ ├── SquidError.PNG │ ├── favicon-32.png │ └── dyalog-white.svg ├── release-notes.md ├── LICENSE.md ├── css │ └── main.css ├── quickstart.md ├── index.md ├── userguide.md └── demos.md ├── .gitignore ├── demos ├── demos.zip ├── Chat.aplf ├── ShowImage.aplf ├── ShowText.aplf ├── Play.aplf ├── Linguist.aplf ├── Image.aplf ├── Translation.aplf ├── Setup.aplf ├── Transcription.aplf ├── Speech.aplf └── OpenAI.apln ├── README.md ├── apl-package.json ├── LICENSE ├── mkdocs.yml └── source └── OpenAI.apln /docs/audio.md: -------------------------------------------------------------------------------- 1 | Pending publication -------------------------------------------------------------------------------- /docs/chat.md: -------------------------------------------------------------------------------- 1 | Pending publication -------------------------------------------------------------------------------- /docs/files.md: -------------------------------------------------------------------------------- 1 | Pending publication -------------------------------------------------------------------------------- /docs/image.md: -------------------------------------------------------------------------------- 1 | Pending publication -------------------------------------------------------------------------------- /docs/models.md: -------------------------------------------------------------------------------- 1 | Pending publication -------------------------------------------------------------------------------- /docs/moderations.md: -------------------------------------------------------------------------------- 1 | Pending publication -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.dlf 2 | *.rng* 3 | site/ 4 | demos/demos.zip -------------------------------------------------------------------------------- /demos/demos.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dyalog/OpenAI/main/demos/demos.zip -------------------------------------------------------------------------------- /docs/assets/apl385.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dyalog/OpenAI/main/docs/assets/apl385.ttf -------------------------------------------------------------------------------- /docs/img/SquidError.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dyalog/OpenAI/main/docs/img/SquidError.PNG -------------------------------------------------------------------------------- /docs/img/favicon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dyalog/OpenAI/main/docs/img/favicon-32.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenAI 2 | Dyalog APL interface to OpenAI API 3 | 4 | Documentation can be found [here](https://dyalog.github.io/OpenAI). 5 | -------------------------------------------------------------------------------- /docs/release-notes.md: -------------------------------------------------------------------------------- 1 | ## Version 0.4.0 2 | This is the initial release of `OpenAI`. It implements interfaces to the following OpenAI endpoints: audio, chat, files, image, models, and moderations. Additional interfaces to other OpenAI endpoints will be available in future releases. 3 | 4 | A set of demos is available in the demos folder -------------------------------------------------------------------------------- /apl-package.json: -------------------------------------------------------------------------------- 1 | { 2 | api: "OpenAI", 3 | assets: "", 4 | description: "Utilities to interface with the OpenAI API", 5 | documentation: "https://dyalog.github.io/OpenAI", 6 | files: "", 7 | group: "dyalog", 8 | io: 1, 9 | license: "MIT", 10 | lx: "", 11 | maintainer: "", 12 | minimumAplVersion: "18.0", 13 | ml: 1, 14 | name: "OpenAI", 15 | os_lin: 1, 16 | os_mac: 1, 17 | os_win: 1, 18 | project_url: "https://github.com/Dyalog/OpenAI", 19 | source: "source/OpenAI.apln", 20 | tags: "mac-os,windows,linux,dyalog,pi,llm,openai", 21 | userCommandScript: "", 22 | version: "0.1.0+1", 23 | } 24 | -------------------------------------------------------------------------------- /demos/Chat.aplf: -------------------------------------------------------------------------------- 1 | Chat;⎕ML;⎕IO;inp;system;c;user;resp;msg 2 | (⎕ML ⎕IO)←1 1 3 | 4 | ⍝ Check that OpenAI is present 5 | :If 9.1≠⎕NC⊂'OpenAI' ⋄ →0⊣⎕←'OpenAI is not loaded, please run Setup' ⋄ :EndIf 6 | 7 | ⍝ Make sure the OpenAI.APIKey is set 8 | :If 0∊⍴OpenAI.APIKey ⋄ →0⊣⎕←'OpenAPI.APIKey has not been set, please run Setup' ⋄ :EndIf 9 | 10 | inp←{inp←⍞⊣⍞←⍵ ⋄ inp↓⍨+/∧\=⌿↑inp ⍵} 11 | 12 | system←inp'Describe the assistant you would like to chat with: ' 13 | c←OpenAI.Chat.Completion system 14 | 15 | loop:→0⍴⍨0∊⍴user←inp'Enter user message: ' 16 | c.User user 17 | resp←c.Run 18 | 19 | :If 0≠resp.rc ⋄ msg←'** OpenAI Chat request failed due to: ',resp.msg 20 | :ElseIf 200≠resp.HttpStatus ⋄ msg←{0::⍵.HttpStatus ⋄ ⍵.Data.error.message}resp 21 | :Else ⋄ →loop⊣⎕←1⌽(2⍴⎕UCS 13),80 OpenAI.U.Wrap (⊢/c.messages).content 22 | :EndIf 23 | →loop⊣⎕←'** ',msg 24 | -------------------------------------------------------------------------------- /demos/ShowImage.aplf: -------------------------------------------------------------------------------- 1 | ShowImage args;⎕ML;⎕IO;h 2 | (⎕ML ⎕IO)←1 1 3 | ⍝ Shows text in an HTMLRenderer window 4 | ⍝ args is either the text to Show 5 | ⍝ or the result from Transcription or Translation which is a return code followed by a message 6 | ⍝ If the return code is 0, the message is the text to show 7 | ⍝ If the return code is not 0, the message is an indication of what went wrong 8 | :If 2=|≡args 9 | :If 0≠⊃args 10 | →0⊣⎕←'Unable to create image due to ',⍕args 11 | :Else ⋄ args←2⊃args 12 | :EndIf 13 | :EndIf 14 | 15 | ⍝ now try to open an HTMLRenderer to display the image 16 | :Trap 0 17 | 'h'⎕WC'HTMLRenderer'('Coord' 'Pixel')('Size'(720 700))('HTML'('')) 18 | {}⎕DQ h 19 | :Else 20 | →0⊣⎕←⎕DMX.('A ',EM,' (',Message,') occurred while trying to play the audio file') 21 | :EndTrap 22 | -------------------------------------------------------------------------------- /demos/ShowText.aplf: -------------------------------------------------------------------------------- 1 | ShowText args;⎕ML;⎕IO;h 2 | (⎕ML ⎕IO)←1 1 3 | ⍝ Shows text in an HTMLRenderer window 4 | ⍝ args is either the text to Show 5 | ⍝ or the result from Transcription or Translation which is a return code followed by a message 6 | ⍝ If the return code is 0, the message is the text to show 7 | ⍝ If the return code is not 0, the message is an indication of what went wrong 8 | :If 2=|≡args 9 | :If 0≠⊃args 10 | →0⊣⎕←'Unable to convert the your text due to ',⍕args 11 | :Else ⋄ args←2⊃args 12 | :EndIf 13 | :EndIf 14 | 15 | ⍝ now try to open an HTMLRenderer to play the audiofile 16 | :Trap 0 17 | 'h'⎕WC'HTMLRenderer'('Coord' 'Prop')('Size'(75 75))('HTML'('

',('\. '⎕R'.
'⊢args),'

')) 18 | {}⎕DQ h 19 | :Else 20 | →0⊣⎕←⎕DMX.('A ',EM,' (',Message,') occurred while trying to play the audio file') 21 | :EndTrap 22 | -------------------------------------------------------------------------------- /demos/Play.aplf: -------------------------------------------------------------------------------- 1 | Play args;⎕ML;⎕IO;data;h;html 2 | (⎕ML ⎕IO)←1 1 3 | ⍝ Plays an audio file 4 | ⍝ args is either the name of a .mp3 audio file to play 5 | ⍝ or the result from Speech which is a return code followed by a message 6 | ⍝ If the return code is 0, the message is the name of a .mp3 audio file 7 | ⍝ If the return code is not 0, the message is an indication of what went wrong 8 | ⍝ auto is optional and indicates whether to automatically play the audio 9 | :If 2=|≡args 10 | :If 0≠⊃args 11 | →0⊣⎕←'Speech was unable to convert the your text due to ',⍕args 12 | :Else ⋄ args←2⊃args 13 | :EndIf 14 | :EndIf 15 | 16 | ⍝ now try to open an HTMLRenderer to play the audiofile 17 | :Trap 0 18 | data←OpenAI.HttpCommand.Base64Encode{(⎕NUNTIE t)⊢⎕NREAD t,83,2↑t←⍵ ⎕NTIE 0}args 19 | html←'