SlideShare uma empresa Scribd logo
1 de 9
Baixar para ler offline
Unlocking the Potential of AI in Spring
• Spring AI is a newly released Spring project, and it takes inspiration from
notable Python projects, such as LangChain and LlamaIndex.
• The Spring AI project aims to simplify the creation of applications integrating
artificial intelligence capabilities by reducing unnecessary complexity.
• With the help of Spring AI, we can integrate the AI APIs (OpenAI) in the spring
applications.
• Artificial Intelligence (AI) Concept
• Model
• AI models are algorithms designed to process and generate information.
• These models can make predictions, images, text, or other outputs by learning
patterns and from large datasets
• There are many different types of AI models, and Each model is suited for the
specific use case
• While ChatGPT and its generative AI capabilities have captivated users
through text input and output, many models and companies offer diverse
inputs and outputs.
• Prompts
• Prompts refer to the query or input that we provide to an AI model to get the
desired response
• Prompts are what guide the AI model’s output and influence its tone, style,
and quality.
• Prompts can include instructions, questions, or any other type of input,
depending on the intended use of the model.
• Prompt Templates
• Prompt Template is one type of predefined or reusable structure for the
prompt
• Prompt templates provide a standardized format or set of instructions that we
can follow to interact with language models effectively.
• These templates include placeholders where we can insert specific
information relevant to their task.
• Spring AI employs the OSS library, String Template, for this purpose.
• Ex: “Translate the following text into {language}: {text}”.
• The above example is of a Prompt Template where language and text are
placeholder which will be taken from the request.
• Embeddings
• Embeddings transform text into numerical arrays or vectors, enabling AI
models to process and interpret language data.
• This transformation from text to numbers and back is a key element in how AI
interacts with and understands human language.
• Tokens
• Tokens serve as the building blocks of how an AI model works.
• On input, models convert words to tokens. On output, they convert tokens
back to words
• Both input and output contribute to the overall token count. Also, models are
subject to token limits, which restrict the amount of text processed in a single
API call.
• This threshold is often referred to as the ‘context window’. The model does
not process any text that exceeds this limit.
• Output Parsing
• AI models typically generate responses in string format, but output parsers
come into use when you need the output in different formats.
• These parsers reformat these raw strings into more programmer-friendly
structures like CSV (Comma-Separated Values) or JSON (JavaScript Object
Notation).
• Bringing Your Data to the AI model
• When you ask the question beyond the model dates then the model says that
it does not know the answer to questions that require knowledge beyond that
date
• In GPT 3.5/4.0, the dataset extends only until September 2021. So, It gives the
same answer when you ask questions beyond September 2021
• Two techniques exist to customize the AI model to incorporate your data:
o Fine Tuning: This traditional machine-learning technique involves
tailoring the model and changing its internal weighting. However, it is
Expensive and Hard to do. Additionally, some models might not offer
this option.
o Prompt Stuffing: A more practical alternative involves embedding your
data within the prompt provided to the model. Given a model’s token
limits, techniques are required to present relevant data within the
model’s context window. This approach is commonly referred to as
“stuffing the prompt.”
• Also Learn: Guide to Spring Reactive Programming using Spring WebFlux
• Generate Spring AI Project Using CLI
• Download the Zip of Spring cli according to your system
• Extract it
• Open the Terminal and add the below command to use the spring command
• alias spring=’java -jar $HOME/path to your jar file /spring-cli-0.8.1.jar’
NOTE: path to your jar file replace this with your jar file path
• To generate a Spring boot project use the command: spring boot new ai
• Go Inside the project and hit the below command to generate spring ai Apis
spring boot add ai
• Generate Spring AI Project Using
Spring Initializer
• Definition: In the input user will provide the state and Spring AI will give the
List of the cities from the provided state
• Generate Spring boot project with below dependency and Repository inside
pom.xml
• For the Spring AI, org.springframework.ai dependency and repository are
required
Create Models of City
City
CityList
Create CityService with the below code
Here,
ChatClient is an interface used to interact with AI models
The design of the ChatClient interface centers around two primary goals:
Portability: The system facilitates seamless integration with various AI Models,
enabling developers to transition b BeanOutputParser between different models
with minimal adjustments to the codebase. This approach is in harmony with
Spring’s ethos of modularity and flexibility.
Simplicity: Leveraging companion classes such as Prompt for input
encapsulation and ChatResponse for output handling, the ChatClient interface
streamlines interactions with AI Models. It abstracts away the intricacies of
request formulation and response interpretation, providing a straightforward and
simplified API interaction experience.
Here,
BeanOutputParser is used to get the output in a specific format by default it will
return in normal text format
PrompTemplate provides a standardized format that we can follow to interact
with language models effectively
The prompt is used to generate the specific output based on the provided string
ChatClient.call(prompt) will generate the response based on a given prompt
Create CityController with the below code.
Call methods of service from this controller. getAnswer API is the basic example
for passing a question in a URL and getting the answers.
Now, we have two endpoints.
1. http://localhost:8080/spring/ai/cities/{state}
o In the above endpoint, we must provide the state in the input, and it will give the
list of cities according to the state.
o As displayed below, we got the response in proper format as we have provided
parser.getFormat()
2. http://localhost:8080/spring/ai/question/Top singer details of India
1. In the above endpoint, we can provide any text input and it will generate the
response accordingly.
2. As displayed below, we got the response in simple text format.
Originally published by: Unlocking the Potential of AI in Spring
Unlocking the Potential of AI in Spring.pdf

