SlideShare a Scribd company logo
1 of 21
MICROSOFT OPENAI SDK
DEMYSTIFYING THE OPENAI SDK
Ken Ross
Senior Consultant
Microsoft ISD
ken@hotkrossbits.com
https://github.com/VeryKross
https://www.linkedin.com/in/techgeek/
https://twitter.com/hotkrossbits
https://www.youtube.com/@imkenross
TOPICS COVERED
 OpenAI SDK Setup
 The price of AI (Tokens)
 Basics of OpenAI Chat
 Training GPT for Better Outcomes
 OpenAI Functions
OPENAI SDK SETUP
PROJECT SETUP AND DEPENDENCIES
OPENAI SDK SETUP
1. Account Information
1. OpenAI API Key or
1. https://platform.openai.com/
2. Azure OpenAI Key and URL for
your
OpenAI Instance
2. Add the OpenAI SDK to your
Project/Solution
OPENAI SDK SETUP
1. Account Information
1. OpenAI API Key or
1. https://platform.openai.com/
2. Azure OpenAI Key and URL for your
OpenAI Instance
2. Add the OpenAI SDK to your
Project/Solution
OPENAI SDK SETUP
1. Account Information
1. OpenAI API Key or
1. https://platform.openai.com/
2. Azure OpenAI Key and URL for your
OpenAI Instance
2. Add the OpenAI SDK to your
Project/Solution
THE PRICE OF AI (TOKENS)
THE COSTS ASSOCIATED WITH USING OPENAI
THE PRICE OF AI (TOKENS)
 There are multiple models, each with different capabilities and price points. Prices are per 1,000 tokens.
You can think of tokens as pieces of words, where 1,000 tokens is about 750 words. This paragraph is 35
tokens.
 Tokens
 GPT-3.5 Turbo
 4K context: $0.0015/1K input, $0.002/1K output
 16K context: $0.003/1K input, $0.004/1K output
 GPT-4
 8K context: $0.03/1K input, $0.06/1K output
 32K context: $0.06/1K input, $0.12/1K output
 https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/
 https://openai.com/pricing
BASICS OF OPENAI CHAT
GET THIS CONVERSATION STARTED
BASICS OF OPENAI CHAT
1. Create the OpenAI Client Instance w/ Key
1. If using an Azure OpenAI instance, the URL will also be needed
2. Define Completion Options (temperature etc.)
3. Add your prompt to the Messages collection
4. Call the SDK to get the Chat Completion
5. Retrieve the message value
COMPLETION OPTIONS
 Temperature
 Determines the degree of randomness in the AI's response. A higher temperature corresponds to a higher degree of
randomness. This closely resembles ChatGPT "Conversation Style" where "More Creative" is a low Temperature and "More
Precise" is a high Temperature.
 Max Tokens
 Limits the length of the AI's response.
 Nucleus Sampling Factor
 Determines the diversity of the AI's response based on sampling previous tokens. (e.g. 0.1 = 10%)
 Note: Don’t set this property if also setting Temperature – results could be unpredictable.
 Frequency Penalty
 Penalizes the probability of frequently occurring words in the AI's response.
 Presence Penalty
 Penalizes the probability of generating statements that have already been generated in the response so far.
DEMO
TRAINING GPT FOR BETTER OUTCOMES
CHAT ROLES AND 1-SHOT, 2-SHOT TRAINING
TRAINING GPT FOR BETTER OUTCOMES
 Chat Roles
 System – gives context and instructions
 User – the human prompt
 Assistant – the reply from the AI
 One Shot & Multi-shot Training
 Simulated conversation
System: You are a Financial Analyst experienced in
corporate tax systems. You will always provide a tax
impact analysis to any question. You will never use the
word “fungible”.
User: What is the best way to invest $100,000?
Assistant: The best way to invest
$100,000 is to buy a house and rent it
out. The tax impact analysis is that you
will be able to deduct the interest on
the mortgage and the depreciation on
the house, saving you $10,000 in taxes.
DEMO
OPENAI FUNCTIONS
A STRUCTURED INTERFACE TO LOCAL DATA
OPENAI FUNCTIONS
 Functions provide a way to generate consistent, structured JSON responses
 An OpenAI Function represents the “signature” of a specific Function for a particular type of information
 More than one Function can be defined, allowing OpenAI to choose the which function to use based on
