Session 5 Getting Started With Cohere
Session 5 Getting Started With Cohere
command-nightly
Updating environments, pushing to production
Cohere Baseline Models - Embed
embed-english-light-v3.0 - 512 Tokens
A smaller, faster version of embed-english-v3.0
rerank-multilingual-v2.0
• A model for documents that are not in English.
• Supports the same languages as embed-multilingual-v3.0.
Command-R is an
LLM with open Aya
weights optimized Aya is a multilingual model from Cohere For AI.
for reasoning, Is trained to support 21 languages:
summarization, and • Arabic, Chinese (simplified, traditional), Czech,
question answering. Dutch, French, German, Greek, Hindi, Indonesian,
Italian, Japanese, Korean, Persian, Polish,
Portuguese, Romanian, Russian, Spanish, Turkish,
Ukrainian, Vietnamese.
[
cohere.Generation {
id: 3d3ecb76-6435-4665-a323-6650eefc2429
prompt: Generate a concise product description for the
product: wireless earbuds.
text: These wireless earbuds are designed for comfort and
convenience, with a secure fit and easy-to-use controls. They're
perfect for when you're on the go, and provide clear sound and
reliable connectivity.
likelihood: None
token_likelihoods: None }
]
import cohere
co = cohere.Client('<<apiKey>>') A list of previous messages between the user and the
response = co.chat( model, meant to give the model conversational context for
chat_history=[ responding to the user's message.
{"role": "USER", "message": "Who discovered gravity?"},
{"role": "CHATBOT", "message": "The man who is widely
credited with discovering gravity is Sir Isaac Newton"} One of CHATBOT|USER to identify who the message is coming from.
],
message="What year was he born?",
# perform web search before answering the question. You can
also use your own custom connector.
connectors=[{"id": "web-search"}] Text input for the model to respond to.
)
print(response)
Summarize Endpoint (Deprecated)
Generates a succinct version of the original text that relays the most important information.
• Ideal use cases : news articles, blogs, chat transcripts, scientific articles, meeting
notes etc.
• The endpoint can:
• Summarize a single document
• Control output length
• Format chosen output
• Handle long documents
• Provide additional instructions to focus the summary
Summarize Endpoint – How to use?
Create prompt
text ="""It's an exciting day for the development community. Cohere's state-of-the-art language AI
is now available through Amazon SageMaker. This makes it easier for developers to deploy Cohere's
pre-trained generation language model to Amazon SageMaker, an end-to-end machine learning (ML)
service. Developers, data scientists, and business analysts use Amazon SageMaker to build, train,
and deploy ML models quickly and easily using its fully managed infrastructure, tools, and
workflows. At Cohere, the focus is on language. The company's mission is to enable developers and
businesses to add language AI to their technology stack and build game-changing applications with
it. Cohere helps developers and businesses automate a wide range of tasks, such as copywriting,
named entity recognition, paraphrasing, text summarization, and classification. The company builds
and continually improves its general-purpose large language models (LLMs), making them accessible
via a simple-to-use platform. Companies can use the models out of the box or tailor them to their
particular needs using their own custom data. Developers using SageMaker will have access to
Cohere's Medium generation language model. The Medium generation model excels at tasks that
require fast responses, such as question answering, copywriting, or paraphrasing. The Medium model
is deployed in containers that enable low-latency inference on a diverse set of hardware
accelerators available on AWS, providing different cost and performance advantages for SageMaker
customers. """
Summarize Endpoint – Define model settings. format
import cohere
co = cohere.Client('<<apiKey>>')
response = co.generate(
prompt='Please explain to me how LLMs work',
)
print(response)
Embed
{
"response_type": "embeddings_floats",
https://api.cohere.ai/v1/embed "id": "string",
"embeddings": [
[
0
• Returns text embeddings. ]
],
• An embedding is a list of floating point numbers that captures "texts": [
"string"
semantic information about the text that it represents. ],
"meta": {
• Embeddings can be used to create text classifiers as well as "api_version": {
"version": "string",
empower semantic search. "is_deprecated": true,
"is_experimental": true
},
import cohere "billed_units": {
co = cohere.Client('<<apiKey>>') "input_tokens": 0,
"output_tokens": 0,
"search_units": 0,
response = co.embed( "classifications": 0
texts=['hello', 'goodbye'], },
model='embed-english-v3.0', "warnings": [
input_type='classification' "string"
) ]
print(response) }
}
Cohere Playground
• A visual interface for users to test Cohere’s LLMs without writing a single line of
code.
Why Use Cohere Playground?
On the top you will see the 5 tabs: Pickup your Model
• Generate,
• Classify, Cohere Playground offers a variety of
models, each with its own set of
• Embed, strengths.
• Summarize and
• Chat. For example, command is a popular
choice for its superior text generation
abilities.
Chat API Example
You can search a specific website and ask questions about it.
Thank You