chatgpt spring boot starter
v1.0.5
該起動器基於Openai官方API。您可以輕鬆地在Springboot Project中使用ChatGpt。
聊天
您可以使用許多型號與Chatgpt聊天。此外,支持多消息,因此您可以將一系列消息(包括對話歷史記錄)作為輸入,並獲取響應消息。
圖像生成
給出提示並獲得生成的圖像。
<dependency>
<groupId>io.github.flashvayne</groupId>
<artifactId>chatgpt-spring-boot-starter</artifactId>
<version>1.0.5</version>
</dependency>
chatgpt :
api-key : xxxxxxxxxxx # api-key. It can be generated here https://platform.openai.com/account/api-keys
# some more properties(model,max-tokens...etc.) have default values. Also you can config them here. @ Autowired
private ChatgptService chatgptService ;
public void test (){
String responseMessage = chatgptService . multiChat ( Arrays . asList ( new MultiChatMessage ( "user" , "how are you?" )));
System . out . print ( responseMessage ); //nnAs an AI language model, I don't have feelings, but I'm functioning well. Thank you for asking. How can I assist you today?
}
public void test2 (){
String responseMessage = chatgptService . sendMessage ( "how are you" );
System . out . print ( responseMessage ); //I'm doing well, thank you. How about you?
} @ Autowired
private ChatgptService chatgptService ;
public void testMultiChat (){
List < MultiChatMessage > messages = Arrays . asList (
new MultiChatMessage ( "system" , "You are a helpful assistant." ),
new MultiChatMessage ( "user" , "Who won the world series in 2020?" ),
new MultiChatMessage ( "assistant" , "The Los Angeles Dodgers won the World Series in 2020." ),
new MultiChatMessage ( "user" , "Where was it played?" ));
String responseMessage = chatgptService . multiChat ( messages );
System . out . print ( responseMessage ); //The 2020 World Series was played at Globe Life Field in Arlington, Texas.
} @ Autowired
private ChatgptService chatgptService ;
public void testImage (){
String imageUrl = chatgptService . imageGenerate ( "A cute baby sea otter" );
System . out . print ( imageUrl ); //https://oaidalleapip.......
}
public void testImageList (){
List < String > images = chatgptService . imageGenerate ( "A cute baby sea otter" , 2 , ImageSize . SMALL , ImageFormat . URL );
System . out . print ( images . toString ()); //["https://oaidalleapipr.....ZwA%3D","https://oaidalleapipr....RE0%3D"]
}demo-chatgpt-spring-boot-starter
電子郵件:[email protected]
博客:https://vayne.cc
感謝Jetbrains對這個項目的支持。他們為我們提供了噴氣橋開發工具。