Mais conteúdo relacionado

Semelhante a Unlocking the Potential of AI in Spring.pdf

MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
 MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ... MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
Databricks
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
NLJUG
 

Semelhante a Unlocking the Potential of AI in Spring.pdf (20)

Build an LLM-powered application using LangChain.pdf
Build an LLM-powered application using LangChain.pdfBuild an LLM-powered application using LangChain.pdf
Build an LLM-powered application using LangChain.pdf
 
Build an LLM-powered application using LangChain.pdf
Build an LLM-powered application using LangChain.pdfBuild an LLM-powered application using LangChain.pdf
Build an LLM-powered application using LangChain.pdf
 
Software Modeling and Artificial Intelligence: friends or foes?
Software Modeling and Artificial Intelligence: friends or foes?Software Modeling and Artificial Intelligence: friends or foes?
Software Modeling and Artificial Intelligence: friends or foes?
 
MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
 MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ... MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
MLflow: Infrastructure for a Complete Machine Learning Life Cycle with Mani ...
 
Build an LLM-powered application using LangChain.pdf
Build an LLM-powered application using LangChain.pdfBuild an LLM-powered application using LangChain.pdf
Build an LLM-powered application using LangChain.pdf
 
Final Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee Applicaties
Final Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee ApplicatiesFinal Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee Applicaties
Final Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee Applicaties
 
Integrating Machine Learning Capabilities into your team
Integrating Machine Learning Capabilities into your teamIntegrating Machine Learning Capabilities into your team
Integrating Machine Learning Capabilities into your team
 
Pa1 session 6
Pa1 session 6Pa1 session 6
Pa1 session 6
 
Practices and tools for building better APIs
Practices and tools for building better APIsPractices and tools for building better APIs
Practices and tools for building better APIs
 
Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)Practices and tools for building better API (JFall 2013)
Practices and tools for building better API (JFall 2013)
 
Vertex AI: Pipelines for your MLOps workflows
Vertex AI: Pipelines for your MLOps workflowsVertex AI: Pipelines for your MLOps workflows
Vertex AI: Pipelines for your MLOps workflows
 
Swift programming language
Swift programming languageSwift programming language
Swift programming language
 
introduction Azure OpenAI by Usama wahab khan
introduction  Azure OpenAI by Usama wahab khanintroduction  Azure OpenAI by Usama wahab khan
introduction Azure OpenAI by Usama wahab khan
 
Student mark Prediction application.pptx
Student mark Prediction application.pptxStudent mark Prediction application.pptx
Student mark Prediction application.pptx
 
Autonomous Machines with Project Bonsai
Autonomous Machines with Project BonsaiAutonomous Machines with Project Bonsai
Autonomous Machines with Project Bonsai
 
DAA Unit 1.pdf
DAA Unit 1.pdfDAA Unit 1.pdf
DAA Unit 1.pdf
 
ChatGPT and AI for web developers - Maximiliano Firtman
ChatGPT and AI for web developers - Maximiliano FirtmanChatGPT and AI for web developers - Maximiliano Firtman
ChatGPT and AI for web developers - Maximiliano Firtman
 
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitAugmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
 
Vedic Calculator
Vedic CalculatorVedic Calculator
Vedic Calculator
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming Go
 

Mais de Inexture Solutions

Mais de Inexture Solutions (20)

Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
Spring Boot for WebRTC Signaling Servers: A Comprehensive GuideSpring Boot for WebRTC Signaling Servers: A Comprehensive Guide
Spring Boot for WebRTC Signaling Servers: A Comprehensive Guide
 
