<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="atom.xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://opensource.salesforce.com/einstein-platform</id>
    <title>Einstein Platform Cookbook Blog</title>
    <updated>2024-09-09T00:00:00.000Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="alternate" href="https://opensource.salesforce.com/einstein-platform"/>
    <subtitle>Einstein Platform Cookbook Blog</subtitle>
    <icon>https://opensource.salesforce.com/einstein-platform/img/favicon.ico</icon>
    <entry>
        <title type="html"><![CDATA[About the Cookbook 📖]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/about</id>
        <link href="https://opensource.salesforce.com/einstein-platform/about"/>
        <updated>2024-09-09T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[The Einstein Platform Cookbook is where Salesforce shares example code and recipes for building with the Einstein Platform. This website is generated based on the contents of the open source einstein-platform repository on GitHub.]]></summary>
        <content type="html"><![CDATA[<p>The <a href="https://opensource.salesforce.com/einstein-platform/" target="_blank" rel="noopener noreferrer">Einstein Platform Cookbook</a> is where Salesforce shares example code and recipes for building with the Einstein Platform. This website is generated based on the contents of the open source <a href="https://github.com/salesforce/einstein-platform" target="_blank" rel="noopener noreferrer">einstein-platform</a> repository on GitHub.</p>
<p>Our first batch of recipes have arrived! These recipes include step-by-step instructions for implementing the LLM Open Connector (<a href="https://github.com/salesforce/einstein-platform?tab=readme-ov-file#llm-open-connector" target="_blank" rel="noopener noreferrer">readme</a>, <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">spec</a>) with an API gateway, and each recipe features a different AI platform. More recipes are in the works featuring new AI platforms and system architectures!</p>
<p>Your contributions to the Cookbook and the open-source repository are welcome! Refer to the <a href="https://github.com/salesforce/einstein-platform/blob/main/CONTRIBUTING.md" target="_blank" rel="noopener noreferrer">Contributing Guide</a> and <a href="https://github.com/salesforce/einstein-platform/blob/main/CODE_OF_CONDUCT.md" target="_blank" rel="noopener noreferrer">Code of Conduct</a> to get started.</p>
<p>If you like the resources that you see here, consider adding a ⭐ on GitHub. It helps other people discover them!</p>
<p>See Also:</p>
<ul>
<li><a href="https://developer.salesforce.com/docs/einstein/genai/overview" target="_blank" rel="noopener noreferrer">Generative AI Developer Guide</a></li>
<li><a href="https://github.com/salesforce/einstein-platform" target="_blank" rel="noopener noreferrer">Einstein Platform GitHub Repo</a></li>
</ul>]]></content>
        <category label="welcome" term="welcome"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[Introducing the LLM Open Connector]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/open-connector</id>
        <link href="https://opensource.salesforce.com/einstein-platform/open-connector"/>
        <updated>2024-09-10T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[The LLM Open Connector is an API specification, closely based on the OpenAI API, that lets you create API gateways and proxy servers that connect any language model to the Einstein AI Platform. Any service that implements the API specification can be connected to Einstein Studio using the Bring Your Own LLM (BYOLLM) feature.]]></summary>
        <content type="html"><![CDATA[<p>The LLM Open Connector is an <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">API specification</a>, closely based on the OpenAI API, that lets you create API gateways and proxy servers that connect any language model to the Einstein AI Platform. Any service that implements the API specification can be connected to Einstein Studio using the Bring Your Own LLM (BYOLLM) feature.</p>
<p>The LLM Open Connector opens up a world of possibilities for bespoke AI applications for Salesforce customers and independent software vendors (ISVs). Check out our recipes to learn how to bring new models to Einstein Studio!</p>]]></content>
        <author>
            <name>Darvish</name>
            <uri>https://github.com/dshadravan</uri>
        </author>
        <author>
            <name>Oleksandr</name>
            <uri>https://github.com/oleksm</uri>
        </author>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + Hugging Face]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/huggingface</id>
        <link href="https://opensource.salesforce.com/einstein-platform/huggingface"/>
        <updated>2024-09-12T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector with the Hugging Face Serverless Inference API for LLM models that support Chat Completion. We also cover how to implement and deploy the connector as a Node.js app on Heroku.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> with the Hugging Face <a href="https://huggingface.co/docs/api-inference/index" target="_blank" rel="noopener noreferrer">Serverless Inference API</a> for LLM models that support <a href="https://huggingface.co/docs/api-inference/en/tasks/chat-completion" target="_blank" rel="noopener noreferrer">Chat Completion</a>. We also cover how to implement and deploy the connector as a Node.js app on Heroku.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/huggingface#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<p>Before you begin, make sure that your local environment meets these prerequisites:</p>
