SlideShare a Scribd company logo
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

Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
gturnquist
 
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
Ivo Andreev
 
Going open source with small teams
Going open source with small teamsGoing open source with small teams
Going open source with small teams
Jamie Thomas
 
[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
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
michael.labriola
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration tests
Kenneth Poon
 
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
Brian Lyttle
 
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 principlesEdorian
 
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
Alon Fliess
 
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.
Yuting Liu
 
AIR & API
AIR & APIAIR & API
AIR & API
Arie Prasetyo
 
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
Adam Englander
 
Swift meetup22june2015
Swift meetup22june2015Swift meetup22june2015
Swift meetup22june2015
Claire Townend Gee
 
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
Jason Townsend, MBA
 
Alexa vs Google Assistant - Comparison
Alexa vs Google Assistant - ComparisonAlexa vs Google Assistant - Comparison
Alexa vs Google Assistant - Comparison
Tarun Chawdhury
 
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
MysoreMuleSoftMeetup
 
ChatGPT and Slack Integration with MuleSoft
ChatGPT and Slack Integration with MuleSoftChatGPT and Slack Integration with MuleSoft
ChatGPT and Slack Integration with MuleSoft
shyamraj55
 
Sumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - FundamentalsSumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - Fundamentals
Sumo Logic
 
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
Amazon Web Services
 
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...
Bret McGowen - NYC Google Developer Advocate
 

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

Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 

Recently uploaded (20)

Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 

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