
智能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
除非适用法律要求或以书面形式同意,否则根据许可证分配的软件是按照“原样”分发的,没有任何明示或暗示的任何形式的保证或条件。请参阅许可证,以获取执行许可条款和限制的特定语言。