Generative AI APIs For Practical Applications
Generative AI APIs For Practical Applications
Introduction
Generative artificial intelligence (AI) has taken the tech and business world by storm.
It currently can create stories, text, images, summaries, essays, and much more,
with sometimes nothing more than a few words to describe what you want.
Unfortunately, it can also be used in ways that can be harmful, such as creating
deepfakes and false information. In this course, you will discover the differences
between generative AI and general AI and look at the history and future of
generative AI. You will explore applications of generative AI and the ethical, safety,
security, and privacy concerns associated with its use. Then you will identify
common generative AI application programming interfaces (APIs) and best practices
when using generative AI. Next, you will find out how to create images and text with
generative AI, and you will focus on the challenges of AI integration into processes
and workflows. Finally, you will learn how to integrate generative AI APIs to create
tools like chatbots.
Table of Contents
[Video description begins] Topic title: Course Overview. Your host for this session is
Sven Batalla. [Video description ends]
Hi, I’m Sven Batalla. Generative AIs have taken the tech and business world by
storm.
They currently can create stories, text, images, summaries, essays, and much more,
with sometimes nothing more than a few words to describe what you want.
Unfortunately, they can also be used in ways that can be harmful, such as creating
deepfakes and false information.
In this course, I’ll explore the available generative AIs, learn how to use them
effectively, understand the ethics considerations, and how they can be used to help
productivity in a variety of situations.
After completing this video, you will be able to define and identify generative AI and
distinguish it from general AI.
[Video description begins] Topic title: What Is Generative Artificial Intelligence (AI)?
Your host for this session is Sven Batalla. [Video description ends]
Generative Artificial Intelligence or AI, has opened up new possibilities for human
computer interactions.
Generative AI models are able to generate creative content and engage with users
dynamically. In fact, there are many generative AI models that have revolutionized
their respective domains with their unique capabilities. For example, there is Dall-E.
This groundbreaking AI interface, developed by OpenAI, focuses on generating
images from textual descriptions. It can imagine and create stunning visual content
based on textual prompts.
Blurring the lines between imagination and reality. From surreal landscapes to
whimsical creatures, Dall-E pushes the boundaries of what AI can visually create.
And no doubt by now you've heard of ChatGPT, a pioneer in conversational AI.
ChatGPT is a language model that engages in interactive and humanlike
conversations with users.
It can answer questions, provide recommendations, and even tell jokes. All while
maintaining context and coherence. ChatGPT's ability to generate human like
responses has made it a valuable tool for customer support, content generation, and
creative writing. And then there's Bard. This generative AI interface is dedicated to
the world of music. Bard can compose original pieces, taking inspiration from
different genres and styles.
From classical symphonies to modern pop tunes, Bard demonstrates the potential of
AI in enhancing the creative process of music composition. Now to understand the
power and capabilities of generative AI, interfaces like Dall-E, ChatGPT, and Bard,
let's distinguish them from predictive AI systems. Now, while both types of AI involve
complex algorithms and neural networks, they serve distinct purposes and exhibit
different behaviors.
Generative AI, as exemplified by Dall-E and Bard, is designed to create new and
original content based on patterns learned from existing data. It can generate fresh
images, music, and text, which sparks creativity and offers novel solutions. On the
other hand, predictive AI, also known as discriminative AI aims to classify or predict
outcomes based on given inputs.
It excels in tasks like image recognition and sentiment analysis. Generative AI is not
limited to inferring future events, but instead generates entirely new content based
on the information it's learned. In contrast, predictive AI is explicitly designed to
make predictions or classifications of future events or patterns based on historical
data. The underlying algorithms for generative AI and predictive AI are distinct.
They can assist in content creation, writing, assistance, and even language
translation, making them valuable tools for writers, educators, and language
enthusiasts. Next, AI interfaces like Dall-E are changing the landscape of visual
content creation, from generating art pieces to designing realistic images.
Generative AI has found applications in graphic design, architecture, and even the
creative arts. There’s also musical use cases. With interfaces like Bard, AI now
composes music that resonates with human emotions. Generative AI in the music
domain has potential applications in film scoring, personalized playlists, and even
helping musicians to explore new ideas. And, of course, we’ve all heard of chatbots.
Generative AI interfaces can mimic specific styles, which enables artists, writers, and
musicians to experiment with different creative directions. Now, all generative AI
interfaces offer lots of impressive capabilities. It’s not all sunshine and rainbows.
They do have some limitations that developers and users need to be aware of.
First, the quality of generated content heavily relies on the quality and diversity of
the source data used for training the AI models. AI interfaces may also inadvertently
perpetuate existing biases present in training data. It's essential to monitor and
address bias during the training and fine tuning processes to ensure fairness and
inclusivity in generated content. And then there's the issue of incorrect information.
AI models may generate content that appears plausible but is factually incorrect.
Ensuring the accuracy of information is really important, particularly in critical
domains like health care, legal advice, or financial planning. And one more limitation
is that generative AI interfaces may struggle to adapt to entirely new and unforeseen
scenarios.
And finally, despite the remarkable progress in generative AI, there are some
concerns and challenges that must be addressed to ensure responsible and ethical
use of AI interfaces. For example, the quality and reliability of generated content
may vary, which leads to both impressive and unexpected outputs. There is also
potential misuse.
And lastly, you need to watch for the inevitable business model disruption. The rise
of generative AI may lead to disruptions in certain industries where AI generated
content competes with traditional human created content.
[Video description begins] Topic title: History and Future of Generative AI. Your host
for this session is Sven Batalla. [Video description ends]
In fact, there have been many key advancements and breakthroughs that have
shaped the development of generative AI. For example, consider Natural Language
Processing or NLP. NLP is a foundational concept in generative AI. NLP focuses on
enabling computers to understand, interpret, and generate human language.
In fact, it's paved the way for the development of more advanced language models.
There is also Generative Adversarial Networks or GANs. GANs represent a significant
milestone in the world of generative AI. GANs consist of two neural networks: the
generator and the discriminator. Both are engaged in a captivating, adversarial
dance that drives the model to generate increasingly realistic data.
The generator's goal is to create outputs that are indistinguishable from real data. So
you provided a prompt, and it generates what it is that you want it to. Meanwhile,
the discriminator serves as the adversary in the GANs setup. Its task is to
differentiate between real data and the synthetic data generated by the generator.
The discriminator's objective is to improve its ability to correctly identify real versus
fake samples. Now, by now, it’s likely that you’ve heard of ChatGPT. But what is
GPT? Well, GPT stands for Generative Pre-trained Transformer. GPT is a
groundbreaking class of models that has pushed the boundaries of language
generation.
The encoder in GPTs is really important for processing input data like sentences or
paragraphs. It transforms the input into a dense, contextualized representation,
capturing the essential information to generate meaningful and coherent responses.
Working in tandem with the encoder, the decoder is responsible for language
generation. It takes the contextualized representation and decodes it to produce
humanlike, coherent, and contextually relevant text.
Next, it’s worth taking a look at some of the impressive generative AI models that
have attracted widespread recognition. For example, Dall-E, which was developed by
OpenAI, is a groundbreaking model capable of generating stunning and highly
creative images from textual descriptions or prompts. It demonstrates the incredible
potential of generative AI in the field of visual arts and design. And, of course, there's
ChatGPT. ChatGPT is another remarkable creation from OpenAI.
It's a powerful language model designed for interactive conversations. It can engage
in meaningful dialogs, answer questions, and offer contextually relevant responses.
Meanwhile, BLIP-2, an emerging generative AI model, showcases the continuous
evolution of this technology. though relatively new BLIP-2 demonstrates promise in
various creative applications. And one more model is GPT-4.
Now, as we look towards the future, GPT-4, which is the latest iteration of GPT,
promises even more impressive capabilities in understanding and generating human
language or even code. And finally, with generative AI continually advancing, there
are lots of interesting trends that are shaping the future of this transformative
technology.
Generative AI is set to revolutionize the music and the audio industry. We're already
experiencing it now, but we can expect to see even more AI generated compositions,
voice synthesis, and realistic soundscapes that expand the boundaries of creativity.
Also, from graphic design to architectural blueprints, generative AI will drive
automated design processes and offer novel, aesthetically pleasing, and functional
creations.
Even the world of gaming will witness a significant transformation with generative AI.
AI generated content, dynamic storylines, and adaptive gameplay mechanics will
provide players with immersive and personalized gaming experiences.
Next, obviously, text generation models will continue to advance, and that’s going to
enable Chatbots, virtual assistants, and content generation systems to deliver highly
tailored and contextually relevant responses. Visual generation capabilities will also
expand and flourish. This will lead to more AI generated art, illustrations, and even
realistic video synthesis that can blur the line between virtual and real worlds.
And lastly, the concept of a Metaverse, a shared virtual space where users interact
and experience various digital environments, will be greatly improved by generative
AI. AI-driven content generation will shape the evolution of the metaverse, creating
captivating and interactive experiences.
[Video description begins] Topic title: Applications of Generative AI. Your host for this
session is Sven Batalla. [Video description ends]
One of the most prominent ways that generative AI helps with the healthcare
industry is through early disease detection. Now, advanced algorithms can analyze
vast amounts of patient data like medical records and imaging results to identify
potential health risks and patterns that may not be apparent to human clinicians.
This early detection capability enables timely intervention and treatment, ultimately
saving lives. Plus, generative AI is enhancing medical training by providing realistic
simulations and virtual training environments.
Medical professionals can practice complex procedures, surgeries, and diagnoses in
a risk free controlled setting, thus improving their skills and confidence. And on top
of that, generative AI is influencing medical product development and design, from
creating customized prosthetics to optimizing medical devices, AI-driven design
processes expedite innovation and improve patient outcomes.
Now, as I said earlier, generative AI even impacts the education sector. In fact, one
of the most exciting applications of generative AI in education anyways is its
personalized learning experiences. AI powered educational platforms can adapt their
content and teaching methods to suit each particular student’s learning style, pace,
and preferences. This tailored approach enhances engagement and promotes better
knowledge retention.
Next, let's look at how generative AI is reshaping business and finance practices.
Generative AI is optimizing operations management across various industries. AI-
driven systems analyze large data sets, identify inefficiencies, and provide insights
that help businesses to streamline their processes and, reduce cost, and improve
overall performance. In the world of marketing and advertising, generative AI
empowers businesses to create targeted ads and social media campaigns.
AI generated content like images, and videos, and music can be produced at a much
larger scale, beating the demand for diverse and engaging content. And lastly,
generative AI is redefining art and media creation.
AI powered tools can assist artists and designers in generating unique and
innovative artwork which pushes the boundaries of creativity.
Upon completion of this video, you will be able to navigate the ethical concerns and
implications that generative AI can create, such as bias and misuse.
navigate the ethical concerns and implications that generative AI can create,
such as bias and misuse
[Video description begins] Topic title: Ethical Concerns of Generative AI. Your host
for this session is Sven Batalla. [Video description ends]
As organizations embark into the world of generative AI, it's critical to address the
ethical implications of this transformative technology. For example, one of the most
significant ethical concerns with generative AI is the potential for misinformation. AI
generated content can spread false or misleading information, which impacts
individuals, communities, and even society at large.
In fact, one of the most obvious concerns is fake news. Fake news is a pressing issue
that comes up with generative AI technology. AI generated content can mimic
authentic news sources, leading to the dissemination of misinformation and the
erosion of trust in reliable journalism.
Generative AI can also challenge copyright laws and ownership rights. Determining
the ownership of AI generated content raises complex legal questions that require
careful consideration. AI model bias is another critical ethical concern. If AI models
are trained on biased data, they can perpetuate and even amplify existing societal
biases, leading to unfair and discriminatory outcomes.
Now, to address these ethical concerns, we need to establish clear principles for
generated AI development and deployment. First and foremost, generative AI must
adhere to ethical principles that prioritize the well-being and rights of individuals and
society as a whole.
AI systems should also be designed and trained to be fair and unbiased, promoting
diversity and inclusivity in their responses and decisions. And, of course, there's
privacy and governance. Respecting privacy is crucial in generative AI. User data
should be handled securely and with proper consent, ensuring compliance with data
protection regulations wherever you are in the world.
Next, technical robustness and safety are also super important to help make sure
that AI systems operate effectively and without unintended consequences or
malfunctions. Generative AI should also consider the broader impact on society and
the environment, promoting positive outcomes and sustainability.
And lastly, as we said before, human oversight and control are indispensable. AI
systems should be designed to serve human interests and not infringe on human
decision-making.
Ultimately, with a robust ethics framework and adherence to ethical principles and
requirements, we can harness the power of generative AI responsibly and ethically,
ensuring that it positively impacts our world.
After completing this video, you will be able to specify the safety, security, and
privacy issues that can be caused by generative AI.
specify the safety, security, and privacy issues that can be caused by
generative AI
[Video description begins] Topic title: Safety, Security, and Privacy Concerns of
Generative AI. Your host for this session is Sven Batalla. [Video description ends]
When it comes to generative AI, it's critically important to understand and consider
data privacy.
There are quite a few concerns that go along with data privacy that you should be
aware of and include in your generative AI journey. For example, one of the primary
concerns in generative AI is a regulatory compliance. With data privacy regulations
like GDPR and CCPA, organizations must ensure that their AI systems handle data in
compliance with these stringent laws or face massive consequences.
Data leakage is also a significant risk associated with generative AI. AI models may
inadvertently reveal sensitive information through generated outputs, potentially
compromising individual's privacy. And on top of that, generative AI's ability to
produce realistic data and visuals can result in the accidental creation of fake data,
which itself poses a unique challenge. The proliferation of fake data could lead to
misinformation or fraud, which raises critical ethical and, privacy, and legal issues.
Data storage and the lifespan of AI generated data also needs careful consideration.
Organizations need to establish protocols for securely storing and managing data to
prevent unauthorized access. Also, the training data used to develop generative AI
models can be vulnerable to security breaches. Unauthorized access to training data
may lead to the creation of harmful AI generated content, as well as potentially
revealing some sensitive information. For businesses, protecting proprietary data is
also really important.
Generative AI systems that rely on proprietary data must have robust security
measures to prevent data exposure to competitors or to malicious actors. So, now
that we understand our data privacy concerns, let's shift our focus to security
concerns related to generative AI.
One example is identity theft. Identity theft and data breaches are persistent threats
in the digital age. Generative AI can inadvertently contribute to these risks if not
adequately protected and secured. Generative AI applications can also be
susceptible to security vulnerabilities. Organizations need to conduct rigorous
security testing and implement robust security measures to safeguard AI systems.
Protecting confidential corporate data is obviously one of the most important things
any organization will want to do. Generative AI systems need strong security controls
to prevent data leaks that may harm businesses or even their stakeholders. And one
more security concern is malicious deepfakes. Malicious deepfakes pose a significant
security concern.
AI generated content like deepfake videos or audio can be exploited for fraudulent
activities or disinformation campaigns. Imagine a video that appears to be coming
from a political figure that's saying some really horrific things. This could actually
impact campaigns or the outcomes of elections. And finally, the obvious question
when we talk about these privacy and security concerns is what sort of proactive
measures can we take and what sort of robust safeguards can be put in place.
One thing you can do is minimize data collection. In fact, minimizing data collection
is a fundamental privacy protection strategy. Why? Well, because collecting only
necessary data helps to reduce the risk of data exposure and potential misuse.
Aggregating and anonymizing data can also enhance privacy protection. Basically,
by anonymizing personal information. Organizations can utilize data without
compromising individual identities. In fact, I've done this many times myself. It's one
thing to say that Bob has diabetes, which is a horrible thing to put out there on the
Internet, but it's a whole other thing to say that 30% of people over the age of X
have diabetes, where no personal information is exposed anywhere.
Also, implementing clear and comprehensive data policies ensures that all
stakeholders understand how data is handled, processed, and protected. Having
granular data control is another strategy that allows organizations to manage access
to data on a need-to-know basis, which reduces the risk of unauthorized data access.
Another strategy for data privacy and security is data encryption. Data encryption is
an essential security measure because it safeguards data at rest and in transit and
that prevents unauthorized access to sensitive information. Regular auditing and
monitoring of AI systems is another way to help detect and address potential privacy
and security breaches proactively.
And one more strategy is implementing robust access controls. Access controls help
to make sure that only authorized personnel can actually access your sensitive data,
which reduces the risk of data breaches. At the end of the day, by adopting these
data privacy protection measures, organizations can responsibly leverage the power
of generative AI while safeguarding individual privacy and data security.
In this video, we will identify and describe multiple common generative AI APIs and
their features.
identify and describe multiple common generative AI APIs and their features
In the world of AI, language models have revolutionized the field of Natural Language
Processing or NLP. Tools like OpenAI’s ChatGPT-3 and its latest iteration, ChatGPT-4,
have attracted significant attention because of their impressive capabilities.
So, let's dive into what makes them stand out. First is processing power. ChatGPT-3
and 4 boast immense processing power thanks to its massive scale and impressive
computational infrastructure. Now, this enables it to handle complex language tasks
with remarkable speed and efficiency. Next is accuracy.
These language models have undergone rigorous training on vast amounts of data,
enabling them to provide accurate and contextually relevant responses to a wide
range of inputs. And one more way ChatGPT stands out is its creativity and
coherency. One of the most remarkable features of ChatGPT-3 and 4 is its ability to
exhibit creativity in its responses. It can generate humanlike text, engage in
interactive conversations, and maintain coherency throughout the dialog.
But ChatGPT is not the only language model out there. There is also Google Bard.
Bard also deserves some attention for its impressive capabilities. Bard is built on the
PaLM 2 architecture, which stands for Pattern Exploiting Training Language Model
Two. This model leverages patterns in data to improve performance and efficiency.
Google Bard is also designed to be accessible in a wide range of users, making it
available for both developers and the general public.
Another cool feature of Bard is its multi-language support. Bard has been trained on
a diverse range of languages, allowing it to handle multilingual inputs and provide
responses in multiple languages. Beyond text generation, Bard can also generate
images based on textual descriptions, showcasing its versatility in both language
and visual domains.
But let's keep exploring the different NLP models out there. So after ChatGPT and
Bard, there's Bing Chat. Bing Chat is Microsoft's offering to the world of language
models. Bing Chat provides developers with access to its capabilities, allowing them
to integrate it into their applications and their services. Currently, in an open preview
stage, Bing Chat offers developers an opportunity to explore its potential and
provide valuable feedback.
And that can be valuable to developers because it can help shape the direction and
the future of the Microsoft NLP. Bing Chat has an interesting capability in that it can
provide visual answers to users, and that makes it useful for applications that require
a combination of textual and visual responses. And on top of all that, with Bing chat,
users can engage in interactive conversations over multiple sessions, enhancing the
user experience.
However, as with any image generation model, it's super important to be mindful of
copyright considerations. Good news is that Midjourney strictly abides by a robust
DMCA takedown policy to ensure responsible use. And finally, let’s explore Dall-E.
Dall-E is a groundbreaking model known for its text-to-image creation capabilities.
These models really showcase the tremendous potential of language and image
generation. Plus, they have practical applications in lots of domains. From language-
based conversational interfaces to sophisticated image manipulation and generation.
Upon completion of this video, you will be able to apply best practices when using
generative AI.
[Video description begins] Topic title: Best Practices for Using Generative AI. Your
host for this session is Sven Batalla. [Video description ends]
In this topic, we're going to explore some key considerations that pave the way for a
positive and impactful AI experience. At the forefront of generative AI usage lies the
crucial aspect of respecting copyright laws and intellectual property rights.
Organizations must ensure that they possess the necessary rights to use the data
and prompts provided to the AI models. Obtaining appropriate permissions and
licenses for copyrighted materials is imperative to avoid legal complications. Each
generative AI platform comes with its own set of terms and conditions that users
must abide by.
These terms may encompass data usage, content restrictions, and ethical guidelines.
It's essential for organizations to thoroughly review and understand these terms to
align their usage with the platform's requirements. Authenticity is of paramount
importance when interacting with generative AI models. To maintain originality and
stay clear of potential legal issues,
it’s really important to use unique and original prompts that do not infringe upon
others’ intellectual property rights. Generative AI models have the capability to
generate content which may, at times, be harmful or inappropriate. So ensuring
safety in AI generated outputs is super important to prevent the dissemination of
offensive or misleading content.
Implementing robust safety measures and filters can safeguard against harmful
outputs. Safeguarding ethical and responsible AI practices requires careful attention
and consideration. For example, to unlock the full creative potential of generative AI,
providing diverse and unique prompts is really important, so avoid repetitive or
biased prompts as they may limit the model's ability to produce varied and
imaginative outputs.
It's also important to keep records of your work and data. Maintaining
comprehensive records of the data and prompts used in AI interactions is
instrumental in ensuring transparency and accountability. These records serve as
valuable references for future assessments and regulatory requirements, and it can't
be overstated that you should definitely contact legal representation in situations
where there may be uncertainty about the legality of specific prompts or AI
generated content.
Seeking advice from legal experts can help ensure compliance with copyright and
intellectual property laws. The foundation of a proficient, generative AI model lies in
the data that was used for its training. Careful validation of your training dataset is
important for optimal performance, and that includes dataset cleanliness.
Inaccurate or misleading data can adversely impact the model’s ability to generate
coherent and contextually relevant outputs. And fine tuning the model on domain-
specific data can also significantly enhance its performance and adaptability to
specialized tasks.
Tailoring the model to specific scenarios enables more accurate and relevant
outputs. Now, to maximize the potential of generative AI models. There are some
best practices that should be followed during the training process. For example, clear
and well-defined objectives guide the model to focus on generating outputs that
align with the intended purpose.
Precise objectives prevent the model from deviating into irrelevant or unintended
outputs. Ethical considerations must also be at the core of AI model training.
Ensuring that the data used for training and the model's outputs adhere to ethical
standards is critical to avoid the propagation of harmful or discriminatory content.
And on top of that, it's important to understand that AI models can continuously
learn and improve from user interactions and feedback. So, regularly updating and
fine tuning the model based on new data and feedback leads to enhanced
performance and accuracy. And finally, copyright implications are a critical aspect of
using generative AI models, as we said earlier.
So, there's a few key points to consider in regards to copyright. First, understanding
the ownership of generated content is really important. In many cases, the content
generated by AI models may belong to the user who provided the prompts. However,
platform terms and conditions must be examined to determine ownership rights.
Also, familiarizing yourself with the legal implications of using AI generated content
is critical too.
And lastly, for valuable and unique content generated by AI models, considering
appropriate intellectual property rights such as patents or copyrights can provide
protection against unauthorized usage or reproduction.
9. Video: Generating Images with Generative AI
(it_gaiapidj_01_enus_09)
In this video, find out how to work with generative AIs to generate images by
providing textual descriptions.
[Video description begins] Topic title: Generating Images with Generative AI. Your
host for this session is Sven Batalla. [Video description ends]
Specifically, we're going to use the OpenAI API. Now, before we get started, this
demo assumes that you have an account with OpenAI and that you have an API key
that you can use to perform the tasks that we're going to go over and that your
account with OpenAI has the necessary permissions to generate images.
This demo also assumes that you have .NET 7 installed and an IDE to create a .NET
console application. All right, now to get started, let’s head over to Visual Studio
Code or VS Code. [Video description begins] The instructor opens Visual Studio Code.
It is mainly divided into two parts: The left-hand side is the Explorer and the right-
hand side is the CLI. The Menu bar contains buttons such as File, Edit, Selection,
View, and so on. There are icons such as Run and Debug, Built-in Git, Extensions,
and so on at the extreme left-hand side of the window. [Video description ends]
Good. Now our first step will be to create a C# console application. So to do that,
let's start by opening up the terminal with a control tilde. And then running the
following command: dotnet new console -n sbdemo0109.
And of course you can name your project anything you’d like. Good. Now that we've
created the project, let’s navigate to the project folder using this command: cd
sbdemo0109. Perfect. Now, in order to interact with open AI, we're going to import
the OpenAI NuGet package. So to do that, let’s run this command: dotnet add
package OpenAI -v 1.7.2.
Perfect. So now we’re ready to write some code. So let's go ahead and open the
Program.cs file in the Explorer on the left-side of the screen. Good. Now, at the top of
the file, we're going to want to reference our OpenAI package. So let's add this using
directive at the top of the page. using OpenAI_API. Perfect.
Now the next thing we want to do is create a reference to the OpenAI API. So let's
add this line of code at the bottom of our file. var API = new OpenAIAPI ( And then in
quotes, we're going to put our key. [Video description begins] The code on line 6
reads var api = new OpenAIAPI("YourKey"); [Video description ends] Good. Now let's
take that value, that placeholder value and replace it with our actual OpenAI API key.
Perfect. [Video description begins] The key reads: ("sk-
43KjzibQIE9ZFEy6kIgAT3B1bkFJsUsAj6NjATI9AyiU7o7e"); [Video description ends]
So we now have a reference to the OpenAI API. The next step is to create a request
for OpenAI. So let’s do that by writing out this code; var request = new
OpenAI_API.Images.ImageGenerationRequest, and then we’ll open some squiggly
brackets and we’ll provide the property of Prompt which = and then in quotes “A
cute kitten in a basket”. And don’t forget the semicolon at the end. Good. [Video
description begins] The code on line 8 reads: var request = new OpenAI_API. Images.
ImageGenerationRequest The code on line 9 reads: { The code on line 10 reads :
Prompt = "A cute kitten in a basket" The code on line 11 reads }; [Video description
ends]
So now that we have a request, now we can query the OpenAI API for a result. So to
do that, let’s add this code below the request: var response = api .ImageGenerations
.CreateImageAsync and then in brackets we’ll pass in our request as a parameter.
And don't forget the semicolon at the end of the line. Perfect. [Video description
begins] The code on line 12 reads: var response = api.
ImageGenerations.CreateImageAsync(request); [Video description ends] And the last
step is now to add some code that helps us display the results on the command line.
So to do that, let’s add this code: Console .WriteLine and then open brackets and in
quotes (“image URL: and then in squiggly brackets {0} and then we’ll pass in
response .Data and in square brackets [0] for the 0 index .Url and don’t forget the
semicolon once again.
Now before we continue, let's quickly talk about what we're doing here. [Video
description begins] The code on line 13 reads: Console.WriteLine("Image URL: {0}",
response.Data[0].Url); [Video description ends] In this code, we're creating a
reference to the OpenAI API and telling it to use our specific account based on the
API key that we give it.
We give it a prompt and tell it to try to create an image based on our description. In
this case, a cute kitten in a basket. Then we display the result, which is just going to
be a URL pointing to the generated image. So let's go ahead and test our work. To do
that, let’s first save the file using a Ctrl+S and now let’s Run the code. So let's go
back to the terminal with a Ctrl ~.
And now, let’s run this command: dotnet run. Perfect. So we're now seeing the URL
of the output of our request. Fantastic. So let's see if it worked. Let's copy the URL.
Good. Now let's head over to our browser and let's navigate to that URL. Awesome.
There’s our kitten in a basket, just like we asked. This is amazing. [Video description
begins] The browser displays the image of the kitten in the basket. [Video
description ends] So there's our image. Fantastic. So there you have it.
[Video description begins] Topic title: Generating Text with Generative AI. Your host
for this session is Sven Batalla. [Video description ends]
Specifically, we're going to create a C# and .NET console application that uses
OpenAI to create some text based on our prompt. So let's get to it. Now, before we
begin, this demo assumes that you have an active OpenAI account and that you've
generated an API key. This demo also assumes that you have .NET 7 installed and
that you have an IDE that you can use. For this demo,
I’ll be using Visual Studio Code or VS Code. In fact, to get started, let’s start by
opening VS Code. Perfect. Now, the first thing we’re going to do is create a project.
[Video description begins] The instructor opens Visual Studio Code. It is mainly
divided into two parts: The left-hand side is the Explorer and the right-hand side is
the CLI. The Menu bar contains buttons such as File, Edit, Selection, View, and so on.
There are icons such as Run and Debug, Built-in Git, Extensions, and so on at the
extreme left-hand side of the window. [Video description ends] So let's open up the
terminal with a Ctrl~ and let's create a console project by running the following
command: dotnet new console -n sbdemo0110. And of course you can name your
project anything you'd like. Good.
Now let’s navigate to the project folder using this command: cd sbdemo0110.
Perfect. Now, in order to interact with OpenAI, we're going to import the OpenAI
NuGet package. So to do that, let’s run this command: dotnet add package OpenAI.
Awesome. So now we have a console application and we’ve imported the needed
NuGet package. Now we can start writing code.
Now the first thing we need to do is reference our OpenAI package and some other
directives in the Program.cs file. So let’s open up that file using the Explorer on the
left-hand side of the screen. [Video description begins] The instructor closes the
terminal window and opens Program.cs file from the Explorer. [Video description
ends] Good. Now let's import the needed namespace by writing this code at the top
of the file: using OpenAI_API. And then don’t forget the semicolon. Good.
Now we need to import our API key. [Video description begins] The code on line 1
reads: using OpenAI_API; [Video description ends] To do that, we’re going to write
the following code at the bottom of the file: var key = new APIAuthentication(“key”).
Now let's replace that key placeholder with our actual API key. Perfect. So now that
we have our key reference, [Video description begins] The code on line 6 reads: var
key = new APIAuthentication("sk-
43KjzibQIE9ZFEy6kIgAT3B1bkFJsUsAj6NjATI9AyiU7o7e"); [Video description ends]
now we can actually make a request to the completion of API. To do that, let’s write
out this code: var API = new OpenAIAPI and then we’ll pass in our key. And then var
prompt = and then let’s provide a prompt, Something like “A long time ago, in a
galaxy far, far away...”
On the next line, we're going to create our request. var request = new
OpenAI_API.Completions .CompletionRequest. And then we’ll pass in our prompt and
then we'll specify a few bits of information. For example, let's specify the model as
being the OpenAI_API.Models.Model.DavinciText.
Then we'll specify a max number of tokens. And we'll specify that value to be 100.
This basically just limits the response size so it doesn't go completely out of control.
And then temperature and we'll pass in a value of 0.7. Good. [Video description
begins] The code on line 8 reads: var api = new OpenAIAPI(key); The code on line 9
reads: var prompt = "A long time ago, in a galaxy far, far away..."; The code on line
10 reads: var request = new OpenAI_API.Completions.CompletionRequest(prompt,
model: OpenAI_API.Models.Model.DaVinciText, max_tokens: 100,temerature:
0.7); [Video description ends] Now, on the next line, let's create or let's collect the
response. To do that, we type, var response = await
api.Completions .CreateCompletionAsync and then we’ll pass in our request.
And once again, don't forget the semicolons. [Video description begins] The code on
line 11 reads: var response = awaut api.
Completions.CreateCompletionAsync(request); [Video description ends] All right, So
what we've done here is requested a text completion based on a prompt, and we all
know the beginning that we've provided. So what we're asking the generative AI to
do is to create the rest of the story. Now we're only using 100 tokens, so we won't
get back the full movie script, but we should get back a good logical bunch of text.
Anyway.
What we want to do next is actually see what the AI comes up with as a logical
completion to our prompt. So to do that we need to add a little bit more code. So
let’s add this, var completion = response.Completions and then square brackets 0.
So we're going to get the first completion, assuming I typed that right and then .Text
and then we’ll put a semicolon at the end. And now let’s output it to the console with
a Console.WriteLine and then in brackets, let’s add the text “Generated Text : and
then we’ll pass in a parameter, which is completion. Perfect.
So now we're ready to test to see if our code works. [Video description begins] The
code on line 12 reads: var completion = response.Completion[0] . Text; The code on
line 13 reads: Console.WriteLine("Generated Text: {0}", completion); [Video
description ends] So let’s start by saving the file with a Ctrl+S. And now let's go back
to the terminal with the Ctrl~ and let's Run the application using this command:
dotnet run. Awesome. So now we're seeing the response from OpenAI. Let's take a
look at it.
Apparently the completion to our prompt of a long time ago in a galaxy far, far away
is: It was a period of civil war. Rebel spaceships, striking from a hidden base, and on
and on. That looks right. Fantastic. So there you have it. In this demo, we
successfully completed a simple text completion using a generative AI and C#.
After completing this video, you will be able to describe how generative AIs can be
embedded into business processes or workflows.
[Video description begins] Topic title: Integration of Generative AI. Your host for this
session is Sven Batalla. [Video description ends]
Understanding the different types of models is essential for harnessing their power
effectively. First, we have generative models. These AI models have the remarkable
ability to well generate new data samples that resemble the input data. They
operate on a probability-based framework and produce outputs that are remarkably
similar to real data.
Next are pre-trained models. Pre-trained models are a valuable resource in the world
of generative AI. These models have undergone extensive training on vast datasets
and possess a knowledge and understanding to generate contextually relevant
content. Now, before diving into the integration of generative AI, a few essential
steps lay in the foundation for a seamless integration experience.
Setting up an account with the generative AI platform is the obvious first step. This
account enables access to the resources and tools necessary for integration. Next, to
interact with generative AI APIs, credentials and API keys are required. These
credentials act as gateways, allowing secure access to AI services. After that,
choosing the appropriate API service that aligns with the integration goals is crucial.
Monitoring the AI usage provides valuable insights into system performance and user
interactions. Regular monitoring enables the optimization of integration for
enhanced user experiences. Now, let’s talk about some specific models. OpenAI’s
GPT-3 model, for example. Integrating the powerful GPT-3 model opens doors to a
bunch of applications across diverse industries.
For example, GPT-3 can power interactive and engaging chatbots, providing
contextually relevant responses to user inquiries and conversations. It can also help
with product descriptions and textual content. In fact, GPT-3 can generate some
pretty compelling product descriptions and textual content that can streamline the
content creation process. GPT-3 can also be used to improve search engine
capabilities, providing more accurate and contextually relevant search results.
Dall-E is another OpenAI model, and it's actually a revolutionary model for image
generation because of all of its exciting integration possibilities. One example of that
is real-time image creation. Dall-E can dynamically generate images based on
textual descriptions, and by itself, that is revolutionizing for content creation.
In fact, integration with Dall-E facilitates the generation of captivating visuals for
marketing campaigns and promotional material. And it's not just about marketing
imagery. Dall-E’s ability to generate medical images based on descriptions holds
promise for enhancing medical diagnoses and research.
Even robotics can be enhanced by Codex. The model's capabilities can be harnessed
in robotics so that it can improve the human-robot interactions and autonomy. And
finally, there’s the Safety API. Now, as you can guess from the name Safety API,
integration is going to be pretty important for ensuring responsible and secure AI
applications. By integrating the Safety API, developers can add safety layers to AI
models to prevent harmful or unsafe outputs. The Safety API also helps with
understanding model behavior, which helps with ensuring accountability and
transparency in AI applications.
And lastly, in sensitive environments, the Safety API can be utilized to control and
monitor AI generated content, ensuring compliance with ethical and legal standards.
[Video description begins] Topic title: Challenges of Integrating Generative AI. Your
host for this session is Sven Batalla. [Video description ends]
These challenges can impact the seamless integration of AI services and affect the
overall success of adopting generative AI capabilities. One of the primary challenges
is dealing with technical debt. In fact, many organizations have existing systems and
infrastructure that may not be designed to accommodate the complexities of
modern generative AI APIs.
As a result, integrating these APIs into legacy systems can be time-consuming and
resource-intensive. Addressing technical debt is really important to ensure that the
integration is smooth and does not compromise the functionality of your existing
systems.
This can create compatibility issues and necessitate additional efforts to bridge the
gap between the legacy systems and the new AI capabilities. Now, keep in mind this
is a little bit different than technical debt because here we can be talking about
physical hardware as well.
Organizations must invest considerable time, resources, and expertise to create and
train these models to achieve the desired results. Handling the intricacies of model
development demands expertise in the field of AI and access to the right talent and
infrastructure. Now, as organizations explore the implementation of generative AI
APIs, several ethical concerns come to forefront.
Understanding and addressing these concerns are really important for the
responsible and ethical use of generative AI technologies, and one of the major
concerns revolves around AI hallucinations. Generative AI models can occasionally
produce misleading or false outputs. Now, such hallucinations can be problematic,
especially in critical applications like medical diagnoses or content generation for
legal purposes.
If these biases are not appropriately addressed, AI models can perpetuate and even
amplify these biases in their outputs. Organizations may be committed to mitigating
bias and promoting fairness and inclusivity in AI generated content. Rate limiting is
an important aspect of any API management, including generative AI APIs. Rate
limits control the number of requests made to the API within a specified time period.
Preventing excessive usage and ensuring fair distribution of resources. Server rate
limiting involves restricting the number of requests that a server can handle from a
particular client in a given time window. Time-based rate limiting sets restrictions
based on specific time intervals. For example, the API may allow a certain number of
requests per minute or per hour to maintain a balanced load on the server and avoid
performance bottlenecks.
User rate limiting imposes restrictions on API access on a per-user basis. Finally,
effectively managing generative AI APIs involves navigating various challenges to
optimize their integration, performance, and usability. Comprehensive API
documentation is essential for developers to understand the functionalities and
usage guidelines of the generative AI APIs.
After completing this video, you will be able to integrate generative AI APIs to create
tools like chatbots.
[Video description begins] Topic title: Creating a Generative AI Chatbot. Your host for
this session is Sven Batalla. [Video description ends]
In this demo, we're going to create a customer facing chatbot using the generative
AI in OpenAI’s API.
To do that, we're going to implement the chat API that's provided by OpenAI. The
chat API allows you to build interactive and dynamic conversations with the chatbot.
To demonstrate this, we’re going to write some code using Python in Visual Studio
Code. So obviously this demo assumes that you have VS Code and Python installed
on your system and this demo also assumes that you have an OpenAI account and
that you've generated an API key with the necessary permissions to perform the
actions in this demo. So to get started, let's head over to VS code. Good.
Now let’s open up the terminal using Ctrl~. Good. [Video description begins] The
instructor opens Visual Studio Code. It is mainly divided into two parts: The left-hand
side is the Explorer and the right-hand side is the CLI. The Menu bar contains buttons
such as File, Edit, Selection, View, and so on. There are icons such as Run and
Debug, Built-in Git, Extensions, and so on at the extreme left-hand side of the
window. [Video description ends] So what we want to do now is install the request
library so that we can interact with the chat API. To do that, let’s run this command:
pip install requests. Good.
Now what the requests library allows us to do is interact with any HTTP endpoint, like
an API. All right. Now, let’s create a Python file. To do that, let’s use the Explorer on
the left to create a New file and we'll call it chatbot.py. [Video description
begins] The instructor closes the CLI and moves to create a file named chatbot.py
under the Explorer pane. [Video description ends] chatbot.py. Perfect. All right. So
the next thing we're going to do is write some code.
Well, actually, what I'm really going to do is copy and paste some code, and then I'll
explain what that code is doing. But don't worry, I'll provide that code with this
demo. Perfect. All right. So let’s go over what this code is doing. On line 1, we import
that request library that we just installed a little bit earlier. On line 3, we reference
our OpenAI API key, so you'll have to put your key in this section. But in the
meantime, I'm going to put my key in there. Perfect. [Video description begins] The
code on line 3 reads: api_key = 'sk-
43KjzibQIE9ZFEy6kIgAT3B1bkFJsUsAj6NjATI9AyiU7o7e' [Video description ends]
Now on line 5, we create a function called chat_with_bot and this is where the magic
happens. Inside this method we print the chatbot prompt and then we create a while
loop. So on line 8, we’re requesting an input from the user. On line 10, we check to
see if that input was the term exit. And if it is, we'll actually break out of the loop and
functionally exit the program. On line 14, If the input was not exit, then we submit
the input to the chat API, which we're going to talk about in a second and then we
collect the response.
Then on line 15, we output the response and then the loop starts all over again. On
line 17, we define another function, and this is the function that we call when the
user gives us an input. There is a parameter that is the user_input into this function.
What this method does is package the user's input as a prompt into a request that
gets sent to the OpenAI GPT-3 model.
On line 18, we create the headers which uses our API key that we set up earlier and
on line 22, we provide that input data as a prompt. Now, lines 27 to 29, we parse the
response and return it. Then on line 32, when the Python script is actually run, we
call our chat method. Okay, so this might look like quite a bit of code, but it's really
not too tough. So let's see if it works.
Let’s start by saving the file with a Ctrl+S and then let’s go back to the terminal with
a Ctrl~. Okay, good. Now let's actually run our application. To do that, let’s run this
command: python chatbot . py. Perfect. Now let's run it. Cool. Our script is running.
All right, Now let's ask our bot a couple of questions just to see if it works.
Let’s start with something simple. Let’s ask it, “How many legs does a cat have?”
Okay, It's processing and it says a cat has four legs. Hey, that looks like the right
answer. I'm pretty sure cats have four legs. All right, Now let's ask it another
question.
Let’s ask it something like, “How much wood would a woodcheck chuck". Actually,
it’s could a woodchuck chuck, if I can spell. All right, let’s see what it says this time.
Amazing. It’s given us an answer. A woodchuck could chuck as much wood as a
woodchuck could chuck if a woodchuck could chuck wood. In other words, it's a fun
tongue twister, but woodchucks don’t actually chuck wood! So this is kind of cool
because it understands the semantics of what we're saying and understands it's
actually a tongue twister. But then just in case, it does give us an actual answer.
Cool.
All right. Now let's try another question. Let's ask it what time it is. "What time is it?"
Oh, interesting. So there is a limit. Now you can see that not all requests are possible
with the chat API. So we've built a pretty cool chat client, but it can't do everything.
All right. So to top it all off, let's see if our exit command works.
Let's type "exit" and hit enter. Perfect. Our app works. So there you have it.
In this demo, we created a simple Python script that is capable of behaving like a
chat client. Great job.
In this video, we will summarize the key concepts covered in this course.
[Video description begins] Topic title: Course Summary. [Video description ends]
So, in this course, we've examined generative AI functionality and how it can be
integrated.
And we did this by exploring history, future, and applications of generative AI ethical,
safety, security, and privacy concerns. Common generative AI APIs, best practices,
and image text generation.
And integrating generative AI, challenges with integration, and creating a generative
AI chatbot.