Mobile App Development Cost 2024 Budgeting Your Dream App
Mobile App Development Cost 2024 Budgeting Your Dream AppMobile App Development Cost 2024 Budgeting Your Dream App
Mobile App Development Cost 2024 Budgeting Your Dream App
 
Data Serialization in Python JSON vs. Pickle
Data Serialization in Python JSON vs. PickleData Serialization in Python JSON vs. Pickle
Data Serialization in Python JSON vs. Pickle
 
Best EV Charging App 2024 A Tutorial on Building Your Own
Best EV Charging App 2024 A Tutorial on Building Your OwnBest EV Charging App 2024 A Tutorial on Building Your Own
Best EV Charging App 2024 A Tutorial on Building Your Own
 
What is a WebSocket? Real-Time Communication in Applications
What is a WebSocket? Real-Time Communication in ApplicationsWhat is a WebSocket? Real-Time Communication in Applications
What is a WebSocket? Real-Time Communication in Applications
 
SaaS Application Development Explained in 10 mins
SaaS Application Development Explained in 10 minsSaaS Application Development Explained in 10 mins
SaaS Application Development Explained in 10 mins
 
Best 7 SharePoint Migration Tools of 2024
Best 7 SharePoint Migration Tools of 2024Best 7 SharePoint Migration Tools of 2024
Best 7 SharePoint Migration Tools of 2024
 
Spring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdfSpring Boot with Microsoft Azure Integration.pdf
Spring Boot with Microsoft Azure Integration.pdf
 
Best Features of Adobe Experience Manager (AEM).pdf
Best Features of Adobe Experience Manager (AEM).pdfBest Features of Adobe Experience Manager (AEM).pdf
Best Features of Adobe Experience Manager (AEM).pdf
 
React Router Dom Integration Tutorial for Developers
React Router Dom Integration Tutorial for DevelopersReact Router Dom Integration Tutorial for Developers
React Router Dom Integration Tutorial for Developers
 
Python Kafka Integration: Developers Guide
Python Kafka Integration: Developers GuidePython Kafka Integration: Developers Guide
Python Kafka Integration: Developers Guide
 
What is SaMD Model, Benefits, and Development Process.pdf
What is SaMD Model, Benefits, and Development Process.pdfWhat is SaMD Model, Benefits, and Development Process.pdf
What is SaMD Model, Benefits, and Development Process.pdf
 
Mobile Banking App Development Cost in 2024.pdf
Mobile Banking App Development Cost in 2024.pdfMobile Banking App Development Cost in 2024.pdf
Mobile Banking App Development Cost in 2024.pdf
 
Education App Development : Cost, Features and Example
Education App Development : Cost, Features and ExampleEducation App Development : Cost, Features and Example
Education App Development : Cost, Features and Example
 
Firebase Push Notification in JavaScript Apps
Firebase Push Notification in JavaScript AppsFirebase Push Notification in JavaScript Apps
Firebase Push Notification in JavaScript Apps
 
Micronaut Framework Guide Framework Basics and Fundamentals.pdf
Micronaut Framework Guide Framework Basics and Fundamentals.pdfMicronaut Framework Guide Framework Basics and Fundamentals.pdf
Micronaut Framework Guide Framework Basics and Fundamentals.pdf
 
Steps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MACSteps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MAC
 
Python Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txtPython Requirements File How to Create Python requirements.txt
Python Requirements File How to Create Python requirements.txt
 
Gain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring BatchGain Proficiency in Batch Processing with Spring Batch
Gain Proficiency in Batch Processing with Spring Batch
 
Explore the System Development Life Cycle and Phases
Explore the System Development Life Cycle and PhasesExplore the System Development Life Cycle and Phases
Explore the System Development Life Cycle and Phases
 

Último

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Último (20)

How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 

