การใช้งาน Spring AI ใหม่ของ https://github.com/marcushellberg/java-ai-playground
แอปนี้แสดงวิธีที่คุณสามารถใช้ Spring AI เพื่อสร้างระบบที่ขับเคลื่อนด้วย AI ที่:
OPENAI_API_KEY
เรียกใช้แอปโดยเรียกใช้ Application.java
ใน IDE หรือ mvn
ของคุณในบรรทัดคำสั่ง
เพิ่มตัวเริ่มต้นการบูต Spring AI Open AI ลงใน POM:
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-openai-spring-boot-starter</ artifactId >
</ dependency >
เพิ่มการกำหนดค่า OpenAI ให้กับ application.properties
:
spring.ai.openai.api-key=${OPENAI_API_KEY}
spring.ai.openai.chat.options.model=gpt-4o
เพิ่มตัวเริ่มต้นการบูต Spring AI VertexAI Gemini และ Onnx Transformer Embedding ลงใน POM:
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-vertex-ai-gemini-spring-boot-starter</ artifactId >
</ dependency >
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-transformers-spring-boot-starter</ artifactId >
</ dependency >
เพิ่มการกำหนดค่า VertexAI Gemini ให้กับ application.properties
:
spring.ai.vertex.ai.gemini.project-id=${VERTEX_AI_GEMINI_PROJECT_ID}
spring.ai.vertex.ai.gemini.location=${VERTEX_AI_GEMINI_LOCATION}
spring.ai.vertex.ai.gemini.chat.options.model=gemini-1.5-pro-001
# spring.ai.vertex.ai.gemini.chat.options.model=gemini-1.5-flash-001
เพิ่มตัวเริ่มต้นการบูต Spring AI Azure OpenAI ลงใน POM:
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-azure-openai-spring-boot-starter</ artifactId >
</ dependency >
เพิ่มการกำหนดค่า Azure OpenAI ให้กับ application.properties
:
spring.ai.azure.openai.api-key=${AZURE_OPENAI_API_KEY}
spring.ai.azure.openai.endpoint=${AZURE_OPENAI_ENDPOINT}
spring.ai.azure.openai.chat.options.deployment-name=gpt-4o
มันนำไคลเอนต์ OpenAI Chat มาใช้ซ้ำ แต่ชี้ไปที่จุดสิ้นสุด Groq
เพิ่มตัวเริ่มต้นการบูต Spring AI Open AI ลงใน POM:
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-openai-spring-boot-starter</ artifactId >
</ dependency >
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-transformers-spring-boot-starter</ artifactId >
</ dependency >
เพิ่มการกำหนดค่า Groq ให้กับ application.properties
:
spring.ai.openai.api-key=${GROQ_API_KEY}
spring.ai.openai.base-url=https://api.groq.com/openai
spring.ai.openai.chat.options.model=llama3-70b-8192
เพิ่มตัวเริ่มต้นการบูต Spring AI Anthropic Claude และ Onnx Transformer Embedding ลงใน POM:
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-anthropic-spring-boot-starter</ artifactId >
</ dependency >
< dependency >
< groupId >org.springframework.ai</ groupId >
< artifactId >spring-ai-transformers-spring-boot-starter</ artifactId >
</ dependency >
เพิ่มการกำหนดค่า Anthropic ให้กับ application.properties
:
spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
spring.ai.openai.chat.options.model=llama3-70b-8192
spring.ai.anthropic.chat.options.model=claude-3-5-sonnet-20240620
./mvnw clean install -Pproduction
java -jar ./target/playground-flight-booking-0.0.1-SNAPSHOT.jar
docker run -it --rm --name postgres -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres ankane/pgvector