<ol>
<li>Node.js and npm are installed on your local machine.</li>
<li>You have a Heroku account. (Sign up at <a href="https://signup.heroku.com/" target="_blank" rel="noopener noreferrer">https://signup.heroku.com/</a>.)</li>
<li>Heroku CLI is installed on your local machine (<a href="https://devcenter.heroku.com/articles/heroku-cli" target="_blank" rel="noopener noreferrer">https://devcenter.heroku.com/articles/heroku-cli</a>).</li>
<li>Git is installed on your local machine.</li>
<li>You have a Hugging Face account with an API key (<a href="https://huggingface.co/docs/hub/en/security-tokens" target="_blank" rel="noopener noreferrer">https://huggingface.co/docs/hub/en/security-tokens</a>).</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="tutorial-video">Tutorial Video<a href="https://opensource.salesforce.com/einstein-platform/huggingface#tutorial-video" class="hash-link" aria-label="Direct link to Tutorial Video" title="Direct link to Tutorial Video">​</a></h2>
<p>View a walkthrough on using any LLM with the Open Connector on the <a href="https://www.youtube.com/@SalesforceDevs" target="_blank" rel="noopener noreferrer">Salesforce Developers</a> channel:</p>
<div style="width:640px;height:360px"></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="set-up-your-local-environment">Set Up Your Local Environment<a href="https://opensource.salesforce.com/einstein-platform/huggingface#set-up-your-local-environment" class="hash-link" aria-label="Direct link to Set Up Your Local Environment" title="Direct link to Set Up Your Local Environment">​</a></h2>
<ol>
<li>
<p>Clone the einstein-platform repository to your local environment.</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"> git clone https://github.com/salesforce/einstein-platform.git</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Create a directory for your project:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">mkdir llm-open-connector-hf</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">cd llm-open-connector-hf</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Locate the source files specific to Hugging Face connector. In the local <code>einstein-platform</code> project directory you cloned in step 1, navigate to the <code>documentation/cookbook-assets/llm-open-connector-huggingface</code> folder. Copy all the files in this folder.</p>
</li>
<li>
<p>Paste the <code>llm-open-connector-huggingface</code> files into the <code>llm-open-connector-hf</code> directory you created in step 2.</p>
</li>
<li>
<p>Install the required dependencies.</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">npm install</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="project-structure">Project Structure<a href="https://opensource.salesforce.com/einstein-platform/huggingface#project-structure" class="hash-link" aria-label="Direct link to Project Structure" title="Direct link to Project Structure">​</a></h2>
<p>This section outlines the folder structure of the <code>llm-open-connector-hf</code> directory.</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain"> llm-open-connector-hf/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── config/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> │   └── index.js</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── controllers/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> │   └── chatController.js</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── middleware/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> │   └── index.js</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── routes/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> │   └── chat.js</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── utils/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> │   └── logger.js</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── .gitignore</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── .prettierrc</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── index.js</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> ├── package.json</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> └── Procfile</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="project-description">Project Description<a href="https://opensource.salesforce.com/einstein-platform/huggingface#project-description" class="hash-link" aria-label="Direct link to Project Description" title="Direct link to Project Description">​</a></h3>
<p>The following list provides a functional overview of each folder and file in the <code>llm-open-connector-hf</code> directory.</p>
<ul>
<li><code>config/</code>: Holds configuration settings.<!-- -->
<ul>
<li><code>index.js</code>: Exports configuration options for different environments.</li>
</ul>
</li>
<li><code>controllers/</code>: Manages the request handling logic for the chat API.<!-- -->
<ul>
<li><code>chatController.js</code>: Calls the chat completion API.</li>
</ul>
</li>
<li><code>middleware/</code>: Contains custom middleware functions.<!-- -->
<ul>
<li><code>index.js</code>: Includes functions for API key validation and error handling.</li>
</ul>
</li>
<li><code>routes/</code>: Defines API routes.<!-- -->
<ul>
<li><code>chat.js</code>: Contains endpoints for chat completion functionality.</li>
</ul>
</li>
<li><code>utils/</code>: Utility functions for support tasks.<!-- -->
<ul>
<li><code>logger.js</code>: A custom logger with data sanitization for secure logging.</li>
</ul>
</li>
<li><code>.gitignore</code>: Lists files and directories that are ignored by Git, such as <code>node_modules</code> and sensitive files.</li>
<li><code>.prettierrc</code>: The configuration file for Prettier, which enforces consistent code formatting across the project.</li>
<li><code>index.js</code>: The main application file that initializes the server and routes.</li>
<li><code>package.json</code>: Contains metadata for the project and manages dependencies, scripts, and configurations.</li>
<li><code>Procfile</code>: Specifies process types and commands for deploying the app on platforms like Heroku.</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="configure-your-local-environment">Configure Your Local Environment<a href="https://opensource.salesforce.com/einstein-platform/huggingface#configure-your-local-environment" class="hash-link" aria-label="Direct link to Configure Your Local Environment" title="Direct link to Configure Your Local Environment">​</a></h2>
<ol>
<li>
<p>Create a <code>.env</code> file in the root directory of the project and add these variables:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">PORT=3000</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">HUGGING_FACE_API_KEY=your_hugging_face_api_key</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">HUGGING_FACE_API_URL=https://api-inference.huggingface.co/models</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">USE_THIRD_PARTY_ROUTER=false</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">ALLOWED_ORIGINS=http://localhost:3000,https://your-salesforce-domain.com</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your_hugging_face_api_key</code> with your own Hugging Face API key and adjust the <code>ALLOWED_ORIGINS</code> as needed. Change <code>ALLOWED_ORIGINS</code> to allowlist your Salesforce domain.</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>The <code>HUGGING_FACE_API_URL</code> and <code>USE_THIRD_PARTY_ROUTER</code> configuration options are important when using third-party routers like Together AI.</p></div></div>
<ul>
<li>For standard Hugging Face models, use <code>HUGGING_FACE_API_URL=https://api-inference.huggingface.co</code> and <code>USE_THIRD_PARTY_ROUTER=false</code>.</li>
<li>For third-party routers (e.g. Together AI), use <code>HUGGING_FACE_API_URL=https://router.huggingface.co/together/v1/chat/completions</code> and <code>USE_THIRD_PARTY_ROUTER=true</code>.</li>
</ul>
</li>
<li>
<p>Make sure your <code>.gitignore</code> file includes the <code>.env</code> file to avoid accidentally committing sensitive information.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="test-your-application-locally">Test Your Application Locally<a href="https://opensource.salesforce.com/einstein-platform/huggingface#test-your-application-locally" class="hash-link" aria-label="Direct link to Test Your Application Locally" title="Direct link to Test Your Application Locally">​</a></h2>
<ol>
<li>
<p>Run your Node.js application locally:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">npm start</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>The server starts on the port specified in your <code>.env</code> file. The default port is 3000.</p>
</li>
<li>
<p>Test the endpoints using a tool like cURL or Postman to ensure they're working correctly. Here are two examples:</p>
<p>a. Using a standard Hugging Face model (Mixtral):</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">curl -X POST http://localhost:3000/chat/completions \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H 'Content-Type: application/json' \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H 'api-key: &lt;use your HuggingFace access token here&gt;' \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-d '{</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "model": "mistralai/Mixtral-8x7B-Instruct-v0.1",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "messages": [</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "content": "What is the capital of Italy?",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "role": "user"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "max_tokens": 100,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "temperature": 0.7,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "n": 2,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "parameters": {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    "top_p": 0.9</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>b. Using Qwen through Together AI (requires setting <code>HUGGING_FACE_API_URL=https://router.huggingface.co/together/v1/chat/completions</code> and <code>USE_THIRD_PARTY_ROUTER=true</code>):</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">curl -X POST http://localhost:3000/chat/completions \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H 'Content-Type: application/json' \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H 'api-key: &lt;use your Together AI access token here&gt;' \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-d '{</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "model": "Qwen/Qwen2.5-7B-Instruct-Turbo",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "messages": [</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "content": "What is the capital of Italy?",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "role": "user"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "max_tokens": 100,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "temperature": 0.7,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "n": 2,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "parameters": {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    "top_p": 0.9</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prepare-for-heroku-deployment">Prepare for Heroku Deployment<a href="https://opensource.salesforce.com/einstein-platform/huggingface#prepare-for-heroku-deployment" class="hash-link" aria-label="Direct link to Prepare for Heroku Deployment" title="Direct link to Prepare for Heroku Deployment">​</a></h2>
<ol>
<li>
<p>Initialize a Git repository in your project directory:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git init</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Add your files to the repository:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git add .</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Commit your changes:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git commit -m "Initial commit"</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="update-your-default-branch">Update Your Default Branch<a href="https://opensource.salesforce.com/einstein-platform/huggingface#update-your-default-branch" class="hash-link" aria-label="Direct link to Update Your Default Branch" title="Direct link to Update Your Default Branch">​</a></h2>
<p>To switch the default branch used to deploy apps from <code>master</code> to <code>main</code>, follow these steps:</p>
<ol>
<li>
<p>Create a branch locally:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git checkout -b main</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Delete the old default branch locally:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git branch -D master</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Now, the local environment only knows about the <code>main</code> branch.</p>
</li>
<li>
<p>Reset the git repository on the Heroku Platform:</p>
<ul>
<li>
<p>Use the <code>heroku-reset</code> command from the <code>heroku-repo</code> CLI plugin. This command does not impact the running application.</p>
</li>
</ul>
<div class="theme-admonition theme-admonition-important admonition_xJq3 alert alert--info"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg></span>important</div><div class="admonitionContent_BuS1"><p>Communicate this change with your team. If other developers are unaware of the reset and push to <code>master</code>, the reset will be overwritten.</p></div></div>
</li>
<li>
<p>To switch the default branch in GitHub, refer to this article: <a href="https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch" target="_blank" rel="noopener noreferrer">Setting the Default Branch</a>.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="deploy-to-heroku">Deploy to Heroku<a href="https://opensource.salesforce.com/einstein-platform/huggingface#deploy-to-heroku" class="hash-link" aria-label="Direct link to Deploy to Heroku" title="Direct link to Deploy to Heroku">​</a></h2>
<ol>
<li>
<p>Login to the Heroku CLI:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku login</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Create a Heroku app:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku create your-app-name</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your-app-name</code> with a unique name for your application.</p>
</li>
<li>
<p>Set the API_KEY config var on Heroku:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku config:set HUGGING_FACE_API_KEY=your_api_key_here -a your-app-name</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your_api_key_here</code> with your own API key.</p>
</li>
<li>
<p>Set the ALLOWED_ORIGINS config var on Heroku:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku config:set ALLOWED_ORIGINS=your_salesforce_domain_here -a your-app-name</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your_salesforce_domain_here</code> with your own Salesforce domain.</p>
</li>
<li>
<p>Deploy your app to Heroku:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git push heroku main</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="test-your-deployed-application">Test Your Deployed Application<a href="https://opensource.salesforce.com/einstein-platform/huggingface#test-your-deployed-application" class="hash-link" aria-label="Direct link to Test Your Deployed Application" title="Direct link to Test Your Deployed Application">​</a></h2>
<p>You can test your deployed application using the deployed API endpoint. Use a tool like cURL or Postman to test the endpoints of your Node.js app:</p>
<ul>
<li>Chat Completions: <code>POST https://your-app-name.herokuapp.com/chat/completions</code></li>
</ul>
<p>To test the <code>chat/completions</code> endpoint with cURL, run this command:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">curl -X POST https://still-beach-80840-58cbb07ae5f4.herokuapp.com/chat/completions \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H 'Content-Type: application/json' \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H 'api-key: &lt;use your HuggingFace access token here&gt;' \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-d '{</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "model": "mistralai/Mixtral-8x7B-Instruct-v0.1",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "messages": [</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "content": "What is the capital of Italy?",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "role": "user"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "max_tokens": 100,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "temperature": 0.7,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "n": 2,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "parameters": {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    "top_p": 0.9</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="bring-your-connected-endpoint-to-salesforce-model-builder">Bring Your Connected Endpoint to Salesforce Model Builder<a href="https://opensource.salesforce.com/einstein-platform/huggingface#bring-your-connected-endpoint-to-salesforce-model-builder" class="hash-link" aria-label="Direct link to Bring Your Connected Endpoint to Salesforce Model Builder" title="Direct link to Bring Your Connected Endpoint to Salesforce Model Builder">​</a></h2>
<p>Follow the instructions in <a href="https://developer.salesforce.com/blogs/2024/10/build-generative-ai-solutions-with-llm-open-connector" target="_blank" rel="noopener noreferrer">this developer blog</a> to use your model in Model Builder. When you activate your model, you can use it within <a href="https://developer.salesforce.com/docs/einstein/genai/guide/get-started-prompt-builder.html" target="_blank" rel="noopener noreferrer">Prompt Builder</a>, the <a href="https://developer.salesforce.com/docs/einstein/genai/guide/models-api.html" target="_blank" rel="noopener noreferrer">Models API</a>, and for building actions using prompt templates in Agent Builder. All these methods provide built-in security offered by the <a href="https://help.salesforce.com/s/articleView?id=sf.generative_ai_trust_layer.htm&amp;type=5" target="_blank" rel="noopener noreferrer">Einstein Trust Layer</a>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="current-features">Current Features<a href="https://opensource.salesforce.com/einstein-platform/huggingface#current-features" class="hash-link" aria-label="Direct link to Current Features" title="Direct link to Current Features">​</a></h2>
<p>The following list outlines the features included in this recipe:</p>
<ul>
<li>Integration with the <a href="https://huggingface.co/docs/api-inference/index" target="_blank" rel="noopener noreferrer">Hugging Face</a> Serverless Inference API for <a href="https://huggingface.co/docs/api-inference/en/tasks/chat-completion" target="_blank" rel="noopener noreferrer">models</a> that support Chat Completion</li>
<li>Express server with advanced security configurations</li>
<li>CORS configuration with customizable allowed origins</li>
<li>Rate limiting to prevent abuse</li>
<li>API key validation for protected routes</li>
<li>Comprehensive error handling and sanitized logging</li>
<li>Helmet.js integration for enhanced security headers</li>
<li>Chat completion controller with input validation and response reshaping</li>
<li>Optimized message processing:<!-- -->
<ul>
<li>Concatenates multiple system messages into a single message as required by some LLMs</li>
<li>Preserves the order of user and assistant messages</li>
</ul>
</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="api-endpoints">API Endpoints<a href="https://opensource.salesforce.com/einstein-platform/huggingface#api-endpoints" class="hash-link" aria-label="Direct link to API Endpoints" title="Direct link to API Endpoints">​</a></h2>
<ul>
<li>POST <code>/chat/completions</code>: Send a chat message and receive an AI-generated response.<!-- -->
<ul>
<li>The endpoint optimizes message processing by concatenating system messages.</li>
<li>The following example provides two system messages:<!-- -->
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"messages"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"system"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"You are a helpful assistant."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"system"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Always be polite."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Hello!"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"assistant"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Hi there!"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"How are you?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"model"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"gpt-3.5-turbo"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"max_tokens"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">150</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>The API processes the system messages into:<!-- -->
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"messages"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"system"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"You are a helpful assistant.\nAlways be polite."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Hello!"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"assistant"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Hi there!"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"How are you?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"model"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"gpt-3.5-turbo"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"max_tokens"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">150</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ul>
</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="current-security-measures">Current Security Measures<a href="https://opensource.salesforce.com/einstein-platform/huggingface#current-security-measures" class="hash-link" aria-label="Direct link to Current Security Measures" title="Direct link to Current Security Measures">​</a></h2>
<p>The recipe's security measures include a Helmet.js configuration, a CORS configuration, rate limiting, API key validation, and sanitized logging.</p>
<p>The following list briefly highlights the current security measures:</p>
<ul>
<li>A Helmet.js configuration with strict security settings:<!-- -->
<ul>
<li>Content Security Policy (CSP) with restrictive directives</li>
<li>Cross-Origin Embedder Policy</li>
<li>Cross-Origin Opener Policy</li>
<li>Cross-Origin Resource Policy</li>
<li>DNS Prefetch Control</li>
<li>Expect-CT header</li>
<li>Frameguard to prevent clickjacking</li>
<li>HTTP Strict Transport Security (HSTS)</li>
<li>IE No Open</li>
<li>X-Content-Type-Options nosniff</li>
<li>Origin-Agent-Cluster header</li>
<li>Permitted Cross-Domain Policies</li>
<li>Referrer-Policy</li>
<li>X-XSS-Protection</li>
</ul>
</li>
<li>A CORS configuration restricts allowed origins.</li>
<li>Rate limits: 100 requests per 15 minutes per IP.</li>
<li>API key validation provides protected routes.</li>
<li>Sanitized logging prevents accidental exposure of sensitive data.</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="important-considerations">Important Considerations<a href="https://opensource.salesforce.com/einstein-platform/huggingface#important-considerations" class="hash-link" aria-label="Direct link to Important Considerations" title="Direct link to Important Considerations">​</a></h2>
<ol>
<li>This cookbook uses the <code>mistralai/Mixtral-8x7B-Instruct-v0.1</code> model in the example cURL requests. You can replace it with any supported model. For a list of supported model IDs, see <a href="https://huggingface.co/docs/api-inference/en/tasks/chat-completion" target="_blank" rel="noopener noreferrer">Hugging Face Chat Completion</a>.</li>
<li>Monitor your usage to manage costs, especially if you expect high traffic.</li>
<li>Error handling and input validation must be improved for production use.</li>
<li>Consider implementing further security measures for production use.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a href="https://opensource.salesforce.com/einstein-platform/huggingface#conclusion" class="hash-link" aria-label="Direct link to Conclusion" title="Direct link to Conclusion">​</a></h2>
<p>This cookbook demonstrates how to set up an LLM Open Connector using Hugging Face Serverless API for Chat Completion endpoints for various models. For production purposes, remember to use Hugging Face's dedicated <a href="https://ui.endpoints.huggingface.co/" target="_blank" rel="noopener noreferrer">Interference Endpoints</a> feature. Always optimize your implementation based on your specific requirements and expected usage patterns.</p>]]></content>
        <author>
            <name>Mohith</name>
            <uri>https://github.com/msrivastav13</uri>
        </author>
        <category label="huggingface" term="huggingface"/>
        <category label="heroku" term="heroku"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + AWS]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/aws</id>
        <link href="https://opensource.salesforce.com/einstein-platform/aws"/>
        <updated>2024-09-13T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector using Amazon Web Services (AWS). We use Amazon Bedrock to host a Llama model from Meta, a Lambda for serverless compute, and an API Gateway to expose our API.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> using Amazon Web Services (AWS). We use Amazon Bedrock to host a Llama model from Meta, a Lambda for serverless compute, and an API Gateway to expose our API.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/aws#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<ol>
<li>AWS Account with appropriate permissions</li>
<li>AWS CLI. For installation instructions, see <a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html" target="_blank" rel="noopener noreferrer">Install or update to the latest version of the AWS CLI</a> and <a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html" target="_blank" rel="noopener noreferrer">Set up the AWS CLI</a>.</li>
<li>Python 3.9 or later</li>
<li>AWS CDK installed (<code>npm install -g aws-cdk</code>)</li>
<li>Access to AWS Bedrock (you may need to request access if it's not enabled in your account)</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="set-up-aws-bedrock-and-model-access">Set Up AWS Bedrock and Model Access<a href="https://opensource.salesforce.com/einstein-platform/aws#set-up-aws-bedrock-and-model-access" class="hash-link" aria-label="Direct link to Set Up AWS Bedrock and Model Access" title="Direct link to Set Up AWS Bedrock and Model Access">​</a></h2>
<p>Before deploying and using the LLM Open Connector, you need to set up access to AWS Bedrock and enable the specific model you want to use. Follow these steps:</p>
<p><strong>Enable AWS Bedrock:</strong></p>
<ul>
<li>Go to the <a href="https://console.aws.amazon.com/bedrock" target="_blank" rel="noopener noreferrer">AWS Bedrock console</a>.</li>
<li>If you see a "Get started" button, click it to enable Bedrock for your account.</li>
<li>If Bedrock is already enabled, you'll see the Bedrock dashboard.</li>
</ul>
<p><strong>Request access to models:</strong></p>
<ul>
<li>In the Bedrock console, go to "Model access" in the left navigation pane.</li>
<li>Find the model you want to use (for example, Llama 3.1 70B Instruct).</li>
<li>Click the menu (three dots) and select "Request model access".</li>
<li>Verify that the model is selected and click <strong>Next</strong>.</li>
<li>Read and accept the terms and conditions, then click <strong>Submit</strong>.</li>
<li>Wait for your request to be approved. This is usually instant for most models.</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="installation">Installation<a href="https://opensource.salesforce.com/einstein-platform/aws#installation" class="hash-link" aria-label="Direct link to Installation" title="Direct link to Installation">​</a></h2>
<ol>
<li>
<p>Create a new local directory for your project and navigate to it:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">mkdir aws-bedrock-llama-connector</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">cd aws-bedrock-llama-connector</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Download from the einstein-platform repository:</p>
<ul>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-aws/lib/aws_bedrock_llama_connector_stack.py" target="_blank" rel="noopener noreferrer">lib/aws_bedrock_llama_connector_stack.py</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-aws/lambda/handler.py" target="_blank" rel="noopener noreferrer">lambda/handler.py</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-aws/app.py" target="_blank" rel="noopener noreferrer">app.py</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-aws/cdk.json" target="_blank" rel="noopener noreferrer">cdk.json</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-aws/index.html" target="_blank" rel="noopener noreferrer">index.html</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-aws/requirements.txt" target="_blank" rel="noopener noreferrer">requirements.txt</a></li>
</ul>
</li>
<li>
<p>Copy the downloaded files into your project directory.</p>
</li>
<li>
<p>Create a virtual environment and install Python dependencies:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">python -m venv venv</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">source venv/bin/activate  # On Windows, use `venv\Scripts\activate`</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">pip install -r requirements.txt</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="project-structure">Project Structure<a href="https://opensource.salesforce.com/einstein-platform/aws#project-structure" class="hash-link" aria-label="Direct link to Project Structure" title="Direct link to Project Structure">​</a></h2>
<p>Your project structure should now look like this:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">aws-bedrock-llama-connector/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">├── lib/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">│   └── aws_bedrock_llama_connector_stack.py</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">├── lambda/</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">│   └── handler.py</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">├── app.py</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">├── cdk.json</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">├── index.html</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">└── requirements.txt</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="deployment">Deployment<a href="https://opensource.salesforce.com/einstein-platform/aws#deployment" class="hash-link" aria-label="Direct link to Deployment" title="Direct link to Deployment">​</a></h2>
<ol>
<li>
<p>Configure AWS CLI with your credentials:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">aws configure</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Bootstrap your AWS environment (if you haven't already):</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">cdk bootstrap</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Deploy the stack:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">cdk deploy</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>After deployment, CDK will output the API Gateway URL. You can use this URL to make requests to your Llama model.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="usage">Usage<a href="https://opensource.salesforce.com/einstein-platform/aws#usage" class="hash-link" aria-label="Direct link to Usage" title="Direct link to Usage">​</a></h2>
<p>To use the deployed API, send a POST request to the <code>/chat/completions</code> endpoint with the following JSON structure:</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"messages"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"system"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"You are a helpful assistant."</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Tell me a joke about programming."</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"temperature"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0.7</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>You can use tools like cUrl, Postman, or any programming language to make HTTP requests to your API.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="example-using-curl">Example using cUrl<a href="https://opensource.salesforce.com/einstein-platform/aws#example-using-curl" class="hash-link" aria-label="Direct link to Example using cUrl" title="Direct link to Example using cUrl">​</a></h3>
<p>Here's an example cUrl command to test your API:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">curl -X POST https://your-api-id.execute-api.your-region.amazonaws.com/prod/chat/completions \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H "Content-Type: application/json" \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-d '{</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "messages": [</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {"role": "system", "content": "You are a helpful assistant."},</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {"role": "user", "content": "Tell me a joke about programming."}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "temperature": 0.7</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>https://your-api-id.execute-api.your-region.amazonaws.com/prod</code> with the actual URL of your deployed API Gateway, which you can find in the AWS Console or in the output of the <code>cdk deploy</code> command.</p>
<p>This cUrl command sends a POST request to your API with the specified JSON payload. The API should respond with a JSON object containing the generated text from the Llama model.</p>
<p><strong>Note</strong>: If you're using Windows Command Prompt, you may need to escape the double quotes in the JSON payload differently. For PowerShell or bash on Windows (e.g., Git Bash), the command should work as written above.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="testing-with-a-web-ui">Testing with a Web UI<a href="https://opensource.salesforce.com/einstein-platform/aws#testing-with-a-web-ui" class="hash-link" aria-label="Direct link to Testing with a Web UI" title="Direct link to Testing with a Web UI">​</a></h2>
<p>Use the included <a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-aws/index.html" target="_blank" rel="noopener noreferrer">index.html</a> file to test your API gateway with a web UI.</p>
<p>Before using the web UI, edit the file and replace <code>https://your-api-id.execute-api.your-region.amazonaws.com/prod</code> with the actual URL of your deployed API Gateway, which you can find in the AWS Console or in the output of the <code>cdk deploy</code> command.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="notes">Notes<a href="https://opensource.salesforce.com/einstein-platform/aws#notes" class="hash-link" aria-label="Direct link to Notes" title="Direct link to Notes">​</a></h2>
<ol>
<li>This cookbook uses the <code>meta.llama3-1-70b-instruct-v1:0</code> model as a placeholder. You can replace it with any supported model that you have been granted access to in Amazon Bedrock. For a list of supported model IDs, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html" target="_blank" rel="noopener noreferrer">Amazon Bedrock model IDs</a>.</li>
<li>The token count in the response is set to -1 as AWS Bedrock doesn't provide token usage information. You may need to implement your own token counting logic if required.</li>
<li>Error handling and input validation should be improved for production use.</li>
<li>Consider disabling CORS.</li>
<li>Consider implementing authentication and rate limiting for your API Gateway.</li>
<li>Monitor your AWS usage to manage costs, especially if you expect high traffic.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a href="https://opensource.salesforce.com/einstein-platform/aws#conclusion" class="hash-link" aria-label="Direct link to Conclusion" title="Direct link to Conclusion">​</a></h2>
<p>This cookbook demonstrates how to set up an LLM Open Connector using AWS Bedrock, Lambda, and API Gateway. It provides a serverless, scalable solution for integrating Llama models into your applications. Remember to optimize your implementation based on your specific requirements and expected usage patterns.</p>]]></content>
        <author>
            <name>Richard</name>
            <uri>https://github.com/rsexton404</uri>
        </author>
        <category label="aws" term="aws"/>
        <category label="bedrock" term="bedrock"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + Groq]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/groq</id>
        <link href="https://opensource.salesforce.com/einstein-platform/groq"/>
        <updated>2024-09-14T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector with the Groq platform for fast AI inference. We also cover how to deploy the connector as a Flask app on Heroku with a simple web UI for testing.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> with the <a href="https://groq.com/" target="_blank" rel="noopener noreferrer">Groq</a> platform for fast AI inference. We also cover how to deploy the connector as a Flask app on Heroku with a simple web UI for testing.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/groq#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<p>Before you begin, make sure that your local environment meets these prerequisites.</p>
<ol>
<li>Python 3.9 or later installed on your local machine</li>
<li>A Heroku account (sign up at <a href="https://signup.heroku.com/" target="_blank" rel="noopener noreferrer">https://signup.heroku.com/</a>)</li>
<li>Heroku CLI installed (<a href="https://devcenter.heroku.com/articles/heroku-cli" target="_blank" rel="noopener noreferrer">https://devcenter.heroku.com/articles/heroku-cli</a>)</li>
<li>Git installed on your local machine</li>
<li>A Groq API key (sign up at <a href="https://console.groq.com/" target="_blank" rel="noopener noreferrer">https://console.groq.com/</a>)</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="set-up-your-local-environment">Set Up Your Local Environment<a href="https://opensource.salesforce.com/einstein-platform/groq#set-up-your-local-environment" class="hash-link" aria-label="Direct link to Set Up Your Local Environment" title="Direct link to Set Up Your Local Environment">​</a></h2>
<ol>
<li>
<p>Create a new directory for your project:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">mkdir llm-open-connector</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">cd llm-open-connector</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Create a virtual environment and activate it:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">python -m venv venv</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">source venv/bin/activate  # On Windows, use `venv\Scripts\activate`</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Download these files from the einstein-platform repository:</p>
<ul>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-groq/.gitignore" target="_blank" rel="noopener noreferrer">.gitignore</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-groq/app.py" target="_blank" rel="noopener noreferrer">app.py</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-groq/index.html" target="_blank" rel="noopener noreferrer">index.html</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-groq/Procfile" target="_blank" rel="noopener noreferrer">Procfile</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-groq/requirements.txt" target="_blank" rel="noopener noreferrer">requirements.txt</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-groq/runtime.txt" target="_blank" rel="noopener noreferrer">runtime.txt</a></li>
</ul>
</li>
<li>
<p>Copy the downloaded files into your project directory.</p>
</li>
<li>
<p>Install the required packages:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">pip install -r requirements.txt</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="configure-your-local-environment">Configure Your Local Environment<a href="https://opensource.salesforce.com/einstein-platform/groq#configure-your-local-environment" class="hash-link" aria-label="Direct link to Configure Your Local Environment" title="Direct link to Configure Your Local Environment">​</a></h2>
<ol>
<li>
<p>For local testing, create a <code>.env</code> file in your project directory and add your Groq API key:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">GROQ_API_KEY=your_groq_api_key_here</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your_groq_api_key_here</code> with your actual Groq API key.</p>
</li>
<li>
<p>Make sure your <code>.gitignore</code> file includes the <code>.env</code> file to avoid accidentally committing sensitive information.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="test-your-application-locally">Test Your Application Locally<a href="https://opensource.salesforce.com/einstein-platform/groq#test-your-application-locally" class="hash-link" aria-label="Direct link to Test Your Application Locally" title="Direct link to Test Your Application Locally">​</a></h2>
<ol>
<li>
<p>Run your Flask application:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">python app.py</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Your app should now be running on <code>http://127.0.0.1:5000/</code>.</p>
</li>
<li>
<p>Test the endpoints using a tool like cURL or Postman to ensure they're working correctly.</p>
</li>
</ol>
<p>To test the <code>chat/completions</code> endpoint, run this cURL command:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">curl -X POST http://127.0.0.1:5000/chat/completions \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H "Content-Type: application/json" \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-d '{</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "model": "llama3-8b-8192",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "messages": [</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {"role": "system", "content": "You are a helpful assistant."},</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {"role": "user", "content": "What is the capital of Canada?"}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "max_tokens": 50,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "temperature": 0.7,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "n": 1</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prepare-for-heroku-deployment">Prepare for Heroku Deployment<a href="https://opensource.salesforce.com/einstein-platform/groq#prepare-for-heroku-deployment" class="hash-link" aria-label="Direct link to Prepare for Heroku Deployment" title="Direct link to Prepare for Heroku Deployment">​</a></h2>
<ol>
<li>
<p>Initialize a Git repository in your project directory:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git init</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Add your files to the repository:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git add .</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Commit your changes:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git commit -m "Initial commit"</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="update-your-default-branch">Update Your Default Branch<a href="https://opensource.salesforce.com/einstein-platform/groq#update-your-default-branch" class="hash-link" aria-label="Direct link to Update Your Default Branch" title="Direct link to Update Your Default Branch">​</a></h2>
<p>To switch the default branch used to deploy apps from <code>master</code> to <code>main</code>, follow these steps:</p>
<ol>
<li>
<p>Create a new branch locally:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git checkout -b main</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Delete the old default branch locally:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git branch -D master</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Now, the local environment only knows about the <code>main</code> branch.</p>
</li>
<li>
<p>Reset the git repository on the Heroku Platform:</p>
<ul>
<li>Use the <code>heroku-reset</code> command from the <code>heroku-repo</code> CLI plugin.</li>
<li>This will not impact the running application.</li>
</ul>
<p><strong>Note:</strong> Communicate this change with your team. If other developers are unaware of the reset, they might push to <code>master</code>, overwriting the reset.</p>
</li>
<li>
<p>To switch the default branch in GitHub, refer to this article: <a href="https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch" target="_blank" rel="noopener noreferrer">Setting the Default Branch</a>.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="deploy-to-heroku">Deploy to Heroku<a href="https://opensource.salesforce.com/einstein-platform/groq#deploy-to-heroku" class="hash-link" aria-label="Direct link to Deploy to Heroku" title="Direct link to Deploy to Heroku">​</a></h2>
<ol>
<li>
<p>Make sure you're logged in to the Heroku CLI:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku login</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Create a new Heroku app:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku create your-app-name</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your-app-name</code> with a unique name for your application.</p>
</li>
<li>
<p>Set the GROQ_API_KEY config var on Heroku:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku config:set GROQ_API_KEY=your_groq_api_key_here -a your-app-name</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your_groq_api_key_here</code> with your actual Groq API key.</p>
</li>
<li>
<p>Deploy your app to Heroku:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git push heroku main</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Open your deployed app:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku open</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<p>Your LLM Open Connector should now be deployed and accessible via the Heroku URL.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="test-your-deployed-application">Test Your Deployed Application<a href="https://opensource.salesforce.com/einstein-platform/groq#test-your-deployed-application" class="hash-link" aria-label="Direct link to Test Your Deployed Application" title="Direct link to Test Your Deployed Application">​</a></h2>
<p>You can test your deployed application in two ways:</p>
<ol>
<li>
<p>Using the example UI:</p>
<ul>
<li>Open your browser and navigate to <code>https://your-app-name.herokuapp.com</code></li>
<li>You'll see a simple interface where you can input prompts and get responses from the LLM</li>
<li>Try different prompts and get super fast responses!</li>
</ul>
</li>
<li>
<p>Using API endpoints:
Use a tool like cURL or Postman to test the endpoints of your Flask app:</p>
<ul>
<li>Chat Completions: <code>POST https://your-app-name.herokuapp.com/chat/completions</code></li>
</ul>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a href="https://opensource.salesforce.com/einstein-platform/groq#conclusion" class="hash-link" aria-label="Direct link to Conclusion" title="Direct link to Conclusion">​</a></h2>
<p>You have successfully created and deployed an LLM Open Connector using the Groq API and deployed it to Heroku! This connector adheres to the Salesforce LLM Open Connector API specification, allowing for seamless integration with the Einstein AI Platform using the BYOLLM feature.</p>
<p>With this connector, you can bring new foundation models like Llama 3 into Einstein Studio that take advantage of Groq's fast inference platform.</p>
<p>Remember to monitor your usage and costs associated with the Groq API, and consider implementing additional security measures, such as rate limiting, CORS restrictions, and user authentication, before using this connector in a production environment.</p>]]></content>
        <author>
            <name>Richard</name>
            <uri>https://github.com/rsexton404</uri>
        </author>
        <category label="groq" term="groq"/>
        <category label="heroku" term="heroku"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + SambaNova]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/sambanova</id>
        <link href="https://opensource.salesforce.com/einstein-platform/sambanova"/>
        <updated>2024-09-15T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector with the SambaNova platform for fast AI inference. We also cover how to deploy the connector as a Flask app on Heroku with a simple web UI for testing.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> with the <a href="https://sambanova.ai/" target="_blank" rel="noopener noreferrer">SambaNova</a> platform for fast AI inference. We also cover how to deploy the connector as a Flask app on Heroku with a simple web UI for testing.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/sambanova#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<p>Before you begin, make sure that your local environment meets these prerequisites.</p>
<ol>
<li>Python 3.9 or later installed on your local machine</li>
<li>A Heroku account (sign up at <a href="https://signup.heroku.com/" target="_blank" rel="noopener noreferrer">https://signup.heroku.com/</a>)</li>
<li>Heroku CLI installed (<a href="https://devcenter.heroku.com/articles/heroku-cli" target="_blank" rel="noopener noreferrer">https://devcenter.heroku.com/articles/heroku-cli</a>)</li>
<li>Git installed on your local machine</li>
<li>A SambaNova API key (sign up at <a href="https://sambanova.ai/" target="_blank" rel="noopener noreferrer">https://sambanova.ai/</a>)</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="set-up-your-local-environment">Set Up Your Local Environment<a href="https://opensource.salesforce.com/einstein-platform/sambanova#set-up-your-local-environment" class="hash-link" aria-label="Direct link to Set Up Your Local Environment" title="Direct link to Set Up Your Local Environment">​</a></h2>
<ol>
<li>
<p>Create a new directory for your project:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">mkdir llm-open-connector</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">cd llm-open-connector</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Create a virtual environment and activate it:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">python -m venv venv</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">source venv/bin/activate  # On Windows, use `venv\Scripts\activate`</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Download these files from the einstein-platform repository:</p>
<ul>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-sambanova/.gitignore" target="_blank" rel="noopener noreferrer">.gitignore</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-sambanova/app.py" target="_blank" rel="noopener noreferrer">app.py</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-sambanova/index.html" target="_blank" rel="noopener noreferrer">index.html</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-sambanova/Procfile" target="_blank" rel="noopener noreferrer">Procfile</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-sambanova/requirements.txt" target="_blank" rel="noopener noreferrer">requirements.txt</a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-sambanova/runtime.txt" target="_blank" rel="noopener noreferrer">runtime.txt</a></li>
</ul>
</li>
<li>
<p>Copy the downloaded files into your project directory.</p>
</li>
<li>
<p>Install the required packages:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">pip install -r requirements.txt</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="configure-your-local-environment">Configure Your Local Environment<a href="https://opensource.salesforce.com/einstein-platform/sambanova#configure-your-local-environment" class="hash-link" aria-label="Direct link to Configure Your Local Environment" title="Direct link to Configure Your Local Environment">​</a></h2>
<ol>
<li>
<p>For local testing, create a <code>.env</code> file in your project directory and add your API key:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">API_KEY=your_api_key_here</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your_api_key_here</code> with your actual API key.</p>
</li>
<li>
<p>Make sure your <code>.gitignore</code> file includes the <code>.env</code> file to avoid accidentally committing sensitive information.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="test-your-application-locally">Test Your Application Locally<a href="https://opensource.salesforce.com/einstein-platform/sambanova#test-your-application-locally" class="hash-link" aria-label="Direct link to Test Your Application Locally" title="Direct link to Test Your Application Locally">​</a></h2>
<ol>
<li>
<p>Run your Flask application:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">python app.py</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Your app should now be running on <code>http://127.0.0.1:5000/</code>.</p>
</li>
<li>
<p>Test the endpoints using a tool like cURL or Postman to ensure they're working correctly.</p>
</li>
</ol>
<p>To test the <code>chat/completions</code> endpoint, run this cURL command:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">curl -X POST http://127.0.0.1:5000/chat/completions \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H "Content-Type: application/json" \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-d '{</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "model": "Meta-Llama-3.1-8B-Instruct",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "messages": [</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {"role": "system", "content": "You are a helpful assistant."},</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {"role": "user", "content": "What is the capital of Canada?"}</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "temperature": 0.7,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prepare-for-heroku-deployment">Prepare for Heroku Deployment<a href="https://opensource.salesforce.com/einstein-platform/sambanova#prepare-for-heroku-deployment" class="hash-link" aria-label="Direct link to Prepare for Heroku Deployment" title="Direct link to Prepare for Heroku Deployment">​</a></h2>
<ol>
<li>
<p>Initialize a Git repository in your project directory:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git init</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Add your files to the repository:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git add .</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Commit your changes:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git commit -m "Initial commit"</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="update-your-default-branch">Update Your Default Branch<a href="https://opensource.salesforce.com/einstein-platform/sambanova#update-your-default-branch" class="hash-link" aria-label="Direct link to Update Your Default Branch" title="Direct link to Update Your Default Branch">​</a></h2>
<p>To switch the default branch used to deploy apps from <code>master</code> to <code>main</code>, follow these steps:</p>
<ol>
<li>
<p>Create a new branch locally:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git checkout -b main</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Delete the old default branch locally:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git branch -D master</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Now, the local environment only knows about the <code>main</code> branch.</p>
</li>
<li>
<p>Reset the git repository on the Heroku Platform:</p>
<ul>
<li>Use the <code>heroku-reset</code> command from the <code>heroku-repo</code> CLI plugin.</li>
<li>This will not impact the running application.</li>
</ul>
<p><strong>Note:</strong> Communicate this change with your team. If other developers are unaware of the reset, they might push to <code>master</code>, overwriting the reset.</p>
</li>
<li>
<p>To switch the default branch in GitHub, refer to this article: <a href="https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch" target="_blank" rel="noopener noreferrer">Setting the Default Branch</a>.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="deploy-to-heroku">Deploy to Heroku<a href="https://opensource.salesforce.com/einstein-platform/sambanova#deploy-to-heroku" class="hash-link" aria-label="Direct link to Deploy to Heroku" title="Direct link to Deploy to Heroku">​</a></h2>
<ol>
<li>
<p>Make sure you're logged in to the Heroku CLI:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku login</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Create a new Heroku app:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku create your-app-name</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your-app-name</code> with a unique name for your application.</p>
</li>
<li>
<p>Set the API_KEY config var on Heroku:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku config:set API_KEY=your_api_key_here -a your-app-name</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Replace <code>your_api_key_here</code> with your actual API key.</p>
</li>
<li>
<p>Deploy your app to Heroku:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">git push heroku main</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Open your deployed app:</p>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">heroku open</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<p>Your LLM Open Connector should now be deployed and accessible via the Heroku URL.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="test-your-deployed-application">Test Your Deployed Application<a href="https://opensource.salesforce.com/einstein-platform/sambanova#test-your-deployed-application" class="hash-link" aria-label="Direct link to Test Your Deployed Application" title="Direct link to Test Your Deployed Application">​</a></h2>
<p>You can test your deployed application in two ways:</p>
<ol>
<li>
<p>Using the example UI:</p>
<ul>
<li>Open your browser and navigate to <code>https://your-app-name.herokuapp.com</code></li>
<li>You'll see a simple interface where you can input prompts and get responses from the LLM</li>
<li>Try different prompts and get super fast responses!</li>
</ul>
</li>
<li>
<p>Using API endpoints:
Use a tool like cURL or Postman to test the endpoints of your Flask app:</p>
<ul>
<li>Chat Completions: <code>POST https://your-app-name.herokuapp.com/chat/completions</code></li>
</ul>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a href="https://opensource.salesforce.com/einstein-platform/sambanova#conclusion" class="hash-link" aria-label="Direct link to Conclusion" title="Direct link to Conclusion">​</a></h2>
<p>You have successfully created and deployed an LLM Open Connector using the SambaNova API and deployed it to Heroku! This connector adheres to the Salesforce LLM Open Connector API specification, allowing for seamless integration with the Einstein AI Platform using the BYOLLM feature.</p>
<p>With this connector, you can bring new foundation models like Llama 3 into Einstein Studio that take advantage of SambaNova's fast inference platform.</p>
<p>Remember to monitor your usage and costs associated with the SambaNova API, and consider implementing additional security measures, such as rate limiting, CORS restrictions, and user authentication, before using this connector in a production environment.</p>]]></content>
        <author>
            <name>Richard</name>
            <uri>https://github.com/rsexton404</uri>
        </author>
        <category label="heroku" term="heroku"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
        <category label="sambanova" term="sambanova"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + watsonx]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/ibm</id>
        <link href="https://opensource.salesforce.com/einstein-platform/ibm"/>
        <updated>2024-10-18T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector with the IBM watsonx platform.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> with the IBM watsonx platform.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/ibm#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<ul>
<li>A Salesforce org with Einstein Generative AI and Data Cloud enabled.</li>
<li>A Salesforce Einstein Studio Environment.</li>
</ul>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-1-create-your-watsonx-instance">Step 1. Create Your watsonx Instance<a href="https://opensource.salesforce.com/einstein-platform/ibm#step-1-create-your-watsonx-instance" class="hash-link" aria-label="Direct link to Step 1. Create Your watsonx Instance" title="Direct link to Step 1. Create Your watsonx Instance">​</a></h2>
<p><strong>Create an account.</strong></p>
<ol>
<li>
<p>If you don’t already have one, <a href="https://dataplatform.cloud.ibm.com/registration/stepone?context=wx" target="_blank" rel="noopener noreferrer">create a watsonx trial account</a>.</p>
<p>If you have an existing, non-trial watsonx account, you need to follow these additional steps:</p>
<ol>
<li>In IBM Cloud, <a href="https://dataplatform.cloud.ibm.com/docs/content/wsj/console/wdp_admin_cos.html?context=wx&amp;audience=wdp" target="_blank" rel="noopener noreferrer">set up IBM Cloud Object Storage for use with IBM watsonx</a>.</li>
<li><a href="https://dataplatform.cloud.ibm.com/docs/content/wsj/getting-started/set-up-ws.html?context=wx&amp;audience=wdp" target="_blank" rel="noopener noreferrer">Set up the Watson Studio and Watson Machine Learning</a> services.</li>
<li>Create a new project from the <a href="https://dataplatform.cloud.ibm.com/projects/?context=wx" target="_blank" rel="noopener noreferrer">IBM watsonx console</a>.</li>
</ol>
</li>
</ol>
<p><strong>Find your Project ID value.</strong></p>
<ol>
<li>In your sandbox, click the <strong>Manage</strong> tab and copy your Project ID value.</li>
<li>Store the project-id value. You’ll need this value along with an API key and a region-id in step three.</li>
</ol>
<p><strong>Create an IBM Cloud API Key.</strong></p>
<ol>
<li>In the IBM Cloud console, go to <strong>Manage</strong> &gt; <strong>Access (IAM)</strong>.</li>
<li>In the sidebar, select <strong>API Keys</strong>.</li>
<li>Click <strong>Create</strong>.</li>
<li>Enter a name and description for your API key.</li>
<li>Then, click <strong>Create</strong>.</li>
<li>Store your API key in a safe location.</li>
</ol>
<p><strong>Get the region value for the watsonx instance.</strong></p>
<ol>
<li>From the watsonx home page, check the region in the header bar.</li>
</ol>
<p><img decoding="async" loading="lazy" alt="IBM region id value" src="https://opensource.salesforce.com/einstein-platform/assets/images/ibm-region-id-6b80d5fa2f1395bb5e57dfc4822b0ea9.png" width="460" height="312" class="img_ev3q"></p>
<ol start="2">
<li>Store the region-id value.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-2-verify-your-open-connector-implementation-optional">Step 2. Verify Your Open Connector Implementation (Optional)<a href="https://opensource.salesforce.com/einstein-platform/ibm#step-2-verify-your-open-connector-implementation-optional" class="hash-link" aria-label="Direct link to Step 2. Verify Your Open Connector Implementation (Optional)" title="Direct link to Step 2. Verify Your Open Connector Implementation (Optional)">​</a></h2>
<p>IBM automatically provides a working implementation of the Open Connector for watsonx that you can use to test this workflow. If you want to create your own implementation for production use cases, follow these steps. Otherwise, skip to step three.</p>
<ol>
<li>Create your own connector implementation for watsonx. For directions and code, see <a href="https://ibm.biz/eebl-salesforce-watsonx-apic-connector-code" target="_blank" rel="noopener noreferrer">IBM's watsonx connector repo</a>.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-3-create-a-byollm-connection-to-the-watsonx-model-in-einstein-studio">Step 3. Create a BYOLLM Connection to the watsonx Model in Einstein Studio<a href="https://opensource.salesforce.com/einstein-platform/ibm#step-3-create-a-byollm-connection-to-the-watsonx-model-in-einstein-studio" class="hash-link" aria-label="Direct link to Step 3. Create a BYOLLM Connection to the watsonx Model in Einstein Studio" title="Direct link to Step 3. Create a BYOLLM Connection to the watsonx Model in Einstein Studio">​</a></h2>
<p>Before you connect your Open Connector implementation to Einstein Studio, you need three pieces of information from Step 1: project-id, API key, and region-id.</p>
<ol>
<li>Log in to your Salesforce org as an admin user and open Einstein Studio.</li>
<li>Click <strong>Model Library</strong>.</li>
<li>Click <strong>Add Foundation Model</strong>.</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Add a Foundation Model" src="https://opensource.salesforce.com/einstein-platform/assets/images/ibm-model-library-a9a45f9ecaf52c556a5a6cf306babd50.png" width="2402" height="304" class="img_ev3q"></p>
<ol start="4">
<li>In Model Builder, click <strong>Connect to your LLM</strong>.</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Connect to your LLM" src="https://opensource.salesforce.com/einstein-platform/assets/images/ibm-model-builder-492fa909aeb06bc34857d32bbe1edc80.png" width="1776" height="1478" class="img_ev3q"></p>
<ol start="5">
<li>Click <strong>Next</strong>.</li>
<li>Enter the details of your watsonx instance.<!-- -->
<ul>
<li>Name: IBM Granite (or your own preferred name)</li>
<li>URL:  if you are using the connector hosted by IBM, get the URL from <a href="https://ibm.biz/eebl-salesforce-watsonx-apic-connector-code" target="_blank" rel="noopener noreferrer">IBM's watsonx connector repo</a>. Otherwise, use the URL from the connector instance that you have created from the code and documentation in <a href="https://ibm.biz/eebl-salesforce-watsonx-apic-connector-code" target="_blank" rel="noopener noreferrer">the watsonx repo</a>. When filling out the URL value, be sure to use the project-id and region-id that you copied from step 1.</li>
<li>Authentication: Key Based</li>
<li>Auth Header: X-IBM-API-KEY</li>
<li>Key: [your IBM API key]</li>
<li>Model Name/ID:  ibm/granite-13b-chat-v2 (Or the specific model ID you want to connect to, refer to watsonx model IDs from your IBM watsonx console.)</li>
<li>Token Limit: 8,192 (Or the specified model's maximum context length. Refer to the watsonx model IDs from your IBM watsonx console.)</li>
</ul>
</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Example IBM Granite connection" src="https://opensource.salesforce.com/einstein-platform/assets/images/ibm-granite-connection-a564f3aa6202dc1dfe88855ac53a6c0c.png" width="2350" height="1384" class="img_ev3q"></p>
<ol start="7">
<li>Click <strong>Connect</strong>.</li>
<li>Click <strong>Name and Connect</strong>.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-4-create-a-configured-model">Step 4. Create a Configured Model<a href="https://opensource.salesforce.com/einstein-platform/ibm#step-4-create-a-configured-model" class="hash-link" aria-label="Direct link to Step 4. Create a Configured Model" title="Direct link to Step 4. Create a Configured Model">​</a></h2>
<p>Before you can use your connected LLM, you need to create a configured model.</p>
<ol>
<li>In the Model Library in Einstein Studio, select <strong>Configure Foundation Model</strong>.</li>
<li>Select <strong>Create Model</strong>.</li>
<li>Choose your connected LLM from the “Foundation Model” dropdown.</li>
<li>Configure the model parameters.</li>
<li>Test the model performance in the model playground.</li>
<li>After testing, click <strong>Save</strong> in the bottom right.</li>
<li>Navigate to the "Generative" tab of the Einstein Studio Models page and verify that your watsonx configured model appears.</li>
<li>Select your watsonx model to view the configuration details or create a prompt template.</li>
</ol>
<p>You can now use your LLM wherever you can use Einstein Studio generative models. For instance, you can build prompt templates using <a href="https://www.google.com/url?q=https://help.salesforce.com/s/articleView?id%3Dsf.prompt_builder_about.htm&amp;sa=D&amp;source=docs&amp;ust=1729008016102516&amp;usg=AOvVaw29nKsztGMWSoa59DEIFXZJ" target="_blank" rel="noopener noreferrer">Prompt Builder</a>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="see-also">See Also<a href="https://opensource.salesforce.com/einstein-platform/ibm#see-also" class="hash-link" aria-label="Direct link to See Also" title="Direct link to See Also">​</a></h2>
<ul>
<li><a href="https://ibm.biz/eebl-salesforce-watsonx-apic-connector-code" target="_blank" rel="noopener noreferrer"><em>External:</em> IBM watsonx Repo</a></li>
<li><a href="https://dsce.ibm.com/wizard/watsonx/results/watsonx-use-watsonx-ai-models-from-salesforce#" target="_blank" rel="noopener noreferrer"><em>Interactive Demo:</em> Use watsonx AI models from Salesforce</a></li>
<li><a href="https://help.salesforce.com/s/articleView?id=sf.c360_a_ai_foundation_models_create.htm&amp;type=5" target="_blank" rel="noopener noreferrer"><em>Salesforce Help:</em> Add a Foundation Model</a></li>
</ul>]]></content>
        <author>
            <name>Tate</name>
            <uri>https://github.com/tatedorman</uri>
        </author>
        <category label="ibm" term="ibm"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + MuleSoft + Cerebras]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/mulesoft</id>
        <link href="https://opensource.salesforce.com/einstein-platform/mulesoft"/>
        <updated>2024-11-25T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector with MuleSoft Anypoint Platform using its AI Chain Connector and Inference Connector.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> with MuleSoft Anypoint Platform using its <a href="https://mac-project.ai/docs/mulechain-ai/getting-started" target="_blank" rel="noopener noreferrer">AI Chain Connector</a> and <a href="https://mac-project.ai/docs/mac-inference/getting-started" target="_blank" rel="noopener noreferrer">Inference Connector</a>.</p>