Unlocking the Potential of AI in Spring.pdf

  • 1. Unlocking the Potential of AI in Spring • Spring AI is a newly released Spring project, and it takes inspiration from notable Python projects, such as LangChain and LlamaIndex. • The Spring AI project aims to simplify the creation of applications integrating artificial intelligence capabilities by reducing unnecessary complexity. • With the help of Spring AI, we can integrate the AI APIs (OpenAI) in the spring applications. • Artificial Intelligence (AI) Concept • Model • AI models are algorithms designed to process and generate information. • These models can make predictions, images, text, or other outputs by learning patterns and from large datasets • There are many different types of AI models, and Each model is suited for the specific use case
  • 2. • While ChatGPT and its generative AI capabilities have captivated users through text input and output, many models and companies offer diverse inputs and outputs. • Prompts • Prompts refer to the query or input that we provide to an AI model to get the desired response • Prompts are what guide the AI model’s output and influence its tone, style, and quality. • Prompts can include instructions, questions, or any other type of input, depending on the intended use of the model. • Prompt Templates • Prompt Template is one type of predefined or reusable structure for the prompt • Prompt templates provide a standardized format or set of instructions that we can follow to interact with language models effectively. • These templates include placeholders where we can insert specific information relevant to their task. • Spring AI employs the OSS library, String Template, for this purpose. • Ex: “Translate the following text into {language}: {text}”. • The above example is of a Prompt Template where language and text are placeholder which will be taken from the request. • Embeddings • Embeddings transform text into numerical arrays or vectors, enabling AI models to process and interpret language data. • This transformation from text to numbers and back is a key element in how AI interacts with and understands human language. • Tokens • Tokens serve as the building blocks of how an AI model works.
  • 3. • On input, models convert words to tokens. On output, they convert tokens back to words • Both input and output contribute to the overall token count. Also, models are subject to token limits, which restrict the amount of text processed in a single API call. • This threshold is often referred to as the ‘context window’. The model does not process any text that exceeds this limit. • Output Parsing • AI models typically generate responses in string format, but output parsers come into use when you need the output in different formats. • These parsers reformat these raw strings into more programmer-friendly structures like CSV (Comma-Separated Values) or JSON (JavaScript Object Notation). • Bringing Your Data to the AI model • When you ask the question beyond the model dates then the model says that it does not know the answer to questions that require knowledge beyond that date • In GPT 3.5/4.0, the dataset extends only until September 2021. So, It gives the same answer when you ask questions beyond September 2021 • Two techniques exist to customize the AI model to incorporate your data: o Fine Tuning: This traditional machine-learning technique involves tailoring the model and changing its internal weighting. However, it is Expensive and Hard to do. Additionally, some models might not offer this option. o Prompt Stuffing: A more practical alternative involves embedding your data within the prompt provided to the model. Given a model’s token limits, techniques are required to present relevant data within the model’s context window. This approach is commonly referred to as “stuffing the prompt.” • Also Learn: Guide to Spring Reactive Programming using Spring WebFlux
  • 4. • Generate Spring AI Project Using CLI • Download the Zip of Spring cli according to your system • Extract it • Open the Terminal and add the below command to use the spring command • alias spring=’java -jar $HOME/path to your jar file /spring-cli-0.8.1.jar’ NOTE: path to your jar file replace this with your jar file path • To generate a Spring boot project use the command: spring boot new ai • Go Inside the project and hit the below command to generate spring ai Apis spring boot add ai • Generate Spring AI Project Using Spring Initializer • Definition: In the input user will provide the state and Spring AI will give the List of the cities from the provided state • Generate Spring boot project with below dependency and Repository inside pom.xml • For the Spring AI, org.springframework.ai dependency and repository are required
  • 5. Create Models of City City CityList
  • 6. Create CityService with the below code Here, ChatClient is an interface used to interact with AI models The design of the ChatClient interface centers around two primary goals: Portability: The system facilitates seamless integration with various AI Models, enabling developers to transition b BeanOutputParser between different models with minimal adjustments to the codebase. This approach is in harmony with Spring’s ethos of modularity and flexibility. Simplicity: Leveraging companion classes such as Prompt for input encapsulation and ChatResponse for output handling, the ChatClient interface streamlines interactions with AI Models. It abstracts away the intricacies of request formulation and response interpretation, providing a straightforward and simplified API interaction experience. Here, BeanOutputParser is used to get the output in a specific format by default it will return in normal text format
  • 7. PrompTemplate provides a standardized format that we can follow to interact with language models effectively The prompt is used to generate the specific output based on the provided string ChatClient.call(prompt) will generate the response based on a given prompt Create CityController with the below code. Call methods of service from this controller. getAnswer API is the basic example for passing a question in a URL and getting the answers. Now, we have two endpoints. 1. http://localhost:8080/spring/ai/cities/{state} o In the above endpoint, we must provide the state in the input, and it will give the list of cities according to the state. o As displayed below, we got the response in proper format as we have provided parser.getFormat()
  • 8. 2. http://localhost:8080/spring/ai/question/Top singer details of India 1. In the above endpoint, we can provide any text input and it will generate the response accordingly. 2. As displayed below, we got the response in simple text format. Originally published by: Unlocking the Potential of AI in Spring