Generative AI LLM Tutorial
Generative AI LLM Tutorial
GPT-3.5
GPT-3.5 is an earlier version of GPT-4, and it is smaller and less capable than its
successor. However, it is still a very powerful LLM, and it is a good choice for tasks that
require moderate levels of processing power, such as:
Generating text
Translating languages
Writing different kinds of creative content
Answering your questions in an informative way
GPT-4
GPT-4 is the latest version of GPT, and it is significantly larger and more capable than
GPT-3.5. It is also multimodal, meaning that it can process and generate text, images,
and code. GPT-4 is a good choice for tasks that require high levels of processing
power, such as:
You should choose GPT-4 if you are looking for the most powerful and versatile LLM
available. GPT-4 is a good choice for developers who are building cutting-edge AI
applications, as well as for individuals who are looking for a tool to help them with their
most challenging writing and creative tasks.
Here is a table summarizing the key differences between GPT-3.5 and GPT-4:
In conclusion, both GPT-3.5 and GPT-4 are powerful LLMs that can be used for a wide
range of tasks. The best choice for you will depend on your specific needs and
requirements.
Comparison of different LLM like Open AI GPT 6,
Anthropic , Google Bard , Amazon Bedrock Titan along
with scenarios when to use which LLM
Here is a comparison of different LLMs like OpenAI GPT-6, Anthropic, Google Bard,
and Amazon Bedrock Titan along with scenarios when to use which LLM:
Generating
Capable of
creative text
A large generating human-
formats,
language model quality text,
translating
with 175 billion translating
Can be languages,
OpenAI parameters, languages, writing
biased and writing different
GPT-6 trained on a different kinds of
inaccurate. kinds of creative
massive creative content,
content,
dataset of text and answering
answering
and code. questions in an
questions in an
informative way.
informative way.
A cloud-based
service that Businesses that
Democratizes Relies on
allows want to build and
access to third-party
customers to scale generative
generative AI and foundation
build and scale AI applications
Amazon enables customers models, which
generative AI without having to
Bedrock to customize and may not be as
applications invest in the
Titan deploy models for powerful or
using infrastructure and
their specific needs versatile as
foundation expertise to
across different Anthropic or
models from develop their own
industries. Google Bard.
various models.
providers.
OpenAI GPT-6:
o When you need a powerful and affordable LLM for a wide range of tasks.
o When you are developing applications that require natural language processing.
o When you are looking for a tool to help you with your writing and creative work.
Anthropic:
o When you are looking for the most powerful and versatile LLM available.
o When you are developing cutting-edge AI applications.
o When you are looking for a tool to help you with your most challenging writing
and creative tasks.
Google Bard:
o When you need an LLM that is conversational and contextual.
o When you need an LLM that can handle complex queries and generate factual
answers.
o When you need an LLM that integrates with other Google services.
Amazon Bedrock Titan:
o When you want to build and scale generative AI applications without having to
invest in the infrastructure and expertise to develop your own models.
o When you need a cloud-based solution that can be easily customized and
deployed.
I hope this information is helpful. Please let me know if you have any other questions.
Sources
info
1. www.linkedin.com/pulse/rise-rivalry-generative-ai-comparison-openai-chatgpt-
google-darbari
GPT-3.5 APIs
Completion API: This is the most versatile API for GPT-3.5, and it can
be used for a wide range of tasks, including generating text, translating
languages, writing different kinds of creative content, and answering
questions in an informative way.
Example: You can use the Completion API to generate a poem about a
sunset.
Python
import openai
openai.api_key = "YOUR_API_KEY"
print(response.choices[0].text)
Chat API: This API is specifically designed for chat conversations, and it
can be used to build chatbots and other conversational applications.
Example: You can use the Chat API to build a chatbot that answers questions
about your company's products.
Python
import openai
openai.api_key = "YOUR_API_KEY"
while True:
response = conversation.continue_(prompt=conversation.chat_log[-1].text)
print(response.choices[0].text)
GPT-4 APIs
Completion API: This API is similar to the Completion API for GPT-3.5,
but it is more powerful and can generate more complex and creative
text formats.
Example: You can use the Completion API to generate a script for a movie
scene.
Python
import openai
openai.api_key = "YOUR_API_KEY"
print(response.choices[0].text)
Image API: This API can be used to generate images from text
descriptions.
Example: You can use the Image API to generate an image of a cat wearing a
hat.
Python
import openai
openai.api_key = "YOUR_API_KEY"
print(response.url)
Code API: This API can be used to generate code from text
descriptions.
Example: You can use the Code API to generate a Python function that takes
a list of numbers and returns the average.
Python
import openai
openai.api_key = "YOUR_API_KEY"
GPT-3.5 APIs
Chat API
The Chat API is specifically designed for chat conversations, and it can be
used to build chatbots and other conversational applications. It is a good
choice for tasks that require a natural and engaging conversation flow, such
as customer service chatbots or virtual assistants.
C# Example:
C#
using OpenAI.API.Models;
while (true)
{
ConversationResponse response =
client.ContinueChatConversation(conversation.Id, new
ChatConversationContinueRequest()
{
Prompt = conversation.ConversationLog.Last().Text
});
Console.WriteLine(response.Choices[0].Text);
}
Completion API
The Completion API is a versatile API that can be used for a wide range of
tasks, including generating text, translating languages, writing different kinds
of creative content, and answering questions in an informative way. It is a
good choice for tasks that require generating text from a given prompt or
context, such as writing product descriptions or generating creative writing
prompts.
C# Example:
C#
using OpenAI.API.Models;
Console.WriteLine(response.Choices[0].Text);
Files API
The Files API is used to upload and manage files that can be used with other
OpenAI APIs, such as the Completion API and the Embeddings API. It is a
good choice for tasks that require processing text files, such as generating
summaries of documents or translating documents into different languages.
C# Example:
C#
using OpenAI.API.Models;
Console.WriteLine(response.Choices[0].Text);
Embeddings API
C# Example:
C#
using OpenAI.API.Models;
GPT-4 APIs
GPT-4 APIs are similar to the GPT-3.5 APIs, but they are more powerful and
can generate more complex and creative text formats. They can also generate
images from text descriptions and generate code from text descriptions.
These examples are not currently available as GPT-4 APIs are not yet
available in C#. However, the structure of the requests and responses would
be similar to the GPT-3.5 examples.
C#
// Image API
Console.WriteLine(response.Url);
C#
// Code API
Open
Amazon Bedrock
Amazon Bedrock is a cloud-based service that enables organizations to build and scale
generative AI applications using foundation models from various providers. It provides a
unified platform for accessing and managing these models, simplifying the development
and deployment of generative AI applications.
Advantages:
Democratizes Access to Generative AI: Bedrock lowers the barrier to entry for
generative AI, making it accessible to organizations of all sizes and technical
expertise.
Centralized Model Management: Bedrock centralizes the management of
foundation models, simplifying the process of selecting, deploying, and scaling
models.
Cloud-Based Infrastructure: Bedrock leverages Amazon's cloud infrastructure,
ensuring scalability and reliability.
Integration with AWS Services: Bedrock integrates seamlessly with other AWS
services, providing a unified environment for building and deploying generative AI
applications.
Disadvantages:
OpenAI
Advantages:
Access to Cutting-Edge Models: OpenAI offers access to the most advanced and
powerful generative AI models available.
Flexibility and Customization: Organizations have more control over model
selection, customization, and training.
Direct Access to OpenAI's Research: OpenAI provides access to its latest
research and development in generative AI.
Disadvantages:
Technical Expertise Required: OpenAI's APIs and platform require a higher level
of technical expertise.
Higher Costs: OpenAI's solutions may be more expensive than Amazon Bedrock.
Potential for Bias and Misuse: OpenAI's models require careful handling to avoid
bias and misuse.
Conclusion
The choice between Amazon Bedrock and OpenAI depends on the specific needs and
capabilities of each organization. Organizations with limited technical expertise may find
Amazon Bedrock's turnkey solution more appealing, while organizations with advanced
machine learning expertise may prefer OpenAI's flexibility and access to cutting-edge
models. Ultimately, the best approach is to evaluate both platforms and select the one
that best aligns with the organization's goals and resources.
APIs used in LLMs like Titan, Anthropic models, Google
Bard and Azure Open AI. Comparison of consumption
cost for each for every 1K tokens. Also give me examples
in C# on when to use which API for different models in
Titan, Anthropic , Azure Open AI and Google Bard
Here is a summary of the APIs used in LLMs like Titan, Anthropic models, Google Bard,
and Azure OpenAI, along with a comparison of consumption costs for each for every
1,000 tokens, and example API calls in C# for different use cases:
Titan
Completion API: The Completion API is a versatile API that can be used for a
wide range of tasks, including generating text, translating languages, writing
different kinds of creative content, and answering questions in an informative
way.
Translation API: The Translation API is specifically designed for translating text
from one language to another.
Code API: The Code API can be used to generate code from text descriptions.
Anthropic
Completion API: The Completion API is similar to the Completion API in Titan,
but it can generate more complex and creative text formats.
Code API: The Code API is similar to the Code API in Titan, but it can generate
more complex and functional code.
Google Bard
Google Bard is a large language model developed by Google AI. It is known for its
ability to generate human-quality text, translate languages, write different kinds of
creative content, and answer questions in an informative way.
Completion API: The Completion API is similar to the Completion API in Titan,
but it is specifically designed for use with Google Bard.
Chat API: The Chat API is specifically designed for chat conversations.
Azure OpenAI
Azure OpenAI is a service that provides access to OpenAI's large language models,
such as GPT-3 and GPT-4, through its REST API.
Completion API: The Completion API is similar to the Completion API in Titan,
but it is specifically designed for use with OpenAI's models.
Titan: $0.005
Anthropic: $0.010
C# Examples
Here are some example API calls in C# for different use cases:
Titan
C#
using Amazon.AI.Models;
// Generate text
CompletionResponse completionResponse = client.CreateCompletion(new
CompletionRequest()
{
Engine = "davinci",
Prompt = "Write a poem about a sunset."
});
Console.WriteLine(completionResponse.Choices[0].Text);
// Translate text
TranslationResponse translationResponse = client.CreateTranslation(new
TranslationRequest()
{
Engine = "davinci",
SourceLanguageCode = "en",
TargetLanguageCode = "fr",
TextToTranslate = "Hello, how are you?"
});
Console.WriteLine(translationResponse.TranslatedText);
// Generate code
CodeResponse codeResponse = client.CreateCode(new CodeRequest()
{
Engine = "davinci",
Prompt = "Generate a Python function that takes a list of numbers and
returns the average."
});
Console.WriteLine(codeResponse.Choices[0].Text);
Anthropic
C#
using Anthropic.Models;
Console.WriteLine(completionResponse.Choices[0].Text);
Console.WriteLine(codeResponse.Choices[0].Text);
Google Bard
C#
using Google.AI.Models;
Console.WriteLine(completionResponse.Choices[0].Text);
Console.WriteLine(translationResponse.TranslatedText);
Console.WriteLine(completionResponse.Choices[0].Text);
Console.WriteLine(questionAnsweringResponse.Answers[0].Text);
Azure OpenAI
C#
using Azure.AI.OpenAI.Models;
The best API for a particular task depends on the specific requirements of the task.
Here is a table that summarizes when to use each API:
Task API
1. Azure OpenAI Service: This is the core service that provides access to OpenAI's
large language models (LLMs) like GPT-3 and GPT-4. It offers a REST API for
interacting with the models and generating text, translating languages, writing
creative content, and answering questions.
2. Azure Storage: To store the training data and generated outputs, you'll need
Azure Blob Storage or Azure Data Lake Storage. These services provide
scalable and secure storage for large volumes of data.
3. Azure Compute: Depending on the complexity and computational requirements
of your generative AI solution, you may need Azure virtual machines (VMs) or
Azure Functions to run the application code. Azure VMs offer a flexible and
scalable compute environment, while Azure Functions provide a serverless
platform for running code without managing infrastructure.
4. Azure Networking: To connect your application to Azure OpenAI and other Azure
services, you'll need a virtual network (VNet) and network security groups
(NSGs). These components ensure secure and controlled communication within
your Azure environment.
5. Azure Monitoring: To monitor the health and performance of your generative AI
solution, you can use Azure Monitor. It provides insights into resource utilization,
error logs, and application performance metrics.
6. Deployment Automation: To automate the deployment process of your
generative AI solution, consider using Azure DevOps or Azure Resource
Manager templates. These tools enable consistent and repeatable deployments
across different environments.
7. Access Management: To manage access to your Azure OpenAI resources and
control who can use the generated outputs, implement Azure Active Directory
(Azure AD) and role-based access control (RBAC). These mechanisms ensure
secure access to sensitive data and prevent unauthorized usage.
8. Data Governance: Establish data governance policies and procedures to ensure
the responsible collection, storage, and usage of data for training and generating
AI models. This includes data privacy considerations, data quality checks, and
bias mitigation strategies.
9. Model Monitoring: Continuously monitor the performance and fairness of your
generative AI models to detect and address potential issues like bias, accuracy
drift, and inappropriate outputs. Utilize tools like Azure Machine Learning Service
(AML) to track model performance metrics and identify anomalies.
10. Explainability and Interpretability: Implement techniques to explain and interpret
the decisions made by your generative AI models, especially when used for
critical decision-making processes. This helps understand the rationale behind
model outputs and build trust in the AI system.
Comparison of the services required for Azure and AWS to deploy Generative AI
(Gen AI) solutions:
Storage for training Azure Blob Storage or Azure Amazon S3 or Amazon Elastic
data and outputs Data Lake Storage Block Store (EBS)
Compute for running Azure Virtual Machines Amazon Elastic Compute Cloud
application code (VMs) or Azure Functions (EC2) or AWS Lambda
Azure OpenAI: Provides access to OpenAI's large language models (LLMs) like
GPT-3 and GPT-4.
Azure Blob Storage: Scalable and secure object storage for large amounts of
unstructured data.
Azure Data Lake Storage: Scalable and secure hierarchical storage for both
structured and unstructured data.
Amazon EBS: Block storage for persistent data volumes attached to EC2
instances.
Azure VMs: Flexible and scalable compute environment for running application
code.
Networking:
Azure VNet: Logical isolation for resources within the Azure cloud.
Amazon VPC: Logical isolation for resources within the AWS cloud.
Monitoring:
Azure Monitor: Collects and analyzes data from Azure resources to monitor
performance and health.
Amazon CloudWatch: Collects and monitors metrics, logs, and events from AWS
resources.
Deployment automation:
Azure Resource Manager templates: Code templates for defining and deploying
Azure resources.
Access management:
Azure AD: Provides identity and access management for Azure resources.
AWS IAM: Provides identity and access management for AWS resources.
IAM Roles for AWS Services: Allows AWS services to assume IAM roles and
perform actions on behalf of the user.
Data governance:
Azure Data Factory: Data integration service for moving and transforming data.
Azure Data Lake Governance: Data governance service for managing data
assets in Azure Data Lake Storage.
Amazon Glue: Data integration service for moving and transforming data.
AWS Lake Formation: Data governance service for managing data assets in
Amazon S3.
Model monitoring:
In general, both Azure and AWS offer a comprehensive set of services for deploying
Gen AI solutions. The best choice for a particular organization will depend on their
specific needs and experience with each platform