In this tutorial, you’ll learn to build a simple chatbot in Python that utilizes Anaconda Desktop’s OpenAI-compatible API server to process natural language queries. You will use conda to establish a working environment to develop the chatbot, build the chatbot application using the OpenAI Python library, and interact with the chatbot at the command line.Prerequisites
Before you begin, ensure that you have the conda installed on your machine. You can install conda by downloading either Anaconda Distribution or Miniconda.
You must have a text-generation type model downloaded onto your local machine. Walk through the Getting started with Anaconda Desktop guide before you begin the tutorial.
Setting up your environment
When working on a new conda project, it is recommended that you create a new environment for development. Follow these steps to set up an environment for your chatbot:
Open (Terminal on macOS/Linux).
This terminal can be opened from within an (JupyterLab, PyCharm, VS Code, Spyder), if preferred.
Create the for your chatbot development and install the packages you’ll need by running the following command:
conda create --name chataconda python openai
Activate your newly created conda environment by running the following command:
conda activate chataconda
For more information and best practices for managing environments, see Environments.
Building the chatbot
Below, you’ll find the necessary code to build your chatbot, along with an explanation of each section to help you understand the functionality of the code.Using your preferred IDE, create a new file on your machine, and name it chatter-max.py.
Importing libraries
The application uses the OpenAI Python library to communicate with the API server. We’ll import the necessary modules for making API calls and handling errors.Make this the first line of code in your chatter-max.py file:
from openai import OpenAI, APIError, APIConnectionError
Setting the base_url
In order for your application to programmatically process natural language inputs to generate responses and perform other actions, it is crucial that you properly structure your application to interact with the API server.The base_url can be constructed by combining the Server Address and Server Port specified in Anaconda Desktop, like this: http://<SERVER_ADDRESS>:<SERVER_PORT>.Set the base_url to point to the default server address by adding the following line to your file.
base_url = 'http://localhost:8080'
localhost and 127.0.0.1 are semantically identical.
Adding the API calls
The OpenAI chat completions API is the main endpoint you’ll use to interact with your model. For a full list of API endpoints and detailed information, see the OpenAI Chat Completions API documentation.To enable your application to communicate with the API server, you need to implement a function that makes the chat completion API call.
Creating the completion function
To interact with the model, you need a function that sends messages to the chat completion endpoint and receives responses. This function handles the API call and error management.The messages parameter is a list of conversation messages, where each message has a role (system, user, or assistant) and content. This format allows the model to understand the full context of the conversation.The parameters in client.chat.completions.create() control how the AI model generates responses. These parameters dictate the model’s behavior during the completion process.The stop parameter specifies tokens that tell the model when to stop generating text. The tokens <|im_end|> and <|im_start|> are special control markers used by the ChatML chat template to denote message boundaries. By including these as stop tokens, you prevent the model from accidentally generating these markers in its response, which could confuse the conversation structure or cause the model to generate both sides of the conversation.Add the following lines to your chatter-max.py file:
def get_completion(client, messages): """Send messages to the chat completion API and return the response.""" try: response = client.chat.completions.create( model="", messages=messages, temperature=0.8, top_p=0.95, max_completion_tokens=400, stop=["<|im_end|>", "<|im_start|>"] ) return response.choices[0].message.content.strip(), True except APIConnectionError as e: return f"Connection error: {e}", False except APIError as e: return f"API error: {e}", False
The model parameter can be left empty when using Anaconda Desktop’s API server, as the model is already loaded on the server.
Constructing the main function
The main function initiates the chatbot, handles user inputs, and manages the flow of the conversation. This is where you set the initial system prompt that defines the assistant’s behavior.
Play around with the system prompt to see how it impacts the responses you receive from your model!If you set an API key value on the Model Servers page in Anaconda Desktop, you can pass it to the OpenAI client by replacing the empty string in the api_key parameter. Otherwise, leave it as an empty string to skip authentication.
Add the following lines to your chatter-max.py file:
def main(): """Run the interactive chatbot loop.""" client = OpenAI(base_url=base_url, api_key="") system_prompt = ('You are a friendly AI assistant designed to provide ' 'helpful, succinct, and accurate information.') messages = [{'role': 'system', 'content': system_prompt}] print(f"Connected to: {base_url}") while True: user_input = input("Enter a prompt or type 'exit' to quit: ") if user_input.lower() == 'exit': break messages.append({'role': 'user', 'content': user_input}) assistant_response, success = get_completion(client, messages) print('Assistant:', assistant_response) if success: messages.append({'role': 'assistant', 'content': assistant_response}) else: messages.pop()if __name__ == "__main__": main()
Running the chatbot
With your chatbot constructed, it’s time to take your model for a test run!
In your terminal (with the chataconda environment activated), navigate to the directory where you stored your chatter-max.py file.
Initiate the chatbot by running the following command:
python chatter-max.py
If everything is set up correctly, you’ll see a confirmation message showing the connected URL, and you can start chatting with your model.
Make sure the API server is running in Anaconda Desktop before running your chatbot. If the server isn’t running, you’ll see a connection error.
Having some fun with the model
Try adjusting the following parameters in the get_completion() function to see how they affect the output from the model.
Visit OpenAI’s official documentation for additional available parameters. Note that some parameters might not be supported by all available models on Anaconda Desktop.
temperature
Adjusting the temperature of your model can increase or decrease the randomness of the responses you receive from your prompts. Higher values (example 2.0) make the output more creative and varied. Lower values (example 0.2) make the output more deterministic and focused. Valid range is 0.0 to 2.0. Defaults to 0.8.
top_p
Limits token selection to a subset of tokens with a cumulative probability above a threshold to balance creativity with coherence. Higher values (closer to 1.0) allow the model to provide more creative responses, and lower values enhance focus. Valid range is 0.0 to 1.0. Adjust top_p to see how it affects the model’s descriptiveness for the same prompt. Defaults to 0.95.
max_completion_tokens
Controls the maximum number of tokens the model can generate in its response. One token is roughly equivalent to 4 characters or 0.75 words in English. Increasing this value allows for longer responses, while decreasing it keeps responses more concise. Defaults to 400.
frequency_penalty
Reduces the likelihood of the model repeating the same words or phrases. Higher values (up to 2.0) make the model avoid repetition more strongly, while lower or negative values allow more repetition. Valid range is -2.0 to 2.0. Defaults to 0.0.
presence_penalty
Encourages the model to introduce new topics rather than continuing with existing ones. Higher values (up to 2.0) push the model to be more exploratory, while lower values allow it to stay on topic. Valid range is -2.0 to 2.0. Defaults to 0.0.
Next steps
You can continue to develop and extend this chatbot by adding features like conversation history persistence, multi-turn context management, or integration with other tools. When you’re done, you can delete this file and clean up your conda environment by running the following command:
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Anaconda","description":"Guides, tutorials, and reference material for Anaconda's Python, data science, and AI tools","colors":{"primary":"#1d6cf7","light":"#1d6cf7","dark":"#96f778"},"logo":{"light":"https://mintcdn.com/anaconda-29683c67/s-9WR15r5rZoaPqb/logo/light.svg?fit=max\u0026auto=format\u0026n=s-9WR15r5rZoaPqb\u0026q=85\u0026s=5996719b8530aaf065dc1ee1f39b2e67","dark":"https://mintcdn.com/anaconda-29683c67/s-9WR15r5rZoaPqb/logo/dark.svg?fit=max\u0026auto=format\u0026n=s-9WR15r5rZoaPqb\u0026q=85\u0026s=db482b1eac6af589d234160a76de3400","href":"https://www.anaconda.com/docs/main"},"favicon":"https://mintcdn.com/anaconda-29683c67/p8JNFuYYvTL8gfpM/favicon.png?fit=max\u0026auto=format\u0026n=p8JNFuYYvTL8gfpM\u0026q=85\u0026s=51a585758330bbe8f1ea032113854252","api":{"playground":{"display":"simple"}},"background":{"color":{"light":"#F7F8F9","dark":"#10121a"}},"navbar":{},"footer":{"socials":{"linkedin":"https://www.linkedin.com/company/anacondainc","github":"https://github.com/ContinuumIO","youtube":"https://www.youtube.com/c/ContinuumIo"},"links":[{"header":"Company","items":[{"label":"Anaconda Newsletter","href":"https://www.anaconda.com/newsletter"}]}]},"seo":{"metatags":{"canonical":"https://www.anaconda.com/docs"}},"styling":{"eyebrows":"breadcrumbs","latex":false},"integrations":{"ga4":{"measurementId":"G-VQTY6YKM6J"},"heap":{"appId":"758475466"}},"contextual":{"options":["claude","chatgpt","perplexity","cursor","vscode","add-mcp","copy"],"display":"header"},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"anaconda-29683c67","hasAudioNarration":false,"actualSubdomain":"anaconda-29683c67","customDomains":["anaconda.com"],"gitSource":{"type":"github","owner":"anaconda","repo":"documentation","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true,"contextualFeedback":{"allowEmail":true,"emailDisclaimer":"Your email will only be used to follow up on this feedback."}},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"REMOVE_BRANDING":{"status":"ENABLED"},"CONTEXTUAL_FEEDBACK":{"status":"ENABLED"},"CODE_SNIPPET_FEEDBACK":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6b00649f6c736afc6845f454","clientVersion":"0.0.4286","searchFilterCounts":[{"language":"default","tag":"Data Science \u0026 AI Workbench","count":240},{"language":"default","tag":"Package Security Manager","count":152},{"language":"default","tag":"Anaconda Platform","count":152},{"language":"default","tag":"Anaconda CLI","count":126},{"language":"default","tag":"Guides","count":105},{"language":"default","tag":"Platform Guides","count":86},{"language":"default","tag":"Package Security Manager (On-prem)","count":85},{"language":"default","tag":"Package Security Manager (6.8.0)","count":85},{"language":"default","tag":"Anaconda Desktop","count":82},{"language":"default","tag":"Anaconda CLI \u0026 MCP","count":79}],"searchSettings":{"isFiltersEnabled":true}},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":true,"enableContextualStarterQuestions":true,"deflection":{"enabled":true,"email":"support@anaconda.com"}},"basePath":"/docs","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"custom.css","href":"/docs/_mintlify/custom/anaconda-29683c67/68c5081e7d29c6a7/custom.css"}]}
{"page":{"pagePath":"anaconda-desktop/tutorials/chatbot-tutorial","slug":"/anaconda-desktop/tutorials/chatbot-tutorial","pageMetadata":{"title":"Developing a chatbot","searchDescription":"Tutorial for developing a chatbot with Anaconda Desktop.","keywords":["chatbot","development","tutorial","natural language","ai","model","anaconda desktop"],"description":null,"href":"/anaconda-desktop/tutorials/chatbot-tutorial"},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];const __snippet_BANNER_SIZES_1a1vhaj={sm:`px-4 py-2 text-sm gap-2`,md:`px-4 py-3 text-sm gap-3`,lg:`px-4 py-4 text-base gap-3`};const __snippet_BANNER_ICON_SIZES_1a1vhaj={sm:`h-4 w-4`,md:`h-4 w-4`,lg:`h-5 w-5`};const __snippet_BANNER_ICON_PATHS_1a1vhaj={info:`M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24v-64H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z`,success:`M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9z`,warning:`M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 0 40.1S493.4 480 479.2 480H32.8c-14.2 0-27.3-7.5-34.5-19.8s-7.3-27.7 0-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24v112c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0-64 0 32 32 0 1 0 64 0z`,danger:`M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM175 175c9.4-9.4 24.6-9.4 33.9 0l47 47 47-47c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9l-47 47 47 47c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0l-47-47-47 47c-9.4 9.4-24.6 9.4-33.9 0s-9.4-24.6 0-33.9l47-47-47-47c-9.4-9.4-9.4-24.6 0-33.9z`};const __snippet_BANNER_STORAGE_PREFIX_1a1vhaj=`anaconda-banner-dismissed:`;const __snippet_getBannerStorageKey_1a1vhaj=banner=>{const content=banner.querySelector(`.anaconda-page-banner-content`)||banner;const text=(content.textContent||``).replace(/\\s+/g,` `).trim();let hash=5381;for(let i=0;i\u003ctext.length;i+=1){hash=(hash\u003c\u003c5)+hash+text.charCodeAt(i)|0}return`${__snippet_BANNER_STORAGE_PREFIX_1a1vhaj}${(hash>>>0).toString(36)}`};const __snippet_readBannerDismissed_1a1vhaj=key=>{try{return window.sessionStorage.getItem(key)===`true`}catch(error){return false}};const __snippet_writeBannerDismissed_1a1vhaj=key=>{try{window.sessionStorage.setItem(key,`true`)}catch(error){}};const Banner=({children,variant=`info`,size=`md`,dismissible=true,icon=true,className=``})=>{const[dismissed,setDismissed]=React.useState(false);const slotRef=React.useRef(null);const bannerRef=React.useRef(null);const storageKeyRef=React.useRef(null);const handleDismiss=()=>{setDismissed(true);if(storageKeyRef.current)__snippet_writeBannerDismissed_1a1vhaj(storageKeyRef.current)};React.useEffect(()=>{const banner=bannerRef.current;const slot=slotRef.current;if(!banner)return undefined;storageKeyRef.current=__snippet_getBannerStorageKey_1a1vhaj(banner);if(dismissible\u0026\u0026__snippet_readBannerDismissed_1a1vhaj(storageKeyRef.current)){setDismissed(true);return undefined}const navbar=document.getElementById(`navbar`);if(!navbar||!navbar.parentNode){banner.setAttribute(`data-banner-placement`,`inline`);return undefined}navbar.parentNode.insertBefore(banner,navbar.nextSibling);banner.setAttribute(`data-banner-placement`,`top`);const root=document.documentElement;const syncHeights=()=>{root.style.setProperty(`--anaconda-navbar-height`,`${navbar.offsetHeight}px`);root.style.setProperty(`--anaconda-banner-height`,`${banner.offsetHeight}px`)};syncHeights();const observer=typeof ResizeObserver!==`undefined`?new ResizeObserver(syncHeights):null;if(observer){observer.observe(navbar);observer.observe(banner)}return()=>{if(observer)observer.disconnect();root.style.removeProperty(`--anaconda-navbar-height`);root.style.removeProperty(`--anaconda-banner-height`);if(slot\u0026\u0026banner.parentNode!==slot){slot.appendChild(banner)}}},[]);const variantKey=__snippet_BANNER_ICON_PATHS_1a1vhaj[variant]?variant:`info`;const sizeClasses=__snippet_BANNER_SIZES_1a1vhaj[size]||__snippet_BANNER_SIZES_1a1vhaj.md;const iconClasses=__snippet_BANNER_ICON_SIZES_1a1vhaj[size]||__snippet_BANNER_ICON_SIZES_1a1vhaj.md;return _jsx(`div`,{ref:slotRef,className:`anaconda-page-banner-slot`,children:_jsx(`div`,{ref:bannerRef,role:variantKey===`danger`?`alert`:`status`,\"data-banner-variant\":variantKey,\"data-banner-dismissed\":dismissed?`true`:undefined,className:`anaconda-page-banner not-prose ${className}`,children:_jsxs(`div`,{className:`anaconda-page-banner-inner mint-flex mint-items-start ${sizeClasses}`,children:[icon\u0026\u0026_jsx(`span`,{className:`anaconda-page-banner-icon mint-shrink-0 mint-mt-0.5 ${iconClasses}`,children:_jsx(`svg`,{viewBox:`0 0 512 512`,fill:`currentColor`,className:`mint-h-full mint-w-full`,\"aria-hidden\":`true`,children:_jsx(`path`,{d:__snippet_BANNER_ICON_PATHS_1a1vhaj[variantKey]})})}),_jsx(`div`,{className:`anaconda-page-banner-content mint-min-w-0 mint-flex-1`,children}),dismissible\u0026\u0026_jsx(`button`,{type:`button`,onClick:handleDismiss,\"aria-label\":`Dismiss banner`,className:`anaconda-page-banner-dismiss mint-shrink-0 mint--mr-1 mint-rounded-md mint-p-1 mint-text-current mint-opacity-70 mint-transition-opacity hover:mint-opacity-100 focus-visible:mint-outline focus-visible:mint-outline-2 focus-visible:mint-outline-offset-2 focus-visible:mint-outline-current`,children:_jsx(`svg`,{viewBox:`0 0 384 512`,fill:`currentColor`,className:`mint-h-3.5 mint-w-3.5`,\"aria-hidden\":`true`,children:_jsx(`path`,{d:`M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z`})})})]})})})};function _createMdxContent(props){const _components={a:`a`,code:`code`,hr:`hr`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Tip,Tooltip,Warning,_MdxComponentBoundary}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Tooltip)_missingMdxReference(`Tooltip`,true);if(!Warning)_missingMdxReference(`Warning`,true);if(!_MdxComponentBoundary)_missingMdxReference(`_MdxComponentBoundary`,true);return _jsxs(_Fragment,{children:[_jsx(_MdxComponentBoundary,{name:`Banner`,children:_jsx(Banner,{variant:`info`,children:_jsxs(_components.p,{children:[`Anaconda Desktop is transitioning to `,_jsx(_components.a,{href:`https://kilo.ai/install`,children:`Kilo Desktop`}),`! Get started with `,_jsx(_components.a,{href:`https://kilo.ai/install`,children:`Kilo Desktop`}),` for agentic AI coding, interactive notebooks, and built-in conda environment management.`]})})}),`\n`,_jsx(_components.p,{children:`In this tutorial, you’ll learn to build a simple chatbot in Python that utilizes Anaconda Desktop’s OpenAI-compatible API server to process natural language queries. You will use conda to establish a working environment to develop the chatbot, build the chatbot application using the OpenAI Python library, and interact with the chatbot at the command line.`}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`Prerequisites`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`Before you begin, ensure that you have the conda `,_jsx(Tooltip,{tip:`A collection of software tools that automates the process of installing, updating, configuring, and removing packages. Also known as a package management system.`,children:`package manager`}),` installed on your machine. You can install `,_jsx(_components.code,{children:`conda`}),` by downloading either `,_jsx(_components.a,{href:`/getting-started/concepts/anaconda-or-miniconda`,children:`Anaconda Distribution or Miniconda`}),`.`]}),`\n`,_jsxs(_components.li,{children:[`You must have a `,_jsx(_components.code,{children:`text-generation`}),` type model downloaded onto your local machine. Walk through the `,_jsx(_components.a,{href:`/anaconda-desktop/getting-started-desktop`,children:`Getting started with Anaconda Desktop`}),` guide before you begin the tutorial.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`setting-up-your-environment`,children:`Setting up your environment`}),`\n`,_jsx(_components.p,{children:`When working on a new conda project, it is recommended that you create a new environment for development. Follow these steps to set up an environment for your chatbot:`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[`Open `,_jsx(Tooltip,{tip:`A command-line application included with Windows installations of Anaconda Distribution and Miniconda. Find it by searching 'Anaconda Prompt' in the Windows Start menu.`,children:`Anaconda Prompt`}),` (Terminal on macOS/Linux).`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`This terminal can be opened from within an `,_jsx(Tooltip,{tip:`An interactive development environment. A suite of software tools that combines everything a developer needs to write and test software.`,children:`IDE`}),` (JupyterLab, PyCharm, VS Code, Spyder), if preferred.`]})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[`Create the `,_jsx(Tooltip,{tip:`An isolated folder containing specific conda packages and dependencies that won't interfere with other projects. Each environment maintains its own versions of libraries and packages, so changes in one environment don't affect others.`,children:`conda environment`}),` for your chatbot development and install the packages you’ll need by running the following command:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`conda`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` create`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --name`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` chataconda`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` python`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` openai`})]}),`\n`]})})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_components.p,{children:`Activate your newly created conda environment by running the following command:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`conda`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` activate`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` chataconda`})]}),`\n`]})})}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`For more information and best practices for managing environments, see `,_jsx(_components.a,{href:`/getting-started/working-with-conda/environments`,children:`Environments`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`building-the-chatbot`,children:`Building the chatbot`}),`\n`,_jsx(_components.p,{children:`Below, you’ll find the necessary code to build your chatbot, along with an explanation of each section to help you understand the functionality of the code.`}),`\n`,_jsxs(_components.p,{children:[`Using your preferred IDE, create a new file on your machine, and name it `,_jsx(_components.code,{children:`chatter-max.py`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`importing-libraries`,children:`Importing libraries`}),`\n`,_jsx(_components.p,{children:`The application uses the OpenAI Python library to communicate with the API server. We’ll import the necessary modules for making API calls and handling errors.`}),`\n`,_jsxs(_components.p,{children:[`Make this the first line of code in your `,_jsx(_components.code,{children:`chatter-max.py`}),` file:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openai `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenAI, APIError, APIConnectionError`})]}),`\n`]})})}),`\n`,_jsxs(Heading,{level:`3`,id:`setting-the-base_url`,children:[`Setting the `,_jsx(_components.code,{children:`base_url`})]}),`\n`,_jsx(_components.p,{children:`In order for your application to programmatically process natural language inputs to generate responses and perform other actions, it is crucial that you properly structure your application to interact with the API server.`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`base_url`}),` can be constructed by combining the `,_jsx(_components.strong,{children:`Server Address`}),` and `,_jsx(_components.strong,{children:`Server Port`}),` specified in Anaconda Desktop, like this: `,_jsx(_components.code,{children:`http://\u003cSERVER_ADDRESS>:\u003cSERVER_PORT>`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`Set the `,_jsx(_components.code,{children:`base_url`}),` to point to the default server address by adding the following line to your file.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`base_url `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'http://localhost:8080'`})]}),`\n`]})})}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`localhost`}),` and `,_jsx(_components.code,{children:`127.0.0.1`}),` are semantically identical.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`adding-the-api-calls`,children:`Adding the API calls`}),`\n`,_jsxs(_components.p,{children:[`The OpenAI chat completions API is the main endpoint you’ll use to interact with your model. For a full list of API endpoints and detailed information, see the `,_jsx(_components.a,{href:`https://developers.openai.com/api/reference/chat-completions/overview`,children:`OpenAI Chat Completions API documentation`}),`.`]}),`\n`,_jsx(_components.p,{children:`To enable your application to communicate with the API server, you need to implement a function that makes the chat completion API call.`}),`\n`,_jsx(Heading,{level:`4`,id:`creating-the-completion-function`,children:`Creating the completion function`}),`\n`,_jsx(_components.p,{children:`To interact with the model, you need a function that sends messages to the chat completion endpoint and receives responses. This function handles the API call and error management.`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`messages`}),` parameter is a list of conversation messages, where each message has a `,_jsx(_components.code,{children:`role`}),` (system, user, or assistant) and `,_jsx(_components.code,{children:`content`}),`. This format allows the model to understand the full context of the conversation.`]}),`\n`,_jsxs(_components.p,{children:[`The parameters in `,_jsx(_components.code,{children:`client.chat.completions.create()`}),` control how the AI model generates responses. These parameters dictate the model’s behavior during the completion process.`]}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`stop`}),` parameter specifies tokens that tell the model when to stop generating text. The tokens `,_jsx(_components.code,{children:`\u003c|im_end|>`}),` and `,_jsx(_components.code,{children:`\u003c|im_start|>`}),` are special control markers used by the ChatML chat template to denote message boundaries. By including these as stop tokens, you prevent the model from accidentally generating these markers in its response, which could confuse the conversation structure or cause the model to generate both sides of the conversation.`]}),`\n`,_jsxs(_components.p,{children:[`Add the following lines to your `,_jsx(_components.code,{children:`chatter-max.py`}),` file:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`16`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`16`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` get_completion`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`messages`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"\"Send messages to the chat completion API and return the response.\"\"\"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.chat.completions.create(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` messages`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`messages,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` temperature`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0.8`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` top_p`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0.95`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` max_completion_tokens`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`400`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` stop`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\u003c|im_end|>\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\u003c|im_start|>\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` )`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.choices[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].message.content.strip(), `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` except`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` APIConnectionError `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` e:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Connection error: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`e`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`False`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` except`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` APIError `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`as`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` e:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"API error: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`e`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`False`})]}),`\n`]})})}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`model`}),` parameter can be left empty when using Anaconda Desktop’s API server, as the model is already loaded on the server.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`constructing-the-main-function`,children:`Constructing the main function`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`main`}),` function initiates the chatbot, handles user inputs, and manages the flow of the conversation. This is where you set the initial system prompt that defines the assistant’s behavior.`]}),`\n`,_jsxs(Tip,{children:[_jsx(_components.p,{children:`Play around with the system prompt to see how it impacts the responses you receive from your model!`}),_jsx(_components.hr,{}),_jsxs(_components.p,{children:[`If you set an API key value on the `,_jsx(_components.strong,{children:`Model Servers`}),` page in Anaconda Desktop, you can pass it to the OpenAI client by replacing the empty string in the `,_jsx(_components.code,{children:`api_key`}),` parameter. Otherwise, leave it as an empty string to skip authentication.`]})]}),`\n`,_jsxs(_components.p,{children:[`Add the following lines to your `,_jsx(_components.code,{children:`chatter-max.py`}),` file:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`27`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`27`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` main`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`():`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"\"\"Run the interactive chatbot loop.\"\"\"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenAI(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`base_url, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` system_prompt `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'You are a friendly AI assistant designed to provide '`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'helpful, succinct, and accurate information.'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` messages `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [{`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'role'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'system'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: system_prompt}]`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Connected to: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`{`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` while`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` user_input `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` input`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Enter a prompt or type 'exit' to quit: \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` user_input.lower() `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'exit'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` break`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` messages.append({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'role'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'user'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: user_input})`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` assistant_response, success `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` get_completion(client, messages)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'Assistant:'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, assistant_response)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` success:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` messages.append({`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'role'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'assistant'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'content'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: assistant_response})`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` else`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` messages.pop()`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:` __name__`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ==`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"__main__\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` main()`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`running-the-chatbot`,children:`Running the chatbot`}),`\n`,_jsx(_components.p,{children:`With your chatbot constructed, it’s time to take your model for a test run!`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[`Open Anaconda Desktop and `,_jsx(_components.a,{href:`/anaconda-desktop/servers#creating-a-server`,children:`create and start a model server`}),`. Leave the `,_jsx(_components.strong,{children:`Server Address`}),` and `,_jsx(_components.strong,{children:`Server Port`}),` at the default values.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[`In your terminal (with the `,_jsx(_components.code,{children:`chataconda`}),` environment activated), navigate to the directory where you stored your `,_jsx(_components.code,{children:`chatter-max.py`}),` file.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_components.p,{children:`Initiate the chatbot by running the following command:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`python`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` chatter-max.py`})]}),`\n`]})})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsx(_components.p,{children:`If everything is set up correctly, you’ll see a confirmation message showing the connected URL, and you can start chatting with your model.`}),`\n`]}),`\n`]}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`Make sure the API server is running in Anaconda Desktop before running your chatbot. If the server isn’t running, you’ll see a connection error.`})}),`\n`,_jsx(Heading,{level:`2`,id:`having-some-fun-with-the-model`,children:`Having some fun with the model`}),`\n`,_jsxs(_components.p,{children:[`Try adjusting the following parameters in the `,_jsx(_components.code,{children:`get_completion()`}),` function to see how they affect the output from the model.`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`Visit OpenAI’s `,_jsx(_components.a,{href:`https://developers.openai.com/api/reference/chat-completions/overview`,children:`official documentation`}),` for additional available parameters. Note that some parameters might not be supported by all available models on Anaconda Desktop.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`temperature`,children:_jsx(_components.code,{children:`temperature`})}),`\n`,_jsxs(_components.p,{children:[`Adjusting the temperature of your model can increase or decrease the randomness of the responses you receive from your prompts. Higher values (example `,_jsx(_components.code,{children:`2.0`}),`) make the output more creative and varied. Lower values (example `,_jsx(_components.code,{children:`0.2`}),`) make the output more deterministic and focused. Valid range is `,_jsx(_components.code,{children:`0.0`}),` to `,_jsx(_components.code,{children:`2.0`}),`. Defaults to `,_jsx(_components.code,{children:`0.8`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`top_p`,children:_jsx(_components.code,{children:`top_p`})}),`\n`,_jsxs(_components.p,{children:[`Limits token selection to a subset of tokens with a cumulative probability above a threshold to balance creativity with coherence. Higher values (closer to `,_jsx(_components.code,{children:`1.0`}),`) allow the model to provide more creative responses, and lower values enhance focus. Valid range is `,_jsx(_components.code,{children:`0.0`}),` to `,_jsx(_components.code,{children:`1.0`}),`. Adjust `,_jsx(_components.code,{children:`top_p`}),` to see how it affects the model’s descriptiveness for the same prompt. Defaults to `,_jsx(_components.code,{children:`0.95`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`max_completion_tokens`,children:_jsx(_components.code,{children:`max_completion_tokens`})}),`\n`,_jsxs(_components.p,{children:[`Controls the maximum number of tokens the model can generate in its response. One token is roughly equivalent to 4 characters or 0.75 words in English. Increasing this value allows for longer responses, while decreasing it keeps responses more concise. Defaults to `,_jsx(_components.code,{children:`400`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`frequency_penalty`,children:_jsx(_components.code,{children:`frequency_penalty`})}),`\n`,_jsxs(_components.p,{children:[`Reduces the likelihood of the model repeating the same words or phrases. Higher values (up to `,_jsx(_components.code,{children:`2.0`}),`) make the model avoid repetition more strongly, while lower or negative values allow more repetition. Valid range is `,_jsx(_components.code,{children:`-2.0`}),` to `,_jsx(_components.code,{children:`2.0`}),`. Defaults to `,_jsx(_components.code,{children:`0.0`}),`.`]}),`\n`,_jsx(Heading,{level:`3`,id:`presence_penalty`,children:_jsx(_components.code,{children:`presence_penalty`})}),`\n`,_jsxs(_components.p,{children:[`Encourages the model to introduce new topics rather than continuing with existing ones. Higher values (up to `,_jsx(_components.code,{children:`2.0`}),`) push the model to be more exploratory, while lower values allow it to stay on topic. Valid range is `,_jsx(_components.code,{children:`-2.0`}),` to `,_jsx(_components.code,{children:`2.0`}),`. Defaults to `,_jsx(_components.code,{children:`0.0`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`next-steps`,children:`Next steps`}),`\n`,_jsx(_components.p,{children:`You can continue to develop and extend this chatbot by adding features like conversation history persistence, multi-turn context management, or integration with other tools. When you’re done, you can delete this file and clean up your conda environment by running the following command:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`conda`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` deactivate`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`conda`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` remove`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --name`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` chataconda`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --all`})]}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{__snippet_BANNER_SIZES_1a1vhaj,__snippet_BANNER_ICON_SIZES_1a1vhaj,__snippet_BANNER_ICON_PATHS_1a1vhaj,__snippet_BANNER_STORAGE_PREFIX_1a1vhaj,__snippet_getBannerStorageKey_1a1vhaj,__snippet_readBannerDismissed_1a1vhaj,__snippet_writeBannerDismissed_1a1vhaj,Banner,default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Developing a chatbot","searchDescription":"Tutorial for developing a chatbot with Anaconda Desktop.","keywords":["chatbot","development","tutorial","natural language","ai","model","anaconda desktop"],"description":null,"href":"/anaconda-desktop/tutorials/chatbot-tutorial"}}},"mdxSourceWithNoJs":null,"noJsSplices":[[165,1460,"undefined;const __snippet_BANNER_ICON_SIZES_1a1vhaj=undefined;const __snippet_BANNER_ICON_PATHS_1a1vhaj=undefined;const "],[1500,2024,"undefined;const __snippet_getBannerStorageKey_1a1vhaj=()=>null;const __snippet_readBannerDismissed_1a1vhaj=()=>null;cons"],[2065,5559,"()=>null;const Banner=()=>null;function "]]},"mdxExtracts":{"tableOfContents":[{"title":"Setting up your environment","slug":"setting-up-your-environment","depth":2,"children":[]},{"title":"Building the chatbot","slug":"building-the-chatbot","depth":2,"children":[{"title":"Importing libraries","slug":"importing-libraries","depth":3,"children":[]},{"title":"Setting the base_url","slug":"setting-the-base_url","depth":3,"children":[]},{"title":"Adding the API calls","slug":"adding-the-api-calls","depth":3,"children":[]},{"title":"Creating the completion function","slug":"creating-the-completion-function","depth":4,"children":[]},{"title":"Constructing the main function","slug":"constructing-the-main-function","depth":3,"children":[]}]},{"title":"Running the chatbot","slug":"running-the-chatbot","depth":2,"children":[]},{"title":"Having some fun with the model","slug":"having-some-fun-with-the-model","depth":2,"children":[{"title":"temperature","slug":"temperature","depth":3,"children":[]},{"title":"top_p","slug":"top_p","depth":3,"children":[]},{"title":"max_completion_tokens","slug":"max_completion_tokens","depth":3,"children":[]},{"title":"frequency_penalty","slug":"frequency_penalty","depth":3,"children":[]},{"title":"presence_penalty","slug":"presence_penalty","depth":3,"children":[]}]},{"title":"Next steps","slug":"next-steps","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/docs/_mintlify/custom/anaconda-29683c67/b738e1eb47e9934c/_transcend.js","/docs/_mintlify/custom/anaconda-29683c67/3ca111da84ffed5d/docs-dropdown-tooltip.js","/docs/_mintlify/custom/anaconda-29683c67/a3d1c2dd97aa6593/toc-indicator.js"],"dynamicCss":".mint--mr-1 {\n margin-right: -0.25rem\n}\n.mint-mt-0\\.5 {\n margin-top: 0.125rem\n}\n.mint-flex {\n display: flex\n}\n.mint-h-3\\.5 {\n height: 0.875rem\n}\n.mint-h-full {\n height: 100%\n}\n.mint-w-3\\.5 {\n width: 0.875rem\n}\n.mint-w-full {\n width: 100%\n}\n.mint-min-w-0 {\n min-width: 0px\n}\n.mint-flex-1 {\n flex: 1 1 0%\n}\n.mint-shrink-0 {\n flex-shrink: 0\n}\n.mint-items-start {\n align-items: flex-start\n}\n.mint-rounded-md {\n border-radius: 0.375rem\n}\n.mint-p-1 {\n padding: 0.25rem\n}\n.mint-text-current {\n color: currentColor\n}\n.mint-opacity-70 {\n opacity: 0.7\n}\n.mint-transition-opacity {\n transition-property: opacity;\n transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);\n transition-duration: 150ms\n}\n.hover\\:mint-opacity-100:hover {\n opacity: 1\n}\n.focus-visible\\:mint-outline:focus-visible {\n outline-style: solid\n}\n.focus-visible\\:mint-outline-2:focus-visible {\n outline-width: 2px\n}\n.focus-visible\\:mint-outline-offset-2:focus-visible {\n outline-offset: 2px\n}\n.focus-visible\\:mint-outline-current:focus-visible {\n outline-color: currentColor\n}","subdomain":"anaconda-29683c67","siteName":"Anaconda","title":"Developing a chatbot - Anaconda","contextualStarterQuestions":[{"_id":"6af60d5d4e8bc908169b79b6","deploymentId":"6781700c5f1e7d2ac00fcc4a","questionText":"How do I integrate chatbot features?","status":"active","generatedBy":"contextual","path":"anaconda-desktop/tutorials/chatbot-tutorial","createdAt":"2026-11-12T19:02:53.470Z","updatedAt":"2026-11-12T19:02:53.470Z","__v":0},{"_id":"6af60d5d4e8bc908169b79b5","deploymentId":"6781700c5f1e7d2ac00fcc4a","questionText":"How do I start building a chatbot?","status":"active","generatedBy":"contextual","path":"anaconda-desktop/tutorials/chatbot-tutorial","createdAt":"2026-11-12T19:02:53.470Z","updatedAt":"2026-11-12T19:02:53.470Z","__v":0}],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{},"searchTabScopes":[{"product":"Getting Started","tab":"About Anaconda"},{"product":"Getting Started","tab":"Installation"},{"product":"Getting Started","tab":"Getting started guides"},{"product":"Getting Started","tab":"Working with conda"},{"product":"Package Security Manager","tab":"Package Security Manager (Cloud)"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.8.0"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.7.2"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.7.1"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.7.0"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.6.5"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.6.4"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.6.3"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.6.2"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.6.1"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.6.0"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.5.3"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.5.2"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.5.1"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.4.0"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.3.1"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.3.0"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.2.0"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.1.9"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.1.8"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.1.7"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.1.6"},{"product":"Package Security Manager","tab":"Package Security Manager (On-prem)","version":"6.1.4"},{"product":"Anaconda Platform","tab":"Guides"},{"product":"Anaconda Platform","tab":"Tutorials"},{"product":"Anaconda Platform","tab":"CLI Reference"},{"product":"Anaconda CLI \u0026 MCP","tab":"Anaconda CLI"},{"product":"Anaconda CLI \u0026 MCP","tab":"Anaconda MCP"},{"product":"Legacy applications","tab":"Anaconda Navigator"},{"product":"Legacy applications","tab":"Anaconda Toolbox Excel Add-in"}]},"lastModified":"2026-11-12T18:58:19.139Z","originalFileLocation":"anaconda-desktop/tutorials/chatbot-tutorial.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"application-name\" content=\"Anaconda\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Developing a chatbot - Anaconda\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Anaconda\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://anaconda-29683c67.mintlify.site/docs/_mintlify/api/og/v2?division=Tutorials\u0026amp;title=Developing+a+chatbot\u0026amp;theme=7f7b55efd41022d147e41c35\u0026amp;signature=6b5dadb2fc46389e1decb5e80c2375067d36f7a12919045d7e39ca065a801c7b\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Developing a chatbot - Anaconda\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://anaconda-29683c67.mintlify.site/docs/_mintlify/api/og/v2?division=Tutorials\u0026amp;title=Developing+a+chatbot\u0026amp;theme=7f7b55efd41022d147e41c35\u0026amp;signature=6b5dadb2fc46389e1decb5e80c2375067d36f7a12919045d7e39ca065a801c7b\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/docs/mintlify-assets/_mintlify/favicons/anaconda-29683c67/Q6mS5k5M0lNdBscF/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Anaconda\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#1d6cf7\">\u003clink data-mint-head rel=\"canonical\" href=\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/anaconda-desktop/tutorials/chatbot-tutorial.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://www.anaconda.com/#organization\",\"name\":\"Anaconda\",\"url\":\"https://www.anaconda.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/anaconda-29683c67/s-9WR15r5rZoaPqb/logo/light.svg?fit=max\u0026auto=format\u0026n=s-9WR15r5rZoaPqb\u0026q=85\u0026s=5996719b8530aaf065dc1ee1f39b2e67\"}},{\"@type\":\"WebSite\",\"@id\":\"https://www.anaconda.com/docs#website\",\"name\":\"Anaconda\",\"url\":\"https://www.anaconda.com/docs\",\"publisher\":{\"@id\":\"https://www.anaconda.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial#webpage\",\"url\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial\",\"name\":\"Developing a chatbot\",\"dateModified\":\"2026-11-12T18:58:19.139Z\",\"isPartOf\":{\"@id\":\"https://www.anaconda.com/docs#website\"},\"breadcrumb\":{\"@id\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Anaconda Desktop\",\"item\":\"https://www.anaconda.com/docs/anaconda-desktop/key-features\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Developing a chatbot\",\"item\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial#article\",\"headline\":\"Developing a chatbot\",\"name\":\"Developing a chatbot\",\"url\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial\",\"mainEntityOfPage\":{\"@id\":\"https://www.anaconda.com/docs/anaconda-desktop/tutorials/chatbot-tutorial#webpage\"},\"dateModified\":\"2026-11-12T18:58:19.139Z\",\"keywords\":\"chatbot, development, tutorial, natural language, ai, model, anaconda desktop\",\"publisher\":{\"@id\":\"https://www.anaconda.com/#organization\"},\"isPartOf\":{\"@id\":\"https://www.anaconda.com/docs#website\"}}]}\u003c/script>","agentPointerHref":"/docs/anaconda-desktop/tutorials/chatbot-tutorial.md","siteName":"Anaconda","nav":{"global":null,"products":[{"product":"Anaconda Docs","icon":"https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/anaconda-icon.svg","pages":[{"title":"Anaconda Docs","href":"/main"}]},{"product":"Getting Started","icon":"rocket-launch","pages":[{"title":"Getting Started","href":"/getting-started/main"}]},{"product":"Anaconda.org","icon":"globe","pages":[{"title":"Anaconda.org","href":"/anaconda-org/key-features"}]},{"product":"Anaconda Desktop","icon":"desktop","groups":[{"group":"Anaconda Desktop","tag":"Beta","pages":[{"title":"Anaconda Desktop","sidebarTitle":"Key features","href":"/anaconda-desktop/key-features"},{"title":"Getting started with Anaconda Desktop","sidebarTitle":"Getting started","href":"/anaconda-desktop/getting-started-desktop"},{"title":"Environments","href":"/anaconda-desktop/environments"},{"title":"Packages","href":"/anaconda-desktop/packages"},{"title":"Channels","href":"/anaconda-desktop/channels"},{"title":"Model catalog","href":"/anaconda-desktop/model-catalog"},{"title":"Application catalog","href":"/anaconda-desktop/application-catalog"},{"title":"AI Models","href":"/anaconda-desktop/models"},{"title":"Chat","href":"/anaconda-desktop/chat"},{"title":"Model servers","href":"/anaconda-desktop/servers"},{"group":"Agent Studio","root":{"title":"Anaconda Agent Studio","sidebarTitle":"Agent Studio","tag":"Beta","href":"/anaconda-desktop/agent-studio/main"},"tag":"Beta","pages":[{"title":"Anaconda Assistant","sidebarTitle":"Anaconda Assistant","href":"/anaconda-desktop/agent-studio/anaconda-assistant"},{"title":"Agents","href":"/anaconda-desktop/agent-studio/agents"},{"title":"Configuring AI providers","sidebarTitle":"AI providers","href":"/anaconda-desktop/agent-studio/ai-providers"},{"title":"Plugins","sidebarTitle":"Plugins","href":"/anaconda-desktop/agent-studio/plugins"},{"title":"Skills","sidebarTitle":"Skills","href":"/anaconda-desktop/agent-studio/skills"},{"title":"Tool servers","sidebarTitle":"Tool servers","href":"/anaconda-desktop/agent-studio/tool-servers"},{"title":"Settings","sidebarTitle":"Settings","href":"/anaconda-desktop/agent-studio/settings"}]},{"title":"Anaconda MCP","sidebarTitle":"Anaconda MCP","tag":"Beta","href":"/anaconda-desktop/mcp"},{"title":"Anaconda Assistant","sidebarTitle":"Anaconda Assistant","tag":"Beta","href":"/anaconda-desktop/anaconda-assistant"},{"title":"Resource consumption","href":"/anaconda-desktop/resource-consumption"},{"title":"Settings","href":"/anaconda-desktop/settings"},{"group":"Desktop API","root":{"title":"Anaconda Desktop API","sidebarTitle":"Getting started","href":"/anaconda-desktop/desktop-api/getting-started"},"pages":[{"group":"Models","pages":[{"title":"Check the health of the models API","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /api/models/health","href":"/api-reference/models/check-the-health-of-the-models-api"},{"title":"Get all models","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /api/models","href":"/api-reference/models/get-all-models"},{"title":"Get model details by ID","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /api/models/{id}","href":"/api-reference/models/get-model-details-by-id"},{"title":"List all files for a specific model","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /models/{modelId}/files","href":"/api-reference/models/list-all-files-for-a-specific-model"},{"title":"Get details of a specific model file","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /api/models/{modelId}/files/{fileId}","href":"/api-reference/models/get-details-of-a-specific-model-file"},{"title":"Delete a model file","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json delete /api/models/{modelId}/files/{fileId}","href":"/api-reference/models/delete-a-model-file"},{"title":"Update download status of a model file","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json patch /api/models/{modelId}/files/{fileId}","href":"/api-reference/models/update-download-status-of-a-model-file"}]},{"group":"Servers","pages":[{"title":"Check the health of the servers API","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /api/servers/health","href":"/api-reference/servers/check-the-health-of-the-servers-api"},{"title":"Get all servers","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /api/servers","href":"/api-reference/servers/get-all-servers"},{"title":"Create a new server","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json post /api/servers","href":"/api-reference/servers/create-a-new-server"},{"title":"Get server details by ID","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json get /api/servers/{serverId}","href":"/api-reference/servers/get-server-details-by-id"},{"title":"Delete a server","deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json delete /api/servers/{serverId}","href":"/api-reference/servers/delete-a-server"},{"title":"Control server state (start/stop)","description":null,"deprecated":null,"version":null,"openapi":"/api-reference/desktop-api.json patch /api/servers/{serverId}","href":"/api-reference/servers/control-server-state-startstop"}]}]},{"group":"Tutorials","pages":[{"title":"Developing a chatbot","href":"/anaconda-desktop/tutorials/chatbot-tutorial"},{"title":"Comparing text using embeddings","description":null,"href":"/anaconda-desktop/tutorials/embedding-tutorial"},{"title":"Crafting effective system prompts","href":"/anaconda-desktop/tutorials/system-prompt"}]},{"group":"Resources","pages":[{"title":"Frequently asked questions","href":"/anaconda-desktop/resources/faq"},{"title":"Security practices","href":"/anaconda-desktop/resources/desktop-security"},{"title":"Release notes","href":"/anaconda-desktop/resources/release-notes"}]},{"title":"Uninstalling Desktop","href":"/anaconda-desktop/uninstall-desktop"}]}]},{"product":"Package Security Manager","icon":"shield-check","versions":[{"version":"6.8.0"},{"version":"6.7.2"},{"version":"6.7.1"},{"version":"6.7.0"},{"version":"6.6.5"},{"version":"6.6.4"},{"version":"6.6.3"},{"version":"6.6.2"},{"version":"6.6.1"},{"version":"6.6.0"},{"version":"6.5.3"},{"version":"6.5.2"},{"version":"6.5.1"},{"version":"6.4.0"},{"version":"6.3.1"},{"version":"6.3.0"},{"version":"6.2.0"},{"version":"6.1.9"},{"version":"6.1.8"},{"version":"6.1.7"},{"version":"6.1.6"},{"version":"6.1.4"}],"pages":[{"title":"Package Security Manager","href":"/anaconda-platform/main"}]},{"product":"Anaconda Platform","icon":"layer-group","pages":[{"title":"Anaconda Platform","href":"/platform/main"}]},{"product":"Data Science \u0026 AI Workbench","icon":"chart-network","versions":[{"version":"5.9.0"},{"version":"5.8.1"},{"version":"5.8.0"},{"version":"5.7.1"},{"version":"5.7.0"},{"version":"5.6.2"},{"version":"5.6.1"},{"version":"5.6.0"},{"version":"5.5.2"},{"version":"5.5.1"}],"pages":[{"title":"Data Science \u0026 AI Workbench","href":"/data-science/latest/main"}]},{"product":"Anaconda CLI \u0026 MCP","icon":"terminal","pages":[{"title":"Anaconda CLI \u0026 MCP","href":"/cli-reference/anaconda-cli/getting-started"}]},{"product":"Legacy applications","icon":"window-restore","pages":[{"title":"Legacy applications","href":"/legacy/anaconda-navigator/main"}]},{"product":"Reference","icon":"book","pages":[{"title":"Reference","href":"/reference/release-notes"}]},{"product":"Support \u0026 Troubleshooting","icon":"headset","pages":[{"title":"Support \u0026 Troubleshooting","href":"/reference/help-support"}]},{"product":"Repository Managers","hidden":true,"pages":[{"title":"Repository Managers","href":"/repo-managers/main"}]}]},"basePath":"","title":"Developing a chatbot - Anaconda","deploymentId":"dpl_3DZuqjnfdjREuPshghHhyiLeMG3U","buildId":"dpl_3DZuqjnfdjREuPshghHhyiLeMG3U","dynamics":[],"chunks":[]}