the user’s prompt content
 OpenAI itself does not call your Function; it will fill out your signature [JSON] so
that you can call the Function with those AI-identified parameters
 In some cases, maybe all you want is the JSON so it can be used for other purposes
 After calling the Function, the return value(s) can be re-inserted into the conversation,
allowing OpenAI to answer the user’s original prompt and incorporate the data from
the Function call
DEMO
THANK YOU
RESOURCES
 Demo code on GitHub:
 https://github.com/VeryKross/OpenAiExample

More Related Content

Similar to OpenAI-SDK101.pptx

[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx
[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx
[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx
AhmedElbaloug
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principles
Edorian
 

Similar to OpenAI-SDK101.pptx (20)

Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
How do OpenAI GPT Models Work - Misconceptions and Tips for Developers
How do OpenAI GPT Models Work - Misconceptions and Tips for DevelopersHow do OpenAI GPT Models Work - Misconceptions and Tips for Developers
How do OpenAI GPT Models Work - Misconceptions and Tips for Developers
 
Going open source with small teams
Going open source with small teamsGoing open source with small teams
Going open source with small teams
 
[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx
[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx
[GEMINI EXTERNAL DECK] Introduction to Gemini.pptx
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration tests
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
 
Save time by applying clean code principles
Save time by applying clean code principlesSave time by applying clean code principles
Save time by applying clean code principles
 
Generative AI in CSharp with Semantic Kernel.pptx
Generative AI in CSharp with Semantic Kernel.pptxGenerative AI in CSharp with Semantic Kernel.pptx
Generative AI in CSharp with Semantic Kernel.pptx
 
How to Build a Dialogflow App by using Actions on Google.
How to Build a Dialogflow App by using Actions on Google.How to Build a Dialogflow App by using Actions on Google.
How to Build a Dialogflow App by using Actions on Google.
 
AIR & API
AIR & APIAIR & API
AIR & API
 
Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
 
Swift meetup22june2015
Swift meetup22june2015Swift meetup22june2015
Swift meetup22june2015
 
Tulsa Techfest 2008 - Creating A Voice User Interface With Speech Server
Tulsa Techfest 2008 - Creating A Voice User Interface With Speech ServerTulsa Techfest 2008 - Creating A Voice User Interface With Speech Server
Tulsa Techfest 2008 - Creating A Voice User Interface With Speech Server
 
Alexa vs Google Assistant - Comparison
Alexa vs Google Assistant - ComparisonAlexa vs Google Assistant - Comparison
Alexa vs Google Assistant - Comparison
 
Slack and ChatGPT Integration using MuleSoft | MuleSoft Mysore Meetup #30
Slack and ChatGPT Integration using MuleSoft | MuleSoft Mysore Meetup #30Slack and ChatGPT Integration using MuleSoft | MuleSoft Mysore Meetup #30
Slack and ChatGPT Integration using MuleSoft | MuleSoft Mysore Meetup #30
 
ChatGPT and Slack Integration with MuleSoft
ChatGPT and Slack Integration with MuleSoftChatGPT and Slack Integration with MuleSoft
ChatGPT and Slack Integration with MuleSoft
 
Sumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - FundamentalsSumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - Fundamentals
 
How to Build a Backend for an Alexa Smart Home Skill - ALX316 - re:Invent 2017
How to Build a Backend for an Alexa Smart Home Skill - ALX316 - re:Invent 2017How to Build a Backend for an Alexa Smart Home Skill - ALX316 - re:Invent 2017
How to Build a Backend for an Alexa Smart Home Skill - ALX316 - re:Invent 2017
 
Google Home and Google Assistant Workshop: Build your own serverless Action o...
Google Home and Google Assistant Workshop: Build your own serverless Action o...Google Home and Google Assistant Workshop: Build your own serverless Action o...
Google Home and Google Assistant Workshop: Build your own serverless Action o...
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 

OpenAI-SDK101.pptx

  • 2. Ken Ross Senior Consultant Microsoft ISD ken@hotkrossbits.com https://github.com/VeryKross https://www.linkedin.com/in/techgeek/ https://twitter.com/hotkrossbits https://www.youtube.com/@imkenross
  • 3. TOPICS COVERED  OpenAI SDK Setup  The price of AI (Tokens)  Basics of OpenAI Chat  Training GPT for Better Outcomes  OpenAI Functions
  • 4. OPENAI SDK SETUP PROJECT SETUP AND DEPENDENCIES
  • 5. OPENAI SDK SETUP 1. Account Information 1. OpenAI API Key or 1. https://platform.openai.com/ 2. Azure OpenAI Key and URL for your OpenAI Instance 2. Add the OpenAI SDK to your Project/Solution
  • 6. OPENAI SDK SETUP 1. Account Information 1. OpenAI API Key or 1. https://platform.openai.com/ 2. Azure OpenAI Key and URL for your OpenAI Instance 2. Add the OpenAI SDK to your Project/Solution
  • 7. OPENAI SDK SETUP 1. Account Information 1. OpenAI API Key or 1. https://platform.openai.com/ 2. Azure OpenAI Key and URL for your OpenAI Instance 2. Add the OpenAI SDK to your Project/Solution
  • 8. THE PRICE OF AI (TOKENS) THE COSTS ASSOCIATED WITH USING OPENAI
  • 9. THE PRICE OF AI (TOKENS)  There are multiple models, each with different capabilities and price points. Prices are per 1,000 tokens. You can think of tokens as pieces of words, where 1,000 tokens is about 750 words. This paragraph is 35 tokens.  Tokens  GPT-3.5 Turbo  4K context: $0.0015/1K input, $0.002/1K output  16K context: $0.003/1K input, $0.004/1K output  GPT-4  8K context: $0.03/1K input, $0.06/1K output  32K context: $0.06/1K input, $0.12/1K output  https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/  https://openai.com/pricing
  • 10. BASICS OF OPENAI CHAT GET THIS CONVERSATION STARTED
  • 11. BASICS OF OPENAI CHAT 1. Create the OpenAI Client Instance w/ Key 1. If using an Azure OpenAI instance, the URL will also be needed 2. Define Completion Options (temperature etc.) 3. Add your prompt to the Messages collection 4. Call the SDK to get the Chat Completion 5. Retrieve the message value
  • 12. COMPLETION OPTIONS  Temperature  Determines the degree of randomness in the AI's response. A higher temperature corresponds to a higher degree of randomness. This closely resembles ChatGPT "Conversation Style" where "More Creative" is a low Temperature and "More Precise" is a high Temperature.  Max Tokens  Limits the length of the AI's response.  Nucleus Sampling Factor  Determines the diversity of the AI's response based on sampling previous tokens. (e.g. 0.1 = 10%)  Note: Don’t set this property if also setting Temperature – results could be unpredictable.  Frequency Penalty  Penalizes the probability of frequently occurring words in the AI's response.  Presence Penalty  Penalizes the probability of generating statements that have already been generated in the response so far.
  • 13. DEMO
  • 14. TRAINING GPT FOR BETTER OUTCOMES CHAT ROLES AND 1-SHOT, 2-SHOT TRAINING
  • 15. TRAINING GPT FOR BETTER OUTCOMES  Chat Roles  System – gives context and instructions  User – the human prompt  Assistant – the reply from the AI  One Shot & Multi-shot Training  Simulated conversation System: You are a Financial Analyst experienced in corporate tax systems. You will always provide a tax impact analysis to any question. You will never use the word “fungible”. User: What is the best way to invest $100,000? Assistant: The best way to invest $100,000 is to buy a house and rent it out. The tax impact analysis is that you will be able to deduct the interest on the mortgage and the depreciation on the house, saving you $10,000 in taxes.
  • 16. DEMO
  • 17. OPENAI FUNCTIONS A STRUCTURED INTERFACE TO LOCAL DATA
  • 18. OPENAI FUNCTIONS  Functions provide a way to generate consistent, structured JSON responses  An OpenAI Function represents the “signature” of a specific Function for a particular type of information  More than one Function can be defined, allowing OpenAI to choose the which function to use based on the user’s prompt content  OpenAI itself does not call your Function; it will fill out your signature [JSON] so that you can call the Function with those AI-identified parameters  In some cases, maybe all you want is the JSON so it can be used for other purposes  After calling the Function, the return value(s) can be re-inserted into the conversation, allowing OpenAI to answer the user’s original prompt and incorporate the data from the Function call
  • 19. DEMO
  • 21. RESOURCES  Demo code on GitHub:  https://github.com/VeryKross/OpenAiExample