<p>This recipe implements an example of Cerebras Inference; however, the high-level process is the same for all models and providers.</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>The steps in this recipe use Anypoint Studio. For instructions using Anypoint Code Builder (ACB), see <a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama">LLM Open Connector + MuleSoft + Ollama</a>.</p></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="high-level-process">High-level Process<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#high-level-process" class="hash-link" aria-label="Direct link to High-level Process" title="Direct link to High-level Process">​</a></h2>
<p>There are four high-level steps for connecting your MuleSoft model endpoint to the LLM Open Connector.</p>
<p><img decoding="async" loading="lazy" alt="MuleSoft high-level process" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-process-1f818868c9d627edee9bd28d6edf4137.png" width="2678" height="546" class="img_ev3q"></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites--tutorial-video">Prerequisites + Tutorial Video<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#prerequisites--tutorial-video" class="hash-link" aria-label="Direct link to Prerequisites + Tutorial Video" title="Direct link to Prerequisites + Tutorial Video">​</a></h2>
<p>Before you begin, review the prerequisites:</p>
<ol>
<li>You have a MuleSoft Account (<a href="https://anypoint.mulesoft.com/login/signup" target="_blank" rel="noopener noreferrer">Sign up here</a>).</li>
<li>You have <a href="https://docs.mulesoft.com/anypoint-code-builder/start-acb-desktop" target="_blank" rel="noopener noreferrer">Anypoint Code Builder (ACB)</a> or <a href="https://www.mulesoft.com/lp/dl/anypoint-mule-studio" target="_blank" rel="noopener noreferrer">Anypoint Studio</a> installed. The instructions in this recipe are based on Anypoint Studio.</li>
<li>You have <a href="https://mac-project.ai/docs/mac-inference/getting-started" target="_blank" rel="noopener noreferrer">Inference Connector</a> installed.</li>
<li>You have a <a href="https://inference.cerebras.ai/" target="_blank" rel="noopener noreferrer">Cerebras account</a> with an API key.</li>
</ol>
<p>View a step-by-step tutorial video that covers an implementation similar to the one covered in this recipe:</p>
<div style="width:640px;height:360px"></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-1-download-the-api-specification-for-the-llm-open-connector">Step 1: Download the API Specification for the LLM Open Connector<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#step-1-download-the-api-specification-for-the-llm-open-connector" class="hash-link" aria-label="Direct link to Step 1: Download the API Specification for the LLM Open Connector" title="Direct link to Step 1: Download the API Specification for the LLM Open Connector">​</a></h2>
<ol>
<li>
<p>Download LLM Open Connector <a href="https://github.com/salesforce/einstein-platform/blob/main/api-specs/llm-open-connector/llm-open-connector.yml" target="_blank" rel="noopener noreferrer">API Spec</a>.</p>
</li>
<li>
<p>Rename the file from <code>llm-open-connector.yml</code> to <code>llm-open-connector.yaml</code>.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-2-import-the-api-specification-into-anypoint-design-center">Step 2: Import the API Specification into Anypoint Design Center<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#step-2-import-the-api-specification-into-anypoint-design-center" class="hash-link" aria-label="Direct link to Step 2: Import the API Specification into Anypoint Design Center" title="Direct link to Step 2: Import the API Specification into Anypoint Design Center">​</a></h2>
<ol>
<li>
<p>Log in to your MuleSoft account.</p>
</li>
<li>
<p>Go to <a href="https://anypoint.mulesoft.com/designcenter/#/projects" target="_blank" rel="noopener noreferrer">Anypoint Design Center</a>.</p>
</li>
<li>
<p>Import a new API specification from a file using these values:</p>
<ul>
<li>Project Name: <code>Cerebras-LLM-Provider</code>,</li>
<li>API Specification: Select <code>REST API</code>,</li>
<li>File upload: <code>llm-open-connector.yaml</code>. Be sure to use the renamed file.</li>
</ul>
</li>
<li>
<p>Click <strong>Import</strong>.</p>
</li>
<li>
<p>Verify that the API specification successfully imported.</p>
</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Import API Specification" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-publish-provider-asset-f322ef300d69906f1f42290c3e29eb12.png" width="1924" height="1244" class="img_ev3q"></p>
<ol start="6">
<li>
<p>Change <code>termsOfService: ""</code> to <code>termsOfService: "-"</code>.</p>
</li>
<li>
<p>Remove <code>servers:</code> and the example <code>url</code>.</p>
</li>
</ol>
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">servers:</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  - url: https://bring-your-own-llm.example.com</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<ol start="7">
<li>
<p>Click <strong>Publish.</strong></p>
</li>
<li>
<p>Provide versioning information:</p>
<ul>
<li>Asset version: <code>1.0.0</code></li>
<li>API version: <code>v1</code></li>
<li>Lifecycle State: <code>Stable</code></li>
</ul>
</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Publish to Exchange" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-publish-to-exchange-5f2371e21ff7627d719821991c146112.png" width="1360" height="1164" class="img_ev3q"></p>
<ol start="9">
<li>Click <strong>Publish to Exchange</strong>.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-3-implement-the-api-specification">Step 3: Implement the API Specification<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#step-3-implement-the-api-specification" class="hash-link" aria-label="Direct link to Step 3: Implement the API Specification" title="Direct link to Step 3: Implement the API Specification">​</a></h2>
<p>This cookbook uses Anypoint Studio to implement the API Specification. If you prefer, you can also implement the spec with Anypoint Code Builder.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="import-api-specification-into-studio">Import API Specification into Studio<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#import-api-specification-into-studio" class="hash-link" aria-label="Direct link to Import API Specification into Studio" title="Direct link to Import API Specification into Studio">​</a></h3>
<ol>
<li>
<p>Open Anypoint Studio and create a Mule Project.</p>
</li>
<li>
<p>Name the project and import an API spec:</p>
<ul>
<li>Project Name: <code>cerebras-llm-provider</code>,</li>
<li>Import a published API: Select the <code>Cerebras-LLM-Provider</code> API spec from the previous step.</li>
</ul>
</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Add API to Mule Project" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-scaffold-7519e545c56ada1d03f6beac23bd177f.png" width="1808" height="1208" class="img_ev3q"></p>
<ol start="3">
<li>Click <strong>Finish</strong>.</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="add-the-inference-connector-to-your-project">Add the Inference Connector to Your Project<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#add-the-inference-connector-to-your-project" class="hash-link" aria-label="Direct link to Add the Inference Connector to Your Project" title="Direct link to Add the Inference Connector to Your Project">​</a></h3>
<ol>
<li>If you have not installed the Inference Connector, <a href="https://mac-project.ai/docs/mac-inference/getting-started" target="_blank" rel="noopener noreferrer">install it</a> before you start.</li>
<li>Add the Inference Connector dependency to the Mule Project.</li>
</ol>
<div class="language-xml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-xml codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">dependency</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">groupId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">com.mulesoft.connectors</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">groupId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">artifactId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">mac-inference-chain</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">artifactId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">version</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">0.1.0</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">version</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">classifier</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">mule-plugin</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">classifier</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">dependency</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<ol start="3">
<li>Make sure the Inference Connector is present in the Mule Palette.
<img decoding="async" loading="lazy" alt="Mule Palette" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-mule-palette-inference-886e3601bcb50893d59153ec3aa41f26.png" width="1646" height="488" class="img_ev3q"></li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="implement-the-chat-completions-endpoint">Implement the Chat Completions Endpoint<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#implement-the-chat-completions-endpoint" class="hash-link" aria-label="Direct link to Implement the Chat Completions Endpoint" title="Direct link to Implement the Chat Completions Endpoint">​</a></h3>
<ol>
<li>
<p>Go to the scaffolded flow <code>post:\chat\completions:application\json:llm-open-connector-config</code>.</p>
</li>
<li>
<p>Drag and drop <code>Chat completions</code> operation from the Inference Connector into the Flow.</p>
</li>
<li>
<p>Provide the Inference connector configuration for Cerebras.</p>
</li>
<li>
<p>Parametrize all properties needed by the LLM Open Connector API Spec.
<img decoding="async" loading="lazy" alt="Configuration Params" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-configuration-params-9f210cb3b6f7d130b0f7e50f976c669d.png" width="1258" height="726" class="img_ev3q">.</p>
</li>
<li>
<p>In the <code>Chat completions</code> operation, enter: <code>payload.messages</code>.</p>
</li>
<li>
<p>Before the <code>Chat completions</code> operation, add the <code>Set Variable</code> operation with the name <code>model</code> and enter in the expression value <code>payload.model</code>.</p>
</li>
<li>
<p>After the <code>Chat completions</code> operation, add the <code>Transform Message</code> operation and provide the mapping in this code block:</p>
</li>
</ol>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">%dw </span><span class="token number" style="color:#36acaa">2.0</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">output application/json</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">---</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">	id</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"chatcmpl-"</span><span class="token plain"> ++ now() as Number as String</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">	created</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> now() as Number</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">	usage</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">		completion_tokens</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> attributes.tokenUsage.outputCount</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">		prompt_tokens</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> attributes.tokenUsage.inputCount</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">		total_tokens</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> attributes.tokenUsage.totalCount</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">	</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">	model</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> vars.model</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">	choices</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    	</span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      finish_reason</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"stop"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      index</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      message</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        content</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> payload.response default </span><span class="token string" style="color:#e3116c">""</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        role</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"assistant"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">	object</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"chat.completion"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<ol start="8">
<li>Save the project.</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="test-locally">Test Locally<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#test-locally" class="hash-link" aria-label="Direct link to Test Locally" title="Direct link to Test Locally">​</a></h3>
<ol>
<li>
<p>Start the Mule Application.</p>
</li>
<li>
<p>Go to the API Console.
<img decoding="async" loading="lazy" alt="Configuration Params" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-test-locally-c3f2131055d7d4f5fbff7f11f7813a16.png" width="3078" height="1514" class="img_ev3q"></p>
</li>
<li>
<p>Enter the API Key and following payload:</p>
</li>
</ol>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"messages"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"What is the capital of Switzerland?"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token property" style="color:#36acaa">"name"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">""</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"model"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"llama3.1-8b"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"max_tokens"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">500</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"n"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"temperature"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0.7</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"parameters"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"top_p"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0.5</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<ol start="4">
<li>Validate the result. Make sure the values are mapped correctly for token usage.</li>
</ol>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"id"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"chatcmpl-1732373228"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"created"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1732373228</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"usage"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"completion_tokens"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">8</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"prompt_tokens"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">42</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"total_tokens"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">50</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"model"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"llama3.1-8b"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"choices"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token property" style="color:#36acaa">"finish_reason"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"stop"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token property" style="color:#36acaa">"index"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">0</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token property" style="color:#36acaa">"message"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token property" style="color:#36acaa">"content"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"The capital of Switzerland is Bern."</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"assistant"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token property" style="color:#36acaa">"object"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"chat.completion"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="step-4-deploy-to-anypoint-cloudhub">Step 4. Deploy to Anypoint CloudHub<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#step-4-deploy-to-anypoint-cloudhub" class="hash-link" aria-label="Direct link to Step 4. Deploy to Anypoint CloudHub" title="Direct link to Step 4. Deploy to Anypoint CloudHub">​</a></h2>
<ol>
<li>
<p>After the application is tested successfully, deploy it to Anypoint CloudHub.</p>
</li>
<li>
<p>Right-click your Mule Project and navigate to <code>Anypoint Platform</code> &gt; <code>Deploy to CloudHub</code>.</p>
</li>
<li>
<p>Choose the environment you want to deploy to.</p>
</li>
<li>
<p>Enter the required values:</p>
<ul>
<li>App name: <code>cerebras-llm-provider</code></li>
<li>Deployment target: <code>Shared Space (Cloudhub 2.0)</code></li>
<li>Replica Count: <code>1</code></li>
<li>Replica Size: <code>Micro (0.1 vCore)</code></li>
</ul>
</li>
<li>
<p>Click <strong>Deploy Application</strong>.</p>
</li>
<li>
<p>Wait until the application is deployed.</p>
</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Deployed App" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-deployed-app-97551247b0b0376e116cf1c7d79bad6f.png" width="2472" height="450" class="img_ev3q"></p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>If you receive the error <code>[The asset is invalid, Error while trying to set type: app. Expected type is: rest-api.]</code>, go to Exchange and delete or rename the asset. <a href="https://help.salesforce.com/s/articleView?id=001119384&amp;type=1" target="_blank" rel="noopener noreferrer">This error is a known issue</a>.</p></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="create-a-configuration-in-model-builder">Create a Configuration in Model Builder<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#create-a-configuration-in-model-builder" class="hash-link" aria-label="Direct link to Create a Configuration in Model Builder" title="Direct link to Create a Configuration in Model Builder">​</a></h2>
<p>After your API is running on CloudHub, you need to add the model endpoint to Model Builder.</p>
<ol>
<li>
<p>In Salesforce, open Data Cloud.</p>
</li>
<li>
<p>Navigate to Einstein Studio.</p>
</li>
<li>
<p>Click <strong>Add Foundation Model</strong>, and click <strong>Connect to your LLM</strong>.</p>
</li>
<li>
<p>Click <strong>Next</strong>.</p>
</li>
<li>
<p>Enter the required values:</p>
<ul>
<li>Name: <code>Cerebras-LLM-Provider</code></li>
<li>URL: <code>&lt;cloudhub_url&gt;/api</code></li>
<li>Model: A model name is required. For this recipe, choose between <code>llama3.1-70b</code> or <code>llama3.1-8b</code>.</li>
</ul>
</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Model Builder" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-add-model-einstein-studio-0e18449420dc98913e5dd770624941a0.png" width="1934" height="1368" class="img_ev3q"></p>
<ol start="6">
<li>
<p>Click <strong>Connect</strong>.</p>
</li>
<li>
<p>Create two configurations for each supported model:</p>
<ul>
<li><code>llama3.1-70b</code></li>
<li><code>llama3.1-8b</code></li>
</ul>
</li>
</ol>
<p><img decoding="async" loading="lazy" alt="Model Builder Playground" src="https://opensource.salesforce.com/einstein-platform/assets/images/mule-mac-einstein-playground-1d93a24bf794f7eff3e36defedc68e59.png" width="2526" height="712" class="img_ev3q"></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="important-considerations">Important Considerations<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#important-considerations" class="hash-link" aria-label="Direct link to Important Considerations" title="Direct link to Important Considerations">​</a></h2>
<ol>
<li>This cookbook uses Cerebras models <code>llama3.1-70b</code> and <code>llama3.1-8b</code>.</li>
<li>When configuring in Model Builder, you need to provide a default value for the model. In this recipe the model name is parametrized, so a value is required.</li>
<li>The API is deployed under the governance of the MuleSoft Anypoint Platform. As a result:<!-- -->
<ul>
<li>You can monitor the application by viewing logs and errors.</li>
<li>You can apply additional security through Anypoint's API management capabilities.</li>
<li>You can deploy multiple replicas to scale horizontally and vertically.</li>
</ul>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a href="https://opensource.salesforce.com/einstein-platform/mulesoft#conclusion" class="hash-link" aria-label="Direct link to Conclusion" title="Direct link to Conclusion">​</a></h2>
<p>This cookbook demonstrates how to set up an LLM Open Connector using MuleSoft for the Chat Completion endpoints of Cerebras. This recipe is a sandbox implementation, and it's not production ready. For production use, please optimize your implementation based on your specific requirements and expected usage patterns.</p>]]></content>
        <author>
            <name>Amir</name>
            <uri>https://github.com/amirkhan-ak-sf</uri>
        </author>
        <category label="mulesoft" term="mulesoft"/>
        <category label="mac" term="mac"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + MuleSoft + Ollama]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/mulesoft-ollama</id>
        <link href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama"/>
        <updated>2024-11-29T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector using MuleSoft and the MuleSoft AI Chain (MAC) project. This recipe relies on locally hosted Ollama for quick testing. The Mule application and MAC project run in CloudHub to expose the API.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> using MuleSoft and the <a href="https://mac-project.ai/" target="_blank" rel="noopener noreferrer">MuleSoft AI Chain (MAC)</a> project. This recipe relies on locally hosted <a href="https://ollama.com/" target="_blank" rel="noopener noreferrer">Ollama</a> for quick testing. The Mule application and MAC project run in CloudHub to expose the API.</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>The steps in this recipe use Anypoint Code Builder (ACB). For instructions using Anypoint Studio, see <a href="https://opensource.salesforce.com/einstein-platform/mulesoft">LLM Open Connector + MuleSoft + Cerebras</a>.</p></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<ol>
