
智能Java(Intellijava)是使用Java與最新語言模型和深度學習框架集成的最終工具。該庫提供了一個直觀的功能,用於將輸入發送到諸如Chatgpt和dall·e之類的模型,並接收生成的文本,語音或圖像。只需幾行代碼,您就可以輕鬆地訪問尖端AI模型的力量以增強您的項目。
受支持的模型:
RemoteLanguageModel ,用於圖像生成的RemoteImageModel , RemoteSpeechModel ,用於語音模型的文本和聊天Chatbot 。 發布給Maven Central存儲庫的軟件包:
馬文:
< dependency >
< groupId >io.github.barqawiz</ groupId >
< artifactId >intellijava.core</ artifactId >
< version >0.8.2</ version >
</ dependency >Gradle:
implementation 'io.github.barqawiz:intellijava.core:0.8.2'
Gradle(Kotlin):
implementation("io.github.barqawiz:intellijava.core:0.8.2")
JAR下載:Intellijava.jar。
語言模型代碼(2個步驟):
// 1- initiate the remote language model
String apiKey = "<add-openai-api-key>" ;
RemoteLanguageModel langModel = new RemoteLanguageModel ( apiKey , "openai" );
// 2- call generateText with any command !
LanguageModelInput langInput = new LanguageModelInput . Builder ( "Summarize the plot of the 'Inception' movie in two sentences" )
. setModel ( "text-davinci-003" ). setTemperature ( 0.7f ). setMaxTokens ( 50 ). build ();
String resValue = langModel . generateText ( langInput );輸出: Inception follows Dom Cobb, a professional thief, who is offered a chance at redemption in exchange for planting an idea in a target's mind. He must navigate a dangerous landscape of dream-sharing technology and battle his inner demons in order to complete the mission and find his way back to reality.
圖像生成代碼(2個步驟):
// 1- initiate the remote image model
RemoteImageModel imageModel = new RemoteImageModel ( apiKey , "openai" );
// 2- call generateImages with any command !
ImageModelInput imageInput = new ImageModelInput . Builder ( "teddy writing a blog in times square" )
. setNumberOfImages ( 2 ). setImageSize ( "1024x1024" ). build ();
List < String > images = imageModel . generateImages ( imageInput );輸出: 
文本到語音代碼(2個步驟):
// 1- initiate the remote speech model
RemoteSpeechModel model = new RemoteSpeechModel ( apiKey , SpeechModels . google );
// 2- call generateEnglishText with any text
Text2SpeechInput input = new Text2SpeechInput . Builder ( "Hi, I am Intelligent Java." ). build ();
byte [] decodedAudio = model . generateEnglishText ( input );輸出:
// save temporary audio file for testing
AudioHelper . saveTempAudio ( decodedAudio );chatgpt代碼:
// 1- initiate the chat model.
Chatbot bot = new Chatbot ( apiKey , SupportedChatModels . openai );
// 2- prepare the chat history by calling addMessage.
String mode = "You are a helpful astronomy assistant." ;
ChatModelInput input = new ChatGPTInput . Builder ( mode )
. addUserMessage ( "what is the space between moon and earth" ). build ();
// 3- call chat!
List < String > resValues = bot . chat ( input );輸出: The average distance between the Moon and the Earth is about 238,855 miles (384,400 kilometers).
有關完整示例並準備好的集成,請嘗試sample_code。
唯一的依賴性是Gson 。使用Intellijava Jar時需要手動添加。但是,如果您通過Maven導入此存儲庫,它將處理依賴關係。
用於罐子下載:GSON下載回購
呼籲貢獻者:
Apache許可證
版權2023 github.com/barqawiz/intellijava
根據Apache許可證(版本2.0(“許可”)獲得許可;除了符合許可外,您不得使用此文件。您可以在
http://www.apache.org/licenses/LICENSE-2.0
除非適用法律要求或以書面形式同意,否則根據許可證分配的軟件是按照“原樣”分發的,沒有任何明示或暗示的任何形式的保證或條件。請參閱許可證,以獲取執行許可條款和限制的特定語言。