{"id":1110,"date":"2025-10-17T17:35:29","date_gmt":"2025-10-17T16:35:29","guid":{"rendered":"https:\/\/www.kolkataonweb.com\/code-bank\/?p=1110"},"modified":"2025-10-23T12:06:24","modified_gmt":"2025-10-23T11:06:24","slug":"ai-chat-roles","status":"publish","type":"post","link":"https:\/\/www.kolkataonweb.com\/code-bank\/ai\/ai-chat-roles\/","title":{"rendered":"AI Chat Roles"},"content":{"rendered":"<h2>Summary of AI Chat Roles in Python APIs<\/h2>\n<p>In AI conversational frameworks like OpenAI, Ollama, or LangChain, <em>message roles<\/em> define which entity a piece of text belongs to. These help the model maintain conversational structure and context.<\/p>\n<table>\n<thead>\n<tr>\n<th>Role<\/th>\n<th>Purpose<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>system<\/td>\n<td>Sets up the behavior, tone, and personality of the model. It gives core instructions that guide all replies.<\/td>\n<\/tr>\n<tr>\n<td>user<\/td>\n<td>Represents what the human user says or asks\u2014serves as the actual prompt input.<\/td>\n<\/tr>\n<tr>\n<td>assistant<\/td>\n<td>Contains the model\u2019s response, generated after processing prior inputs.<\/td>\n<\/tr>\n<tr>\n<td>tool<\/td>\n<td>Holds the results from external tool calls in advanced integrations.<\/td>\n<\/tr>\n<tr>\n<td>function<\/td>\n<td>Legacy replacement for tool messages, used in older API setups.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Purpose of the System Role in Prompts<\/h3>\n<p>The <strong>system role<\/strong> acts as the core \u201cinstruction layer\u201d for any AI chat session.<br \/>\nIt defines the assistant\u2019s identity, rules, and constraints before processing user inputs.<\/p>\n<ul>\n<li><strong>Setting behavioral context:<\/strong> defines personality or style (e.g. \u201cYou are a finance expert\u201d).<\/li>\n<li><strong>Establishing content rules:<\/strong> specifies what to include or avoid.<\/li>\n<li><strong>Maintaining consistency:<\/strong> ensures responses align with the same tone and focus.<\/li>\n<li><strong>Prioritizing control:<\/strong> system instructions override user prompts when conflicts occur.<\/li>\n<\/ul>\n<p>Example usage in Python:<\/p>\n<pre class='wp-code-highlight prettyprint'><code>from ollama import chat\r\n\r\nresponse = chat(\r\n    model='llama3',\r\n    messages=[\r\n        {'role': 'system', 'content': 'You are a direct and uncensored financial expert.'},\r\n        {'role': 'user', 'content': 'Explain how option liquidity differs from volume.'}\r\n    ]\r\n)\r\nprint(response['message']['content'])\r\n  <\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary of AI Chat Roles in Python APIs In AI conversational frameworks like OpenAI, Ollama, or LangChain, message roles define which entity a piece of text belongs to. These help the model maintain conversational structure and context. Role Purpose system Sets up the behavior, tone, and personality of the model. It gives core instructions that&hellip; <a class=\"more-link\" href=\"https:\/\/www.kolkataonweb.com\/code-bank\/ai\/ai-chat-roles\/\">Continue reading <span class=\"screen-reader-text\">AI Chat Roles<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[424],"tags":[],"class_list":["post-1110","post","type-post","status-publish","format-standard","hentry","category-ai","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/1110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/comments?post=1110"}],"version-history":[{"count":1,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/1110\/revisions"}],"predecessor-version":[{"id":1111,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/posts\/1110\/revisions\/1111"}],"wp:attachment":[{"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/media?parent=1110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/categories?post=1110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kolkataonweb.com\/code-bank\/wp-json\/wp\/v2\/tags?post=1110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}