<li>Anypoint Platform account (create a free trial <a href="https://anypoint.mulesoft.com/login/signup" target="_blank" rel="noopener noreferrer">here</a>).</li>
<li>MuleSoft's IDE: either <a href="https://docs.mulesoft.com/anypoint-code-builder/start-acb-desktop" target="_blank" rel="noopener noreferrer">Anypoint Code Builder (ACB)</a> or <a href="https://www.mulesoft.com/lp/dl/anypoint-mule-studio" target="_blank" rel="noopener noreferrer">Anypoint Studio</a>. This recipe is based on ACB.</li>
<li><a href="https://ollama.com/" target="_blank" rel="noopener noreferrer">Ollama</a> locally running the model of your choice (for example, <code>llama3</code>).</li>
<li><a href="https://download.ngrok.com/" target="_blank" rel="noopener noreferrer">Ngrok</a> to expose your local Ollama instance to the public cloud.</li>
<li>A REST client application to test the API calls. For example, cURL or Postman.</li>
</ol>
<p>For troubleshooting, you can compare your Mule app with <a href="https://github.com/alexandramartinez/ollama-llm-provider" target="_blank" rel="noopener noreferrer">this GitHub repo</a>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="expose-the-ollama-url">Expose the Ollama URL<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#expose-the-ollama-url" class="hash-link" aria-label="Direct link to Expose the Ollama URL" title="Direct link to Expose the Ollama URL">​</a></h2>
<ol>
<li>
<p>Verify your model is up and running (locally) in Ollama using <code>ollama list</code> or <code>ollama ps</code>.</p>
</li>
<li>
<p>Run this command to start ngrok:</p>
<div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">ngrok http 11434 --host-header="localhost:11434"</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Copy the address from the <strong>Forwarding</strong> field. This address is the URL you need to connect to Ollama from the Mule app.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="create-and-publish-the-api-specification">Create and Publish the API Specification<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#create-and-publish-the-api-specification" class="hash-link" aria-label="Direct link to Create and Publish the API Specification" title="Direct link to Create and Publish the API Specification">​</a></h2>
<ol>
<li>
<p>Download the <code>llm-open-connector.yml</code> file from the <a href="https://github.com/salesforce/einstein-platform/blob/main/api-specs/llm-open-connector/llm-open-connector.yml" target="_blank" rel="noopener noreferrer">einstein-platform</a> GitHub repository.</p>
</li>
<li>
<p>Rename the extension of the file from <code>yml</code> to <code>yaml</code>.</p>
</li>
<li>
<p>Log in to your <a href="https://anypoint.mulesoft.com/" target="_blank" rel="noopener noreferrer">Anypoint Platform</a> account.</p>
</li>
<li>
<p>Navigate to <strong>Design Center</strong>.</p>
</li>
<li>
<p>Click <strong>Create +</strong> &gt; <strong>Import from File</strong>.</p>
</li>
<li>
<p>Fill out the spec details:</p>
<ul>
<li>Project name: <code>LLM Open Connector</code></li>
<li>Import type: API specification <code>REST API</code></li>
<li>Import file: The <code>llm-open-connector.yaml</code> file from steps 1 and 2. (Ensure that the file extension is <code>.yaml</code>.)</li>
</ul>
</li>
<li>
<p>Click <strong>Import</strong>.</p>
</li>
<li>
<p>Add a character inside <code>termsOfService</code> (for example, <code>termsOfService: "-"</code>).</p>
</li>
<li>
<p>Remove the <code>servers</code> section, including the example <code>url</code>:</p>
<div class="language-yaml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-yaml codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token key atrule" style="color:#00a4db">servers</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain"> </span><span class="token key atrule" style="color:#00a4db">url</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> https</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain">//bring</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">your</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">own</span><span class="token punctuation" style="color:#393A34">-</span><span class="token plain">llm.example.com</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Click <strong>Publish</strong> in the top right of the screen.</p>
</li>
<li>
<p>Provide versioning information:</p>
<ul>
<li>Asset version: <code>1.0.0</code></li>
<li>API version: <code>v1</code></li>
<li>LifeCycle State: Stable</li>
</ul>
</li>
<li>
<p>Click <strong>Publish to Exchange</strong>.</p>
</li>
<li>
<p>After it is published, you can click the <strong>Exchange</strong> link to see the preview of the published asset, or click <strong>Close</strong>.</p>
</li>
<li>
<p>Exit Design Center.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="implement-the-mule-app">Implement the Mule App<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#implement-the-mule-app" class="hash-link" aria-label="Direct link to Implement the Mule App" title="Direct link to Implement the Mule App">​</a></h2>
<ol>
<li>
<p>Head to the IDE of your choice. In this recipe, we are using Anypoint Code Builder, the MuleSoft IDE powered by Visual Studio Code.</p>
</li>
<li>
<p>In ACB, click <strong>Implement an API</strong>.</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>If you haven't signed in to your Anypoint Platform account through ACB, it asks you to sign in. Follow the prompts to sign in.</p></div></div>
</li>
<li>
<p>Fill out the project details:</p>
<ul>
<li>Project Name: <code>ollama-llm-provider</code></li>
<li>Project Location: choose any folder to keep this project</li>
<li>Search an API Specification from Exchange to implement it: the <strong>LLM Open Connector</strong> we just published</li>
<li>Mule Runtime: <code>4.8.0</code></li>
<li>Java Version: <code>17</code></li>
</ul>
</li>
<li>
<p>Click <strong>Create Project</strong> and wait for it to be fully processed.</p>
</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="maven">Maven<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#maven" class="hash-link" aria-label="Direct link to Maven" title="Direct link to Maven">​</a></h3>
<ol>
<li>
<p>After it is processed, open the <code>pom.xml</code> file and add the Maven dependency:</p>
<div class="language-xml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-xml codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">dependency</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">groupId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">com.mulesoft.connectors</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">groupId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">artifactId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">mule4-aichain-connector</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">artifactId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">version</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">1.0.0</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">version</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">classifier</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">mule-plugin</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">classifier</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">dependency</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Change the <code>version</code> in line 6:</p>
<div class="language-xml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-xml codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">version</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">1.0.0</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">version</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Copy the <code>groupId</code> (in <code>dependencies</code>) for the <code>llm-open-connector</code> artifact. The <code>groupId</code> is a number similar to: <code>d62b8a81-f143-4534-bb89-3673ad61ah01</code>. This number is your organization ID.</p>
</li>
<li>
<p>Paste this organization ID in the <code>groupId</code> field at the top of the file, replacing <code>com.mycompany</code>:</p>
<div class="language-xml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-xml codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">groupId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain">d62b8a81-f143-4534-bb89-3673ad61ah01</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag" style="color:#00009f">groupId</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="llm-config">LLM Config<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#llm-config" class="hash-link" aria-label="Direct link to LLM Config" title="Direct link to LLM Config">​</a></h3>
<ol>
<li>
<p>Create a file under src/main/resources named <code>llm-config.json</code>.</p>
</li>
<li>
<p>Paste this code into the <code>llm-config.json</code> file:</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"OLLAMA"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token property" style="color:#36acaa">"OLLAMA_BASE_URL"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"https://11-13-23-16-11.ngrok-free.app"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Replace the example URL with the one you copied from ngrok in step 3 of <a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#expose-the-ollama-url">Expose the Ollama URL</a>.</p>
</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="mule-flow">Mule Flow<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#mule-flow" class="hash-link" aria-label="Direct link to Mule Flow" title="Direct link to Mule Flow">​</a></h3>
<ol>
<li>
<p>Open the <code>ollama-llm-provider.xml</code> file under src/main/mule.</p>
</li>
<li>
<p>Add this code under <code>apikit:config</code> and before <code>&lt;flow name="llm-open-connector-main"&gt;</code>.</p>
<div class="language-xml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-xml codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ms-aichain:</span><span class="token tag" style="color:#00009f">config</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">configType</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">Configuration Json</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">filePath</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">'</span><span class="token tag attr-value" style="color:#e3116c">#[(mule.home default "") ++ "/apps/" ++ (app.name default "") ++ "/llm-config.json"]</span><span class="token tag attr-value punctuation" style="color:#393A34">'</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">llmType</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">OLLAMA</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">modelName</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">#[vars.inputPayload.model default 'llama3']</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">name</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">MAC_Config</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">temperature</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">#[vars.inputPayload.temperature default 1]</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">maxTokens</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">#[vars.inputPayload.max_tokens default 500]</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ms-aichain:</span><span class="token tag" style="color:#00009f">config</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>If your model is not <code>llama3</code>, make sure you upload the <code>default</code> value in the previous line (for example, <code>modelName="#[vars.inputPayload.model default 'llama3']"</code>).</p></div></div>
</li>
<li>
<p>Locate the last flow in the file (for example, <code>post:\chat\completions:application\json:llm-open-connector-config</code>).</p>
</li>
<li>
<p>Remove the logger and add this code to the flow.</p>
<div class="language-xml codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-xml codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">logger</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">name</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">Logger</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">id</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">ezzhif</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">message</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">#[payload]</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag punctuation" style="color:#393A34">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">transform</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">name</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">Transform</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">id</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">dstcls</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">message</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">set-payload</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token cdata" style="color:#999988;font-style:italic">&lt;![CDATA[(payload.messages filter ($.role == "user"))[0].content default payload.messages[0].content]]&gt;</span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">set-payload</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">message</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">variables</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">set-variable</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">variableName</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">inputPayload</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">            </span><span class="token cdata" style="color:#999988;font-style:italic">&lt;![CDATA[payload]]&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">set-variable</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">variables</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">transform</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ms-aichain:</span><span class="token tag" style="color:#00009f">chat-answer-prompt</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">config-ref</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">MAC_Config</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">id</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">mmoptd</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">name</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">Chat answer prompt</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag punctuation" style="color:#393A34">/&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">transform</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">name</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">Transform</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">id</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">czdqgi</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">message</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">set-payload</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">                </span><span class="token cdata" style="color:#999988;font-style:italic">&lt;![CDATA[output application/json</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">---</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">{</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    id: uuid( ),</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    choices: [</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">        {</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">            finish_reason: "stop",</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">            index: 0,</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">            message: {</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">                content: payload.response default "",</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">                role: "assistant"</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">            }</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">        }</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    created: now() as Number,</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    model: vars.inputPayload.model default "",</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    object: "chat.completion",</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    usage: {</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">        completion_tokens: (attributes.tokenUsage.outputCount default 0) as Number,</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">        prompt_tokens: (attributes.tokenUsage.inputCount default 0) as Number,</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">        total_tokens: (attributes.tokenUsage.totalCount default 0) as Number</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">    }</span><br></span><span class="token-line" style="color:#393A34"><span class="token cdata" style="color:#999988;font-style:italic">}]]&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">set-payload</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">message</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;/</span><span class="token tag namespace" style="color:#00009f;opacity:0.7">ee:</span><span class="token tag" style="color:#00009f">transform</span><span class="token tag punctuation" style="color:#393A34">&gt;</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token tag punctuation" style="color:#393A34">&lt;</span><span class="token tag" style="color:#00009f">logger</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">name</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">Logger</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name namespace" style="color:#00a4db;opacity:0.7">doc:</span><span class="token tag attr-name" style="color:#00a4db">id</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">rzhuiw</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag attr-name" style="color:#00a4db">message</span><span class="token tag attr-value punctuation attr-equals" style="color:#393A34">=</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag attr-value" style="color:#e3116c">#[payload]</span><span class="token tag attr-value punctuation" style="color:#393A34">"</span><span class="token tag" style="color:#00009f"> </span><span class="token tag punctuation" style="color:#393A34">/&gt;</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Save all the files.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="deploy-to-cloudhub-20">Deploy to CloudHub 2.0<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#deploy-to-cloudhub-20" class="hash-link" aria-label="Direct link to Deploy to CloudHub 2.0" title="Direct link to Deploy to CloudHub 2.0">​</a></h2>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>To verify your setup, you can test your application locally before deploying to CloudHub. Navigate to the <strong>Run and Debug</strong> tab, click the green <strong>run</strong> button, and follow <a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#test-the-deployed-mule-app">Test the Deployed Mule App</a>. Be sure to replace the URL with <code>http://localhost:8081/api/chat/completions</code>.</p></div></div>
<ol>
<li>
<p>With the <code>ollama-llm-provider.xml</code> file open, click <strong>Deploy to CloudHub</strong> in the top right of the screen (the rocket 🚀 icon).</p>
</li>
<li>
<p>Select <strong>CloudHub 2.0</strong>.</p>
</li>
<li>
<p>Select <strong>Cloudhub-US-East-2</strong> if you have a free trial account based on the US cloud. Otherwise, select any of the regions available to you.</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>To verify the regions you have access to in your Anypoint Platform account, you can do so from the <strong>Runtime Manager</strong> by creating a deployment and checking the available options.</p></div></div>
</li>
<li>
<p>Select <strong>Sandbox</strong> as the environment.</p>
</li>
<li>
<p>A new file named <code>deploy_ch2.json</code> is created under src/main/resources. You can change the data in this file if needed. By default, it contains:</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"applicationName"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"ollama-llm-provider"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"runtime"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"4.8.0"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"replicas"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"replicaSize"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"0.1"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token property" style="color:#36acaa">"deploymentModel"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"rolling"</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>In the message that appears in the bottom right, click <strong>Deploy</strong>.</p>
</li>
<li>
<p>In the next prompt, select the latest Mule runtime version available. For this recipe, you can select <code>4.8.1:6e-java17</code> if available. This action changes the <code>runtime</code> field in the <code>deploy_ch2.json</code> file.</p>
</li>
<li>
<p>Your asset is first published to Exchange as an Application. Afterwards, the deployment to CloudHub 2.0 starts. When you receive the message: <em>'ollama-llm-provider' is deployed to 'Sandbox' Env in CloudHub 2.0</em>, the deployment has successfully started in Anypoint Platform.</p>
</li>
<li>
<p>Navigate to your Anypoint Platform account and open <strong>Runtime Manager</strong> (or click <strong>Open in Runtime Manager</strong> in ACB).</p>
</li>
<li>
<p>When your application's status appears as 🟢 <code>Running</code>, it's ready to start receiving requests. Copy the public endpoint URL (for example, <code>https://ollama-llm-provider-69s5jr.5se6i9-2.usa-e2.cloudhub.io</code>).</p>
</li>
<li>
<p>Add <code>/api</code> at the end of the URL. This URL is used to call the API.</p>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="test-the-deployed-mule-app">Test the Deployed Mule App<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#test-the-deployed-mule-app" class="hash-link" aria-label="Direct link to Test the Deployed Mule App" title="Direct link to Test the Deployed Mule App">​</a></h2>
<p>You can call the previous URL using tools like cURL or Postman. Here is an example cURL command; make sure you replace the example URL with your own.</p>
<div class="language-shell codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-shell codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">curl -X POST https://ollama-llm-provider-69s5jr.5se6i9-2.usa-e2.cloudhub.io/api/chat/completions \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-H 'Content-Type: application/json' \</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">-d '{</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "messages": [</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "content": "What is the capital of Canada?",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "role": "user",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">      "name": "Alex"</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  ],</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "model": "llama3",</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "max_tokens": 0,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "n": 1,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "temperature": 1,</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  "parameters": {</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">    "top_p": 0.5</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">  }</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">}'</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>Since Ollama does not require an <code>api-key</code> header, we are not sending it in this request.</p></div></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="bring-your-connected-endpoint-to-salesforce-model-builder">Bring Your Connected Endpoint to Salesforce Model Builder<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#bring-your-connected-endpoint-to-salesforce-model-builder" class="hash-link" aria-label="Direct link to Bring Your Connected Endpoint to Salesforce Model Builder" title="Direct link to Bring Your Connected Endpoint to Salesforce Model Builder">​</a></h2>
<p>Follow the instructions in <a href="https://developer.salesforce.com/blogs/2024/10/build-generative-ai-solutions-with-llm-open-connector" target="_blank" rel="noopener noreferrer">this developer blog</a> to use your model in Model Builder. When you activate your model, you can use it within <a href="https://developer.salesforce.com/docs/einstein/genai/guide/get-started-prompt-builder.html" target="_blank" rel="noopener noreferrer">Prompt Builder</a>, the <a href="https://developer.salesforce.com/docs/einstein/genai/guide/models-api.html" target="_blank" rel="noopener noreferrer">Models API</a>, and for building actions using prompt templates in Agent Builder. All these methods provide built-in security offered by the <a href="https://help.salesforce.com/s/articleView?id=sf.generative_ai_trust_layer.htm&amp;type=5" target="_blank" rel="noopener noreferrer">Einstein Trust Layer</a>.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="conclusion">Conclusion<a href="https://opensource.salesforce.com/einstein-platform/mulesoft-ollama#conclusion" class="hash-link" aria-label="Direct link to Conclusion" title="Direct link to Conclusion">​</a></h2>
<p>This cookbook demonstrates how to set up the LLM Open Connector using Ollama locally for Chat Completion endpoints for various models. This option is recommended for local testing since there are no credit limits. Another scenario is if you want to test your own model locally using Ollama. The implementation in this recipe is not recommended for production use unless you plan to host your model on-premises.</p>]]></content>
        <author>
            <name>Alex Martinez</name>
            <uri>https://github.com/alexandramartinez</uri>
        </author>
        <category label="mulesoft" term="mulesoft"/>
        <category label="mac" term="mac"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
        <category label="ollama" term="ollama"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + Vertex AI]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/vertex</id>
        <link href="https://opensource.salesforce.com/einstein-platform/vertex"/>
        <updated>2025-02-28T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector with the Google Cloud Platform (GCP).]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> with the Google Cloud Platform (GCP).</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="overview">Overview<a href="https://opensource.salesforce.com/einstein-platform/vertex#overview" class="hash-link" aria-label="Direct link to Overview" title="Direct link to Overview">​</a></h2>
