### Install Docker on Ubuntu Source: https://docs.cohere.com/docs/aws-private-deployment Installs Docker on an Ubuntu instance, starts the Docker service, and enables it to start on boot. It also verifies the installation by running a 'hello-world' container. ```bash sudo apt-get update sudo apt-get install docker.io -ysudo systemctl start docker sudo docker run hello-world sudo systemctl enable docker docker --version ``` -------------------------------- ### Example Prompt to Begin Completion (HTML) Source: https://docs.cohere.com/docs/crafting-effective-prompts Guides the LLM by providing the starting HTML structure for the desired output. ```text Please generate the response in a well-formed HTML document. The completion should begin as follows: ``` -------------------------------- ### Internet Search Example for API Setup Source: https://docs.cohere.com/docs/routing-queries-to-data-sources This example illustrates the agent's process for answering a question about setting up an external API using the `search_internet` tool. It details the steps for creating a Notion integration. ```mdx QUESTION: How to set up the Notion API. ================================================== TOOL PLAN: I will search for 'Notion API setup' to find out how to set up the Notion API. TOOL CALLS: Tool name: search_internet | Parameters: {"query":"Notion API setup"} ================================================== RESPONSE: To set up the Notion API, you need to create a new integration in Notion's integrations dashboard. You can do this by navigating to https://www.notion.com/my-integrations and clicking '+ New integration'. Once you've done this, you'll need to get your API secret by visiting the Configuration tab. You should keep your API secret just that – a secret! You can refresh your secret if you accidentally expose it. Next, you'll need to give your integration page permissions. To do this, you'll need to pick or create a Notion page, then click on the ... More menu in the top-right corner of the page. Scroll down to + Add Connections, then search for your integration and select it. You'll then need to confirm the integration can access the page and all of its child pages. If your API requests are failing, you should confirm you have given the integration permission to the page you are trying to update. You can also create a Notion API integration and get your internal integration token. You'll then need to create a .env file and add environmental variables, get your Notion database ID and add your integration to your database. For more information on what you can build with Notion's API, you can refer to this guide. ================================================== CITATIONS: Start: 38| End:62| Text:'create a new integration' Sources: 1. search_internet_cwabyfc5mn8c:0 2. search_internet_cwabyfc5mn8c:2 Start: 75| End:98| Text:'integrations dashboard.' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 132| End:170| Text:'https://www.notion.com/my-integrations' Sources: 1. search_internet_cwabyfc5mn8c:0 Start: 184| End:203| Text:''+ New integration'' Sources: 1. search_internet_cwabyfc5mn8c:0 2. search_internet_cwabyfc5mn8c:2 Start: 244| End:263| Text:'get your API secret' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 280| End:298| Text:'Configuration tab.' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 310| End:351| Text:'keep your API secret just that – a secret' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 361| End:411| Text:'refresh your secret if you accidentally expose it.' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 434| End:473| Text:'give your integration page permissions.' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 501| End:529| Text:'pick or create a Notion page' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 536| End:599| Text:'click on the ... More menu in the top-right corner of the page.' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 600| End:632| Text:'Scroll down to + Add Connections' Sources: 1. search_internet_cwabyfc5mn8c:2 Start: 639| End:681| Text:'search for your integration and select it.' Sources: 1. search_internet_cwabyfc5mn8c:2 ``` -------------------------------- ### Install Cohere Go SDK Source: https://docs.cohere.com/docs/get-started-installation Install the Cohere Go SDK using the go get command. This command fetches and installs the cohere-go package for your Go project. ```bash go get github.com/cohere-ai/cohere-go/v2 ``` -------------------------------- ### Python Classify Example with Examples Source: https://docs.cohere.com/reference/classify Demonstrates how to use the Python SDK to classify a list of inputs using provided examples. Ensure you have the cohere library installed and replace placeholders with your actual token and model ID. ```python import asyncio from cohere import Client, ClassifyExample async def main(): response = await cohere.classify( model="", inputs=[ "Confirm your email address", "hey i need u to send some $", ], examples=[ ClassifyExample(text="Please help me?", label="Spam"), ClassifyExample(text="Your parcel will be delivered today", label="Not spam"), ClassifyExample( text="Review changes to our Terms and Conditions", label="Not spam" ), ClassifyExample(text="Weekly sync notes", label="Not spam"), ClassifyExample(text="'Re: Follow up from today's meeting'", label="Not spam"), ClassifyExample(text="Pre-read for tomorrow", label="Not spam"), ], ) print(response) asyncio.run(main()) ``` -------------------------------- ### Create Audio Transcription Request Setup (C#) Source: https://docs.cohere.com/reference/create-audio-transcription This C# example shows the initial setup for making an audio transcription request using RestSharp. It configures the client and request URL and adds the authorization header. ```csharp using RestSharp; var client = new RestClient("https://api.cohere.com/v2/audio/transcriptions"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); ``` -------------------------------- ### Install Cohere SDK and Setup Azure Clients Source: https://docs.cohere.com/docs/cohere-on-azure/azure-ai-rag Installs the Cohere SDK and initializes clients for chat, embed, and rerank models deployed on Azure AI Foundry. Requires Azure API keys and endpoint URLs for each model. ```python # %pip install cohere hnswlib unstructured import cohere co_chat = cohere.ClientV2( api_key="AZURE_API_KEY_CHAT", base_url="AZURE_ENDPOINT_CHAT", # example: "https://cohere-command-r-plus-08-2024-xyz.eastus.models.ai.azure.com/" ) co_embed = cohere.ClientV2( api_key="AZURE_API_KEY_EMBED", base_url="AZURE_ENDPOINT_EMBED", # example: "https://embed-v-4-0-xyz.eastus.models.ai.azure.com/" ) co_rerank = cohere.ClientV2( api_key="AZURE_API_KEY_RERANK", base_url="AZURE_ENDPOINT_RERANK", # example: "https://cohere-rerank-v3-multilingual-xyz.eastus.models.ai.azure.com/" ) ``` -------------------------------- ### Install Cohere SDK and Initialize Client for Azure Source: https://docs.cohere.com/docs/cohere-on-azure/azure-ai-reranking Install the Cohere Python SDK and initialize the client with your Azure API key and the model's base URL for the Azure endpoint. This setup is required before making any API calls. ```python # %pip install cohere import cohere co = cohere.ClientV2( api_key="AZURE_API_KEY_RERANK", base_url="AZURE_ENDPOINT_RERANK", # example: "https://cohere-rerank-v3-multilingual-xyz.eastus.models.ai.azure.com/" ) ``` -------------------------------- ### End-to-End Tool Use Example Source: https://docs.cohere.com/docs/tool-use-overview Demonstrates a full tool use round trip: model gets a message, generates a tool call, gets tool results, and responds with citations. Requires the Cohere client to be installed. ```python # ! pip install -U cohere # Do this if you don't already have the Cohere client installed. import json import cohere def search_docs(query: str, top_k: int = 3): # Implement your retrieval logic here (vector DB, keyword search, etc.) # For simplicity, we'll return a few hardcoded "documents". return [ { "title": "Cohere API v2 - Chat", "url": "https://docs.cohere.com/reference/chat", "text": "Use the Chat endpoint to generate responses and optionally call tools.", }, { "title": "Tool use (function calling) overview", "url": "https://docs.cohere.com/v2/docs/tool-use-overview", "text": "Tool use connects models to external tools like search engines and APIs.", }, { "title": "Structured outputs", "url": "https://docs.cohere.com/docs/structured-outputs", "text": "Use JSON schema to define structured inputs/outputs for tools and responses.", }, ][:top_k] functions_map = {"search_docs": search_docs} tools = [ { "type": "function", "function": { "name": "search_docs", "description": "Search documentation and return relevant snippets as documents.", "parameters": { "type": "object", "properties": { "query": { "type": "string", "description": "The search query to look up in the docs.", }, "top_k": { "type": "integer", "description": "How many documents to return.", }, }, "required": ["query"], }, }, } ] co = cohere.ClientV2("COHERE_API_KEY") # Step 1: user message messages = [ { "role": "user", "content": "How does tool use work in Cohere? Please cite your sources.", } ] # Step 2: model generates tool calls response = co.chat( model="command-a-plus-05-2026", messages=messages, tools=tools ) if response.message.tool_calls: messages.append(response.message) # Step 3: application executes tools and sends tool results back for tc in response.message.tool_calls: tool_result = functions_map[tc.function.name]( **json.loads(tc.function.arguments) ) tool_content = [] for data in tool_result: tool_content.append( { "type": "document", "document": {"data": json.dumps(data)}, } ) messages.append( { "role": "tool", "tool_call_id": tc.id, "content": tool_content, } ) # Step 4: model generates a response grounded in tool results (with citations) response = co.chat( model="command-a-plus-05-2026", messages=messages, tools=tools ) print(response.message.content[0].text) print(response.message.citations) ``` -------------------------------- ### Install Cohere Library and Initialize Client Source: https://docs.cohere.com/docs/building-a-chatbot-with-cohere Install the cohere library and create a Cohere client. Ensure you have your API key from the Cohere dashboard. ```python # pip install cohere import cohere # Get your free API key: https://dashboard.cohere.com/api-keys co = cohere.ClientV2(api_key="COHERE_API_KEY") ``` -------------------------------- ### Example Introduction Message Source: https://docs.cohere.com/docs/text-gen-quickstart This is an example of a one-sentence introduction message suitable for teammates at a new startup. ```text "Excited to join the team at Co1t, looking forward to contributing my skills and collaborating with everyone!" ``` -------------------------------- ### Get Finetuned Model using HTTP Request (PHP) Source: https://docs.cohere.com/reference/getfinetunedmodel Example of fetching a finetuned model by its ID using PHP with Guzzle HTTP client. Ensure you have the SDK installed and replace '' with your actual bearer token. ```php request('GET', 'https://api.cohere.com/v1/finetuning/finetuned-models/id', [ 'headers' => [ 'Authorization' => 'Bearer ', 'X-Client-Name' => 'my-cool-project', ], ]); echo $response->getBody(); ``` -------------------------------- ### Streaming Response Example Source: https://docs.cohere.com/docs/tool-use-streaming This example shows the sequence of events and content deltas received when a model uses tools and streams its response. It includes message start, content start, content deltas, and citation events. ```text "What's the weather in Madrid and Brasilia?" type='message-start' id='e8f9afc1-0888-46f0-a9ed-eb0e5a51e17f' delta=ChatMessageStartEventDelta(message=ChatMessageStartEventDeltaMessage(role='assistant', content=[], tool_plan='', tool_calls=[], citations=[])) -------------------------------------------------- type='content-start' index=0 delta=ChatContentStartEventDelta(message=ChatContentStartEventDeltaMessage(content=ChatContentStartEventDeltaMessageContent(text='', type='text'))) -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='It'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' is'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' currently'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' 2'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='4'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='°'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='C in'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' Madrid'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' and'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' 2'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='8'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='°'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='C in'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' Brasilia'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='.'))) logprobs=None -------------------------------------------------- type='citation-start' index=0 delta=CitationStartEventDelta(message=CitationStartEventDeltaMessage(citations=Citation(start=16, end=20, text='24°C', sources=[ToolSource(type='tool', id='get_weather_m3kdvxncg1p8:0', tool_output={'temperature': '{"madrid":"24°C"}'})], type='TEXT_CONTENT'))) -------------------------------------------------- type='citation-end' index=0 -------------------------------------------------- type='citation-start' index=1 delta=CitationStartEventDelta(message=CitationStartEventDeltaMessage(citations=Citation(start=35, end=39, text='28°C', sources=[ToolSource(type='tool', id='get_weather_cfwfh3wzkbrs:0', tool_output={'temperature': '{"brasilia":"28°C"}'})], type='TEXT_CONTENT'))) -------------------------------------------------- type='citation-end' index=1 ``` -------------------------------- ### Example Introduction Message Source: https://docs.cohere.com/docs/text-gen-quickstart A sample one-sentence introduction message for new teammates at a startup. ```text "Excited to be part of the Co1t team, I'm [Your Name], a [Your Role/Position], looking forward to contributing my skills and collaborating with this talented group to drive innovation and success." ``` -------------------------------- ### Example Introduction Message Source: https://docs.cohere.com/docs/text-gen-quickstart A sample one-sentence introduction message generated for a new team member joining a startup. ```markdown "Excited to be part of the Co1t team, I'm [Your Name], a [Your Role], passionate about [Your Area of Expertise] and looking forward to contributing to the company's success." ``` -------------------------------- ### Install Dependencies Source: https://docs.cohere.com/page/creating-a-qa-bot Installs necessary Python packages for Cohere, datasets, and LlamaIndex. Use this at the beginning of your project setup. ```python %%capture !pip install cohere datasets llama_index llama-index-llms-cohere llama-index-embeddings-cohere ``` -------------------------------- ### Get Dataset Usage via HTTP GET Request (Swift) Source: https://docs.cohere.com/reference/get-dataset-usage Perform an HTTP GET request in Swift to fetch dataset usage. This example uses URLSession and configures necessary headers. ```swift import Foundation let headers = [ "X-Client-Name": "my-cool-project", "Authorization": "Bearer " ] let request = NSMutableURLRequest(url: NSURL(string: "https://api.cohere.com/v1/datasets/usage")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Cohere Client Setup Source: https://docs.cohere.com/docs/tool-use-overview Import the Cohere library and create a client. This is the initial step for using Cohere's API. ```python import cohere co = cohere.ClientV2("COHERE_API_KEY") ``` -------------------------------- ### RAG Streaming Example Source: https://docs.cohere.com/docs/rag-streaming This example shows the event stream for a RAG-enabled chat response. It includes message start, content deltas, and citation events. ```text "Where do the tallest penguins live?" type='message-start' id='d93f187e-e9ac-44a9-a2d9-bdf2d65fee94' delta=ChatMessageStartEventDelta(message=ChatMessageStartEventDeltaMessage(role='assistant', content=[], tool_plan='', tool_calls=[], citations=[])) -------------------------------------------------- type='content-start' index=0 delta=ChatContentStartEventDelta(message=ChatContentStartEventDeltaMessage(content=ChatContentStartEventDeltaMessageContent(text='', type='text'))) -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='The'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' tallest'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' penguins'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' are'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' the'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' Emperor'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' penguins'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='.'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' They'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' only'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' live'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' in'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text=' Antarctica'))) logprobs=None -------------------------------------------------- type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatContentDeltaEventDeltaMessageContent(text='.'))) logprobs=None -------------------------------------------------- type='citation-start' index=0 delta=CitationStartEventDelta(message=CitationStartEventDeltaMessage(citations=Citation(start=29, end=46, text='Emperor penguins.', sources=[DocumentSource(type='document', id='doc:0', document={'id': 'doc:0', 'snippet': 'Emperor penguins are the tallest.', 'title': 'Tall penguins'})], type='TEXT_CONTENT'))) -------------------------------------------------- type='citation-end' index=0 -------------------------------------------------- type='citation-start' index=1 delta=CitationStartEventDelta(message=CitationStartEventDeltaMessage(citations=Citation(start=65, end=76, text='Antarctica.', sources=[DocumentSource(type='document', id='doc:1', document={'id': 'doc:1', 'snippet': 'Emperor penguins only live in Antarctica.', 'title': 'Penguin habitats'})], type='TEXT_CONTENT'))) -------------------------------------------------- type='citation-end' index=1 -------------------------------------------------- type='content-end' index=0 -------------------------------------------------- ``` -------------------------------- ### Set Up System Preamble and User Message Source: https://docs.cohere.com/page/basic-tool-use Define the system's instructions and the user's request to guide the model's response and tool selection. ```python preamble = """ ## Task & Context You help people answer their questions and other requests interactively. You will be asked a very wide array of requests on all kinds of topics. You will be equipped with a wide range of search engines or similar tools to help you, which you use to research your answer. You should focus on serving the user's needs as best you can, which will be wide-ranging. ## Style Guide Unless the user asks for a different style of answer, you should answer in full sentences, using proper grammar and spelling. """ message = "Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?" ``` -------------------------------- ### List Training Step Metrics in Python (SDK Example) Source: https://docs.cohere.com/reference/listtrainingstepmetrics Example demonstrating the use of the Cohere Python SDK for listing training step metrics, including client initialization. ```python from cohere import Client client = Client( token="YOUR_TOKEN_HERE", client_name="my-cool-project", ) client.finetuning.list_training_step_metrics( finetuned_model_id="finetuned_model_id", ) ``` -------------------------------- ### List Models via HTTP GET Request (C#) Source: https://docs.cohere.com/reference/list-models Employ C# with RestSharp to perform an HTTP GET request to the Cohere API for listing models. Ensure RestSharp is installed. ```csharp using RestSharp; var client = new RestClient("https://api.cohere.com/v1/models"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Install Cohere Python SDK Source: https://docs.cohere.com/page/aya-vision-intro Installs the Cohere Python SDK. Use this command before initializing the client. ```python %pip install cohere -q ``` -------------------------------- ### Example Citation Output Source: https://docs.cohere.com/page/basic-rag This is an example of the structured output for citations generated by a Cohere RAG call. Each entry details the character range (start, end), the extracted text, and the document(s) it belongs to. ```text Citations that support the final answer: {'start': 63, 'end': 79, 'text': 'Denis Villeneuve', 'document_ids': ['doc_0']} {'start': 81, 'end': 102, 'text': 'director and producer', 'document_ids': ['doc_0']} {'start': 105, 'end': 116, 'text': 'Jon Spaihts', 'document_ids': ['doc_0']} {'start': 118, 'end': 145, 'text': 'co-writer of the screenplay', 'document_ids': ['doc_0']} {'start': 148, 'end': 159, 'text': 'Mary Parent', 'document_ids': ['doc_1']} {'start': 164, 'end': 175, 'text': 'Cale Boyter', 'document_ids': ['doc_1']} {'start': 177, 'end': 186, 'text': 'producers', 'document_ids': ['doc_1']} {'start': 190, 'end': 204, 'text': 'Tanya Lapointe', 'document_ids': ['doc_1']} {'start': 206, 'end': 219, 'text': 'Brian Herbert', 'document_ids': ['doc_1']} {'start': 221, 'end': 234, 'text': 'Byron Merritt', 'document_ids': ['doc_1']} {'start': 236, 'end': 247, 'text': 'Kim Herbert', 'document_ids': ['doc_1']} {'start': 249, 'end': 260, 'text': 'Thomas Tull', 'document_ids': ['doc_1']} {'start': 262, 'end': 283, 'text': 'Richard P. Rubinstein', 'document_ids': ['doc_1']} {'start': 285, 'end': 298, 'text': 'John Harrison', 'document_ids': ['doc_1']} {'start': 300, 'end': 315, 'text': 'Herbert W. Gain', 'document_ids': ['doc_1']} {'start': 320, 'end': 337, 'text': 'Kevin J. Anderson', 'document_ids': ['doc_1']} {'start': 339, 'end': 358, 'text': 'executive producers', 'document_ids': ['doc_1']} {'start': 362, 'end': 372, 'text': 'Joe Walker', 'document_ids': ['doc_2']} {'start': 374, 'end': 380, 'text': 'editor', 'document_ids': ['doc_2']} {'start': 383, 'end': 393, 'text': 'Brad Riker', 'document_ids': ['doc_2']} {'start': 395, 'end': 419, 'text': 'supervising art director', 'document_ids': ['doc_2']} {'start': 422, 'end': 438, 'text': 'Patrice Vermette', 'document_ids': ['doc_2']} {'start': 440, 'end': 459, 'text': 'production designer', 'document_ids': ['doc_2']} {'start': 462, 'end': 474, 'text': 'Paul Lambert', 'document_ids': ['doc_2']} {'start': 476, 'end': 501, 'text': 'visual effects supervisor', 'document_ids': ['doc_2']} {'start': 504, 'end': 515, 'text': 'Gerd Nefzer', 'document_ids': ['doc_2']} {'start': 517, 'end': 543, 'text': 'special effects supervisor', 'document_ids': ['doc_2']} {'start': 546, 'end': 562, 'text': 'Thomas Struthers', 'document_ids': ['doc_2']} {'start': 564, 'end': 582, 'text': 'stunt coordinator.', 'document_ids': ['doc_2']} {'start': 686, 'end': 691, 'text': '2024.', 'document_ids': ['doc_0']} ``` -------------------------------- ### Example Citation Output Source: https://docs.cohere.com/page/basic-tool-use This is an example of the raw citation data that might be returned by a Cohere model. Each citation includes start and end character offsets, the cited text, and document IDs. ```text Citations that support the final answer: {'start': 7, 'end': 26, 'text': '29th September 2023', 'document_ids': ['query_daily_sales_report:0:0']} {'start': 32, 'end': 61, 'text': 'total sales amount was 10,000', 'document_ids': ['query_daily_sales_report:0:0']} {'start': 70, 'end': 95, 'text': 'total units sold was 250.', 'document_ids': ['query_daily_sales_report:0:0']} {'start': 168, 'end': 180, 'text': 'Product Name', 'document_ids': ['query_product_catalog:1:0']} {'start': 183, 'end': 188, 'text': 'Price', 'document_ids': ['query_product_catalog:1:0']} {'start': 191, 'end': 201, 'text': 'Product ID', 'document_ids': ['query_product_catalog:1:0']} {'start': 204, 'end': 215, 'text': 'Stock Level', 'document_ids': ['query_product_catalog:1:0']} {'start': 238, 'end': 248, 'text': 'Smartphone', 'document_ids': ['query_product_catalog:1:0']} {'start': 251, 'end': 254, 'text': '500', 'document_ids': ['query_product_catalog:1:0']} {'start': 257, 'end': 262, 'text': 'E1001', 'document_ids': ['query_product_catalog:1:0']} {'start': 265, 'end': 267, 'text': '20', 'document_ids': ['query_product_catalog:1:0']} {'start': 272, 'end': 278, 'text': 'Laptop', 'document_ids': ['query_product_catalog:1:0']} {'start': 281, 'end': 285, 'text': '1000', 'document_ids': ['query_product_catalog:1:0']} {'start': 288, 'end': 293, 'text': 'E1002', 'document_ids': ['query_product_catalog:1:0']} {'start': 296, 'end': 298, 'text': '15', 'document_ids': ['query_product_catalog:1:0']} {'start': 303, 'end': 309, 'text': 'Tablet', 'document_ids': ['query_product_catalog:1:0']} {'start': 312, 'end': 315, 'text': '300', 'document_ids': ['query_product_catalog:1:0']} {'start': 318, 'end': 323, 'text': 'E1003', 'document_ids': ['query_product_catalog:1:0']} {'start': 326, 'end': 328, 'text': '25', 'document_ids': ['query_product_catalog:1:0']} ``` -------------------------------- ### Install Libraries Source: https://docs.cohere.com/page/retrieval-eval-pydantic-ai Installs the necessary Python libraries for the tutorial: cohere and pydantic-ai. ```python %pip install -U cohere pydantic-ai ``` -------------------------------- ### Get Finetuned Model with TypeScript SDK (async/await) Source: https://docs.cohere.com/reference/getfinetunedmodel An example demonstrating how to get a finetuned model using the Cohere TypeScript SDK with async/await syntax. Remember to replace 'YOUR_TOKEN_HERE' with your actual token. ```typescript import { CohereClient } from "cohere-ai"; async function main() { const client = new CohereClient({ token: "YOUR_TOKEN_HERE", clientName: "my-cool-project", }); await client.finetuning.getFinetunedModel("id"); } main(); ``` -------------------------------- ### Initialize SemanticSimilarityExampleSelector Source: https://docs.cohere.com/page/sql-agent-cohere-langchain Set up an example selector using Cohere embeddings and FAISS for efficient similarity search. This allows the agent to dynamically select relevant examples based on the input query. ```python example_selector = SemanticSimilarityExampleSelector.from_examples( examples, CohereEmbeddings( cohere_api_key=os.getenv("COHERE_API_KEY"), model="embed-v4.0" ), FAISS, k=5, input_keys=["input"], ) ``` -------------------------------- ### List Training Step Metrics via HTTP GET Request (C#) Source: https://docs.cohere.com/reference/listtrainingstepmetrics Example using RestSharp in C# to perform a GET request for training step metrics. Set the 'X-Client-Name' and 'Authorization' headers. ```csharp using RestSharp; var client = new RestClient("https://api.cohere.com/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics"); var request = new RestRequest(Method.GET); request.AddHeader("X-Client-Name", "my-cool-project"); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Install Required Libraries Source: https://docs.cohere.com/page/sql-agent-cohere-langchain Install the necessary Python packages for LangChain, Cohere integration, and vector storage. The -qq flag suppresses most output. ```bash ! pip install langchain-core langchain-cohere langchain-community faiss-cpu -qq ``` -------------------------------- ### List Finetuning Events via HTTP Request (Swift) Source: https://docs.cohere.com/reference/listevents Swift example using URLSession to make a GET request for finetuning events. It shows how to configure request headers including authorization and client name. ```swift import Foundation let headers = [ "X-Client-Name": "my-cool-project", "Authorization": "Bearer " ] let request = NSMutableURLRequest(url: NSURL(string: "https://api.cohere.com/v1/finetuning/finetuned-models/finetuned_model_id/events")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Get Finetuned Model with Python SDK (Specific ID) Source: https://docs.cohere.com/reference/getfinetunedmodel Example of getting a finetuned model by a specific ID using the Cohere Python SDK. Ensure you replace 'YOUR_TOKEN_HERE' and 'id' with your actual values. ```python from cohere import Client client = Client( token="YOUR_TOKEN_HERE", client_name="my-cool-project", ) client.finetuning.get_finetuned_model( id="id", ) ``` -------------------------------- ### Install OpenAI SDK Source: https://docs.cohere.com/docs/compatibility-api Install the OpenAI SDK using pip. This is the first step to using the Compatibility API. ```bash $| pip install openai ---|--- ``` -------------------------------- ### Python Setup for Grounded Summarization Source: https://docs.cohere.com/page/grounded-summarization Imports necessary libraries and initializes the Cohere client. Requires user input for the API key. ```python %%capture import cohere import networkx as nx import nltk nltk.download("punkt") from nltk.tokenize import sent_tokenize import numpy as np import spacy from collections import deque from getpass import getpass import re from typing import List, Tuple co_api_key = getpass("Enter your Cohere API key: ") co_model = "command-a-03-2025" co = cohere.Client(co_api_key) ``` -------------------------------- ### Get Dataset via HTTP Request (Swift) Source: https://docs.cohere.com/reference/get-dataset Fetch dataset details by making an HTTP GET request using Swift's URLSession. This example configures necessary headers for authentication and client identification. ```swift import Foundation let headers = [ "X-Client-Name": "my-cool-project", "Authorization": "Bearer " ] let request = NSMutableURLRequest(url: NSURL(string: "https://api.cohere.com/v1/datasets/id")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Example Prompt with Instructions and Output Format Source: https://docs.cohere.com/docs/crafting-effective-prompts This snippet shows how to instruct an LLM to summarize an article and format the output using bullet points. ```text ## Instructions Below there is a long form news article discussing the 1972 Canada–USSR Summit Series, an eight-game ice hockey series between the Soviet Union and Canada, held in September 1972. Please summarize the salient points of the text and do so in a flowing high natural language quality text. Use bullet points where appropriate. ## Example Output High level summary: 3 important events related to the series: * * * ## News Article {news_article} ``` -------------------------------- ### Get Finetuned Model (Python SDK) Source: https://docs.cohere.com/reference/getfinetunedmodel Example of how to retrieve a fine-tuned model using the Cohere Python SDK. ```APIDOC ## Get Finetuned Model (Python SDK) ### Description Retrieves details about a specific fine-tuned model using the Cohere Python SDK. ### Method ```python co.finetuning.get_finetuned_model("test-id") ``` ### Parameters - **id** (string) - Required - The ID of the fine-tuned model to retrieve. ``` -------------------------------- ### Example Prompt for JSON Output Source: https://docs.cohere.com/docs/crafting-effective-prompts Demonstrates how to request structured output in JSON format for a summary and key events. ```text Output the summary in the following JSON format: { "short_summary": "", "most_important_events": [ "", "", "" ] } ``` -------------------------------- ### Get Finetuned Model (TypeScript SDK) Source: https://docs.cohere.com/reference/getfinetunedmodel Example of how to retrieve a fine-tuned model using the Cohere TypeScript SDK. ```APIDOC ## Get Finetuned Model (TypeScript SDK) ### Description Retrieves details about a specific fine-tuned model using the Cohere TypeScript SDK. ### Method ```typescript await cohere.finetuning.getFinetunedModel('test-id'); ``` ### Parameters - **id** (string) - Required - The ID of the fine-tuned model to retrieve. ``` -------------------------------- ### Installing Weaviate Client Source: https://docs.cohere.com/docs/weaviate-and-cohere Installs the Weaviate Python client library. The '-q' flag suppresses verbose output during installation. ```python !pip install -U weaviate-client -q ``` -------------------------------- ### Get Finetuned Model (Go SDK) Source: https://docs.cohere.com/reference/getfinetunedmodel Example of how to retrieve a fine-tuned model using the Cohere Go SDK. ```APIDOC ## Get Finetuned Model (Go SDK) ### Description Retrieves details about a specific fine-tuned model using the Cohere Go SDK. ### Method ```go co.Finetuning.GetFinetunedModel(context.TODO(), "test-id") ``` ### Parameters - **id** (string) - Required - The ID of the fine-tuned model to retrieve. ``` -------------------------------- ### Install Cohere Library Source: https://docs.cohere.com/docs/generating-multi-faceted-queries Installs the cohere library for use in your project. The '-qq' flag suppresses most output. ```python ! pip install cohere -qq ``` -------------------------------- ### Get Finetuned Model (Java SDK) Source: https://docs.cohere.com/reference/getfinetunedmodel Example of how to retrieve a fine-tuned model using the Cohere Java SDK. ```APIDOC ## Get Finetuned Model (Java SDK) ### Description Retrieves details about a specific fine-tuned model using the Cohere Java SDK. ### Method ```java cohere.finetuning().getFinetunedModel("test-id"); ``` ### Parameters - **id** (string) - Required - The ID of the fine-tuned model to retrieve. ``` -------------------------------- ### List Finetuning Events with Cohere Go SDK Source: https://docs.cohere.com/reference/listevents Retrieve finetuning events using the Cohere Go SDK. This example requires setting the CO_API_KEY environment variable and uses a context for the request. ```go package main import ( "context" "log" "os" "github.com/cohere-ai/cohere-go/v2/client" ) func main() { co := client.NewClient(client.WithToken(os.Getenv("CO_API_KEY"))) resp, err := co.Finetuning.ListEvents( context.TODO(), "test-finetuned-model-id", nil, ) if err != nil { log.Fatal(err) } log.Printf("%+v", resp.Events) } ``` -------------------------------- ### Get Embed Job (HTTP Request - Swift) Source: https://docs.cohere.com/reference/get-embed-job Perform an HTTP GET request using Swift's URLSession to fetch embed job details. This example configures request headers for client name and authorization. ```swift import Foundation let headers = [ "X-Client-Name": "my-cool-project", "Authorization": "Bearer " ] let request = NSMutableURLRequest(url: NSURL(string: "https://api.cohere.com/v1/embed-jobs/id")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### List Training Step Metrics via HTTP GET Request (Swift) Source: https://docs.cohere.com/reference/listtrainingstepmetrics Swift code for making an HTTP GET request to retrieve training step metrics. Includes URL session setup and header configuration. ```swift import Foundation let headers = [ "X-Client-Name": "my-cool-project", "Authorization": "Bearer " ] let request = NSMutableURLRequest(url: NSURL(string: "https://api.cohere.com/v1/finetuning/finetuned-models/finetuned_model_id/training-step-metrics")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Initialize and Prepare for Recommendations Source: https://docs.cohere.com/page/article-recommender-with-text-embeddings This snippet initializes variables and prepares the input DataFrame for the recommendation process. It copies the DataFrame, shortens the text in the 'Text' column, and defines the get_recommendations function. ```python SHOW_TOP = 5 df_inputs = df_inputs.copy() df_inputs['Text'] = df_inputs['Text'].apply(shorten_text) def get_recommendations(reading_idx,similarity,show_top): # Show the current article print('------ You are reading... ------') print(f'[ID {READING_IDX}] Article:',df_inputs['Text'][reading_idx][:MAX_CHARS]+'... ') # Show the recommended articles print('------ You might also like... ------') # Classify the target article target_class = classify_text([df_inputs['Text'][reading_idx]],examples) print(target_class) count = 0 for idx,score in similarity: # Classify each candidate article candidate_class = classify_text([df_inputs['Text'][idx]],examples) # Show recommendations ```