<p>This document outlines detailed steps for using LLM Open Connector with Vertex AI on Google Cloud.</p>
<p>Instead of building custom, one-off integrations for each LLM vendor, the LLM Open Connector provides a standard API-based approach on the OpenAI schema. LLM Open Connector provides a simple and quick path for teams to connect any model—be it enterprise-grade, open-source, or custom-trained—to Salesforce.</p>
<p>In this example, we will deploy a fine-tuned Gemini model from Google on Vertex AI Model Garden, use Google Cloud Run Functions (Gen 2) for serverless compute, providing a scalable and maintainable solution that connects Salesforce to Vertex AI's model endpoints. This approach is particularly suited for Agentforce chat completion use cases, enabling advanced conversational AI capabilities within Salesforce.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="tutorial-video">Tutorial Video<a href="https://opensource.salesforce.com/einstein-platform/vertex#tutorial-video" class="hash-link" aria-label="Direct link to Tutorial Video" title="Direct link to Tutorial Video">​</a></h2>
<p>View a step-by-step tutorial video that covers this Vertex AI recipe on YouTube:</p>
<div style="width:640px;height:360px"></div>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="background-information">Background Information<a href="https://opensource.salesforce.com/einstein-platform/vertex#background-information" class="hash-link" aria-label="Direct link to Background Information" title="Direct link to Background Information">​</a></h2>
<p>This section introduces the products and features covered in the cookbook. If you're already familiar with LLM Open Connector, Google Cloud Platform (GCP), and Vertex AI feel free to skip to the next section.</p>
<ol>
<li>
<p>Google Cloud equivalents to AWS services.</p>
<ul>
<li><strong>AWS Bedrock:</strong> GCP's equivalent for hosting foundation models is <strong>Vertex AI</strong>. Vertex AI provides access to various models, including Google's own and other partner models. All models can be found in Model Garden</li>
<li><strong>AWS Lambda:</strong> GCP's serverless compute platform is <strong>Cloud Functions</strong>. This will host your code that interacts with the LLM.</li>
<li><strong>AWS API Gateway:</strong> GCP's API management service is <strong>Cloud Endpoints</strong> or <strong>Cloud Functions (HTTP)</strong>. These services create the API endpoint that the LLM Open Connector will call in Salesforce.</li>
</ul>
</li>
<li>
<p>Vertex AI offers a range of <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models" target="_blank" rel="noopener noreferrer">foundation models</a>. This cookbook uses Gemini 1.5 Pro.</p>
<ul>
<li>Text models, like PaLM 2, offer different sizes (e.g., Bison, Gecko) and are optimized for various tasks and performance requirements.</li>
<li>Code models, for code generation and related tasks.</li>
<li>Chat models, optimized for conversational interactions.</li>
</ul>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="high-level-solution-components">High-level Solution Components<a href="https://opensource.salesforce.com/einstein-platform/vertex#high-level-solution-components" class="hash-link" aria-label="Direct link to High-level Solution Components" title="Direct link to High-level Solution Components">​</a></h2>
<ol>
<li>A fine-tuned Gemini model deployed on Vertex AI (required for the cookbook). An end user can use any model as-is from Model Garden for their use case.</li>
<li>A Cloud Run Function that serves as a middleware, handling authentication and request/response transformation.</li>
<li>Secret Manager for secure API key storage.</li>
<li>Salesforce Einstein Studio configuration for the LLM Open Connector.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="high-level-solution-flow">High-level Solution Flow<a href="https://opensource.salesforce.com/einstein-platform/vertex#high-level-solution-flow" class="hash-link" aria-label="Direct link to High-level Solution Flow" title="Direct link to High-level Solution Flow">​</a></h2>
<p>In this scenario, we will deploy a fine-tuned Gemini Model in Google Cloud Platform and leverage Cloud Run Functions to authenticate the Data Cloud Open LLM Connector and invoke the Vertex Model endpoint. This setup is for Agentforce chat completion.</p>
<p><img decoding="async" loading="lazy" alt="Vertex High Level Process" src="https://opensource.salesforce.com/einstein-platform/assets/images/vertex-llm-open-connector-workflow-2220a11bbafab1f72f37c38e34680bde.png" width="2142" height="1740" class="img_ev3q"></p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/vertex#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<p>Before beginning the implementation, review the following requirements.</p>
<ol>
<li>
<p>Google Cloud Account with appropriate permissions. Required project editor or equivalent roles.</p>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>If you’re new to Google Cloud, new customers get $300 in free credits to run, test, and deploy workloads as of 02/11/2025.</p></div></div>
</li>
<li>
<p>A Google Cloud project with billing enabled.</p>
<ul>
<li>On the project selector page in the Google Cloud console, select or create a Google Cloud project.</li>
<li>Ensure that billing is enabled for your Google Cloud project.</li>
</ul>
</li>
<li>
<p>Google Cloud SDK (gcloud CLI). For installation instructions, see <a href="https://cloud.google.com/sdk/docs/install-sdk" target="_blank" rel="noopener noreferrer">Install the gcloud CLI</a> and <a href="https://cloud.google.com/sdk/docs/initializing" target="_blank" rel="noopener noreferrer">Set up gcloud CLI</a>.</p>
</li>
<li>
<p>Python 3.9 or later.</p>
</li>
<li>
<p>Access to Vertex AI. You may need to enable the Vertex AI API in your project via the Google Cloud Console if it's not already enabled.</p>
</li>
<li>
<p>Enable all APIs required for this cookbook:</p>
<ul>
<li>Vertex AI API</li>
<li>Cloud Run API</li>
<li>Secret Manager API</li>
<li>Cloud Build API</li>
<li>Any additional APIs as required by Google Cloud UI.</li>
</ul>
</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="implementation-steps">Implementation Steps<a href="https://opensource.salesforce.com/einstein-platform/vertex#implementation-steps" class="hash-link" aria-label="Direct link to Implementation Steps" title="Direct link to Implementation Steps">​</a></h2>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="1-fine-tune-your-gemini-model">1. Fine-tune Your Gemini Model<a href="https://opensource.salesforce.com/einstein-platform/vertex#1-fine-tune-your-gemini-model" class="hash-link" aria-label="Direct link to 1. Fine-tune Your Gemini Model" title="Direct link to 1. Fine-tune Your Gemini Model">​</a></h3>
<p>Fine-tuning a Gemini model allows you to customize its responses for your specific use case. Here's how to set it up:</p>
<ol>
<li>
<p>Access Vertex AI Model Garden:</p>
<ul>
<li>Go to the Google Cloud Console.</li>
<li>Go to Vertex AI &gt; Model Garden.</li>
<li>Search for "Gemini".</li>
<li>Select "gemini-1.5-pro" (non-streaming version).</li>
</ul>
</li>
<li>
<p>Prepare your training data. The training data must be in JSONL format, with each line containing a complete conversation example. The following template represents the required structure:</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Your question here"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Expected response here"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
<p>Refer to the following test data sample:</p>
<div class="language-json codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-json codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Based on sensor data, what is the recommended maintenance interval for CNC Lathe Alpha?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"CNC Lathe Alpha should be maintained every 5 months, especially if sensor readings show vibration levels above 2.5 m/s² or temperatures exceeding 80°C."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"What maintenance schedule does CNC Milling Beta require according to the latest IoT data?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"CNC Milling Beta should be scheduled for maintenance every 6 months. Abnormal spindle temperatures above 85°C or increased vibrations may indicate the need for earlier service."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"From the IoT sensor analysis, what maintenance interval is recommended for Hydraulic Press Delta?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Hydraulic Press Delta is recommended to be maintained every 4 months. Sudden drops in hydraulic pressure or unexpected increases in acoustic emissions should prompt earlier service."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"According to sensor readings, how often should Robotic Arm Omega be serviced?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Robotic Arm Omega should be serviced every 7 months, with earlier checks if joint torque variability exceeds 10% or if motor temperatures spike unexpectedly."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"What maintenance interval does the sensor data suggest for Injection Molder Sigma?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Injection Molder Sigma should undergo maintenance every 8 months. Notable increases in heating element temperature or pressure fluctuations indicate the need for an earlier service."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Based on current IoT readings, what maintenance frequency is recommended for Conveyor Belt Gamma?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Conveyor Belt Gamma is best maintained every 3 months, especially if sensor data shows inconsistent belt speeds or abnormal motor vibrations."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"What does the IoT data recommend for the maintenance schedule of Packaging Machine Epsilon?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Packaging Machine Epsilon should be maintained every 6 months. Spikes in vibration levels or minor misalignments detected by sensors suggest that prompt maintenance may be necessary."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"How often should Press Brake Zeta be serviced according to sensor trends?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Press Brake Zeta should be serviced every 5 months. Consistent monitoring of force output and temperature is crucial; significant deviations indicate that earlier service might be required."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Based on sensor insights, what is the recommended maintenance interval for Laser Cutter Theta?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Laser Cutter Theta is recommended to be maintained every 4 months. Increases in ambient dust levels or fluctuations in laser power readings are critical indicators for timely maintenance."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token plain"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"contents"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"user"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"What maintenance schedule should be followed for Drilling Machine Kappa based on IoT data?"</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"role"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"model"</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token property" style="color:#36acaa">"parts"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">[</span><span class="token punctuation" style="color:#393A34">{</span><span class="token property" style="color:#36acaa">"text"</span><span class="token operator" style="color:#393A34">:</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"Drilling Machine Kappa should be maintained every 6 months, with special attention if there are sudden spikes in vibration or drilling temperature that may signal an urgent service need."</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><span class="token punctuation" style="color:#393A34">]</span><span class="token punctuation" style="color:#393A34">}</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
<li>
<p>Create and configure the tuning job:</p>
<ul>
<li>Go to Vertex AI → Training.</li>
<li>Click <strong>Create Training Job</strong>.</li>
<li>Select your fine-tuning dataset.</li>
<li>Configure the hyperparameters (start with defaults).</li>
<li>Start the training job.</li>
</ul>
</li>
<li>
<p>Deploy the fine-tuned model:</p>
<ul>
<li>After you complete training, go to the model in Vertex AI.</li>
<li>Click <strong>Deploy</strong>.</li>
<li>Select region (e.g., <code>us-central1</code>).</li>
<li>Store the following information. You'll need these values later.<!-- -->
<ul>
<li>Endpoint Name</li>
<li>Endpoint ID</li>
<li>Location</li>
<li>Project ID</li>
</ul>
</li>
</ul>
</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="2-create-and-configure-your-secrets-in-google-cloud">2. Create and Configure Your Secrets in Google Cloud<a href="https://opensource.salesforce.com/einstein-platform/vertex#2-create-and-configure-your-secrets-in-google-cloud" class="hash-link" aria-label="Direct link to 2. Create and Configure Your Secrets in Google Cloud" title="Direct link to 2. Create and Configure Your Secrets in Google Cloud">​</a></h3>
<p>The LLM Open Connector requires an API key for authentication. We'll store this securely in Google Cloud Secret Manager.</p>
<ol>
<li>
<p>Go to Secret Manager:</p>
<ul>
<li>Open Google Cloud Console.</li>
<li>Go to Security → Secret Manager</li>
<li>Click <strong>CREATE SECRET</strong>.</li>
</ul>
</li>
<li>
<p>Configure the secret:</p>
<ul>
<li>Name: <code>llm_connector_api_key</code></li>
<li>Upload a pre-generated API key — you'll need this when configuring your model in Salesforce.</li>
<li>Click <strong>CREATE SECRET</strong>.</li>
</ul>
<div class="theme-admonition theme-admonition-note admonition_xJq3 alert alert--secondary"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>note</div><div class="admonitionContent_BuS1"><p>For the cookbook, we set this key to never expire. GCP takes care of rotating the encryption key. However, a different Cloud Run function can be set to rotate the API key. When a new key is generated in GCP, the Open LLM Connector API key needs to be updated.</p></div></div>
</li>
<li>
<p>Verify the secret creation. You should see your secret listed in Secret Manager. The "Resource ID" will be in the format: <code>projects/{PROJECT_ID}/secrets/llm_connector_api_key</code>.</p>
</li>
<li>
<p>Configure IAM Permissions. Ensure your Cloud Run Function's service account has the following roles:</p>
<ul>
<li>Secret Manager Secret Accessor</li>
<li>Vertex AI User</li>
</ul>
</li>
</ol>
<p>We recommend creating a dedicated Cloud Run function service account. Provide all required permissions to this service account.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="3-implement-the-cloud-run-function">3. Implement the Cloud Run Function<a href="https://opensource.salesforce.com/einstein-platform/vertex#3-implement-the-cloud-run-function" class="hash-link" aria-label="Direct link to 3. Implement the Cloud Run Function" title="Direct link to 3. Implement the Cloud Run Function">​</a></h3>
<p>The Cloud Run Function serves as middleware between Salesforce and Vertex AI. Follow the steps to implement it. You can download asset files from the <a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-vertex" target="_blank" rel="noopener noreferrer">einstein-platform repo</a>.</p>
<ol>
<li>Create the Function Code with at least the minimum required settings.<!-- -->
<ul>
<li>Trigger type: HTTPS</li>
<li>Choose a dedicated service account that has access to the secrets.</li>
<li>Runtime python 3.10</li>
</ul>
</li>
<li>Configure environment variables:<!-- -->
<ul>
<li>Project ID</li>
<li>Location</li>
<li>Endpoint ID (fine-tuned model endpoint)</li>
</ul>
</li>
<li>Create a new directory for your function and add the following files:<!-- -->
<ul>
<li>main.py: <a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-vertex/openllmconnectormain.py" target="_blank" rel="noopener noreferrer"><code>openllmconnectormain.py</code></a></li>
<li><a href="https://github.com/salesforce/einstein-platform/tree/main/documentation/cookbook-assets/llm-open-connector-vertex/requirements.txt" target="_blank" rel="noopener noreferrer"><code>requirements.txt</code></a>:<!-- -->
<div class="language-txt codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-txt codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">functions-framework==3.*</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">google-cloud-aiplatform==1.*</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">google-cloud-secret-manager==2.*</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain">flask==2.*</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="Copy code to clipboard" title="Copy" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div>
</li>
</ul>
</li>
<li>Test and deploy the function.</li>
</ol>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="4-create-a-configured-model-in-salesforce">4. Create a Configured Model in Salesforce<a href="https://opensource.salesforce.com/einstein-platform/vertex#4-create-a-configured-model-in-salesforce" class="hash-link" aria-label="Direct link to 4. Create a Configured Model in Salesforce" title="Direct link to 4. Create a Configured Model in Salesforce">​</a></h3>
<ol>
<li>In your Salesforce Org, open Data Cloud.</li>
<li>Go to Einstein Studio, go to Model Builder.</li>
<li>Click <strong>New Configuration</strong>.</li>
<li>Select "LLM Open Connector".</li>
<li>Enter Configuration Details:<!-- -->
<ul>
<li>Endpoint URL: <code>https://{REGION}-{PROJECT_ID}.cloudfunctions.net/llm\_connector/chat/completions</code></li>
<li>Auth Header: api-key</li>
<li>Auth Key: <code>{VALUE_FROM_SECRET_MANAGER}</code></li>
<li>Model Name: <code>{FINETUNED_MODEL_NAME}</code></li>
</ul>
</li>
<li>After the connection is successful, select and test the fine-tuned model in Model Garden.</li>
<li>Adjust temperature settings and create a chat completions version for use in Salesforce.</li>
</ol>
<p>Congratulations! Your Vertex AI model is now ready to use!</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="see-also">See Also<a href="https://opensource.salesforce.com/einstein-platform/vertex#see-also" class="hash-link" aria-label="Direct link to See Also" title="Direct link to See Also">​</a></h2>
<ul>
<li><a href="https://opensource.salesforce.com/einstein-platform/aws">LLM Open Connector + AWS</a></li>
</ul>]]></content>
        <author>
            <name>Vasundra Srinivasan</name>
            <uri>https://github.com/vasundras</uri>
        </author>
        <category label="vertex" term="vertex"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
    <entry>
        <title type="html"><![CDATA[LLM Open Connector + Grok]]></title>
        <id>https://opensource.salesforce.com/einstein-platform/grok</id>
        <link href="https://opensource.salesforce.com/einstein-platform/grok"/>
        <updated>2025-08-20T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Learn how to implement Salesforce's LLM Open Connector with the xAI platform and Grok. This blog walks through generating an xAI API key and creating a configured model in Salesforce. No custom scripts or deployments are required.]]></summary>
        <content type="html"><![CDATA[<p>Learn how to implement Salesforce's <a href="https://opensource.salesforce.com/einstein-platform/docs/apis/llm-open-connector">LLM Open Connector</a> with the xAI platform and <a href="https://x.ai/news/grok-4" target="_blank" rel="noopener noreferrer">Grok</a>. This blog walks through generating an xAI API key and creating a configured model in Salesforce. No custom scripts or deployments are required.</p>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="prerequisites">Prerequisites<a href="https://opensource.salesforce.com/einstein-platform/grok#prerequisites" class="hash-link" aria-label="Direct link to Prerequisites" title="Direct link to Prerequisites">​</a></h2>
<ol>
<li>If you don't already have one, <a href="https://accounts.x.ai/sign-up" target="_blank" rel="noopener noreferrer">create an xAI account</a>.</li>
<li>Create a team in the <a href="https://console.x.ai/" target="_blank" rel="noopener noreferrer">xAI Cloud Console</a>.
<img decoding="async" loading="lazy" alt="xAI Cloud Console Landing Page" src="https://opensource.salesforce.com/einstein-platform/assets/images/xai-cloud-console-landing-page-506e934b29ccae4c88de44db1f83f4e9.png" width="3456" height="2162" class="img_ev3q"></li>
<li>Purchase some xAI API credits.</li>
<li>Create an API key.</li>
</ol>
<h2 class="anchor anchorWithStickyNavbar_LWe7" id="integrate-with-agentforce">Integrate with Agentforce<a href="https://opensource.salesforce.com/einstein-platform/grok#integrate-with-agentforce" class="hash-link" aria-label="Direct link to Integrate with Agentforce" title="Direct link to Integrate with Agentforce">​</a></h2>
<p>xAI is fully compatible with the Open Connector API specification, so you can follow the LLM Open Connector <a href="https://developer.salesforce.com/blogs/2024/10/build-generative-ai-solutions-with-llm-open-connector" target="_blank" rel="noopener noreferrer">product guide</a>. Follow the steps in this post for an overview.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-1-add-a-foundation-model">Step 1. Add a Foundation Model<a href="https://opensource.salesforce.com/einstein-platform/grok#step-1-add-a-foundation-model" class="hash-link" aria-label="Direct link to Step 1. Add a Foundation Model" title="Direct link to Step 1. Add a Foundation Model">​</a></h3>
<p>Navigate to Einstein Studio in Data Cloud.</p>
<p><img decoding="async" loading="lazy" alt="Agentforce Add Foundation Model" src="https://opensource.salesforce.com/einstein-platform/assets/images/agentforce-add-foundation-model-9d680482317f1486a0a5843db00f7198.png" width="1562" height="306" class="img_ev3q"></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-2-connect-your-llm">Step 2. Connect Your LLM<a href="https://opensource.salesforce.com/einstein-platform/grok#step-2-connect-your-llm" class="hash-link" aria-label="Direct link to Step 2. Connect Your LLM" title="Direct link to Step 2. Connect Your LLM">​</a></h3>
<p>Select the option to bring your own model.</p>
<p><img decoding="async" loading="lazy" alt="Agentforce Connect Your LLM" src="https://opensource.salesforce.com/einstein-platform/assets/images/agentforce-connect-your-llm-80761893d8265b54083b467ed1c2c24b.png" width="1539" height="1000" class="img_ev3q"></p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-3-enter-your-xai-api-key">Step 3. Enter Your xAI API Key<a href="https://opensource.salesforce.com/einstein-platform/grok#step-3-enter-your-xai-api-key" class="hash-link" aria-label="Direct link to Step 3. Enter Your xAI API Key" title="Direct link to Step 3. Enter Your xAI API Key">​</a></h3>
<p>Enter your xAI details to create a new model connection in Model Builder.</p>
<p><img decoding="async" loading="lazy" alt="Model Builder" src="https://opensource.salesforce.com/einstein-platform/assets/images/xai-grok-connection-8a478037c9ad7a76ec42e3ea990bbf41.png" width="1766" height="1156" class="img_ev3q"></p>
<ul>
<li>Add <code>https://api.x.ai/v1/chat/completions</code> to the <strong>URL</strong> field.</li>
<li>Add your API secret to the <strong>Auth Key</strong> field.</li>
<li>Add <code>grok-4</code> to the <strong>Model Name</strong> field.</li>
</ul>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-4-create-a-configured-model">Step 4. Create A Configured Model<a href="https://opensource.salesforce.com/einstein-platform/grok#step-4-create-a-configured-model" class="hash-link" aria-label="Direct link to Step 4. Create A Configured Model" title="Direct link to Step 4. Create A Configured Model">​</a></h3>
<p>Before you can use your connected model, you need to create a configured model. Select grok-4 in the Model Library and click <strong>New Configuration</strong>.</p>
<p><img decoding="async" loading="lazy" alt="Agentforce New Configuration" src="https://opensource.salesforce.com/einstein-platform/assets/images/xai-grok-configuration-81aedfcc002ef3a73eba9b3f62aafe88.png" width="2224" height="1152" class="img_ev3q"></p>
<p>Test your model in the the Model Playground. When you're ready, you can save your configuration and create the model for use in Salesforce.</p>
<h3 class="anchor anchorWithStickyNavbar_LWe7" id="step-5-start-using-grok">Step 5. Start Using Grok<a href="https://opensource.salesforce.com/einstein-platform/grok#step-5-start-using-grok" class="hash-link" aria-label="Direct link to Step 5. Start Using Grok" title="Direct link to Step 5. Start Using Grok">​</a></h3>
<p>You can now use <a href="https://x.ai/news/grok-4" target="_blank" rel="noopener noreferrer">Grok 4</a> via Salesforce's Open Connector! You can leverage Grok’s advanced reasoning in your Agentforce application to handle complex requests and streamline workflows.</p>
<p>To monitor consumption, purchase additional credits, and manage your Grok models, use the <a href="https://console.x.ai/" target="_blank" rel="noopener noreferrer">xAI Cloud console</a>.</p>]]></content>
        <author>
            <name>Brett Allen</name>
            <uri>https://github.com/brettallenyo</uri>
        </author>
        <category label="grok" term="grok"/>
        <category label="llm-open-connector" term="llm-open-connector"/>
    </entry>
</feed>