<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="331935" data-post-id="331935">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="joelpaulkoch" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joelpaulkoch/120/34540_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  joelpaulkoch
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You can set a secret <code>OPENAI_KEY</code> in livebook, then you must give your current livebook access to it in the secrets tab.<br>
After that you can get the secret with an <code>LB_</code> prefix and pass it to <code>ChatOpenAI.new!</code></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  api_key = System.get_env("LB_OPENAI_KEY") 

  %{
    llm:
      ChatOpenAI.new!(%{
        model: "gpt-4",
        api_key: api_key,
      })
  }
  |&gt; LLMChain.new!()
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="331935" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-331935" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="331935"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="331991" data-post-id="331991">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jszod" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jszod/120/3495_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jszod
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yeah I tried that exact same thing and for some reason the api_key in the map is always nil for some reason.</p>
<p>I can retrieve the key from the environment but when I set it in the map it’s nil for some reason</p>
<p>Thanks for the help I’ll continue to try to figure out what should be a very easy thing to do</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="331991" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-331991" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="331991"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="331998" data-post-id="331998">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jszod" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jszod/120/3495_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jszod
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Today with zero code changes it works! Shut down and restarted the server a few times, and now it’s good to go. Thanks for the help.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="331998" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-331998" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="331998"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="337166" data-post-id="337166">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bdarla" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bdarla/120/19471_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bdarla
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Amazing work! Many thanks to all contributors!</p>
<p>By combining this library with Ollama, I can transparently use the GPU of my MBP (Apple Silicon). Interacting with LLMs within Elixir applications becomes very efficient and local-only (I dislike reaching cloud services with sensitive context).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="337166" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-337166" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="337166"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="343032" data-post-id="343032">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="acrolink" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/acrolink/120/8985_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  acrolink
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Amazing work! Many thanks <a class="mention" href="/u/brainlid" rel="nofollow">@brainlid</a> and all contributors!</p>
<p>I am starting using this library, so far looks great. Have minor question, what be the best way to handle alternative logic based on user input? I mean in code? For example, in my application, different logic will be executed based if the user <em><strong>A. wants to order food</strong></em>, or <em><strong>B. wants to eat at restaurant.</strong></em></p>
<p>Also, how to provide it contextual data (actually data retrieved from tables in DB) based on user choices during the conversation? i.e. how to hook inside an ongoing chat and feed in DB data?</p>
<p>Thank you!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="343032" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-343032" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="343032"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="343079" data-post-id="343079">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="brainlid" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/brainlid/120/20975_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  brainlid
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <a class="mention" href="/u/acrolink" rel="nofollow">@acrolink</a>!</p>
<p>A <code>RoutingChain</code> is a good tool for changing how handle different contexts. It’s a basic prompt and chain that looks at the prompt and determines “Do they want to order food to be delivered? Or do they want to eat a restaurant?” The LLM looks at the prompt you provide and the user’s message to make the decision.</p>
<p>The result is to select a new, purpose built chain. You can then run the same message from the user on the selected chain.</p>
<p>To access databases, typically that’s done through a <code>Tool</code>. You define the tools (aka functions) that the LLM should have access to. If the LLM decides to call the tool, the library handles it and executes your Elixir code. Your function’s result is returned to the LLM for it to act on.</p>
<p>Have fun!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="343079" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-343079" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="343079"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="343139" data-post-id="343139">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="acrolink" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/acrolink/120/8985_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  acrolink
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/brainlid" rel="nofollow">@brainlid</a></p>
<p>I have tried to implement <code>RoutingChain</code> but failed. It would be nice if you could give me an idea how to do that in the context of this file:</p>
<p><a href="https://github.com/brainlid/langchain_demo/blob/main/lib/langchain_demo_web/live/agent_chat_live/index.ex" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/brainlid/langchain_demo/blob/main/lib/langchain_demo_web/live/agent_chat_live/index.ex</a></p>
<p>Thank you <img src="https://forum.elixirforum.com/images/emoji/apple/pray/2.png?v=15" title=":pray:t2:" class="emoji" alt=":pray:t2:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="343139" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-343139" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="343139"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="343144" data-post-id="343144">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="acrolink" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/acrolink/120/8985_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  acrolink
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/brainlid" rel="nofollow">@brainlid</a></p>
<p>Ok, I made some progress. The documentation needs to be updated to this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">    selected_route =
      RoutingChain.new!(%{
        llm: ChatOpenAI.new!(%{model: "gpt-4o-mini", stream: false}),
        input_text: "I need help with JAVA programming language",
        routes: routes,
        default_route: PromptRoute.new!(%{name: "DEFAULT", chain: llm_chain})
      })
      |&gt; RoutingChain.evaluate()
</code></pre>
<p>i.e. using <code>RoutingChain.new!</code> and <code>llm: ChatOpenAI.new!(..)</code></p>
<p>I have made it work and can think how to implement it before the chat starts, e.g. using buttons (click handlers) determining the <code>input_text</code> to provide for <code>RoutingChain.evaluate()</code>.</p>
<p>But would it be possible to do the routing inside an ongoing chat (changing the chain inside an ongoing chat)? If you can give me some direction that would be great. Thank you.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="343144" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-343144" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="343144"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="343676" data-post-id="343676">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="brainlid" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/brainlid/120/20975_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  brainlid
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <a class="mention" href="/u/acrolink" rel="nofollow">@acrolink</a>!</p>
<p>Thanks for the doc note.</p>
<blockquote>
<p>But would it be possible to do the routing inside an ongoing chat (changing the chain inside an ongoing chat)?</p>
</blockquote>
<p>The way I handle this is to manage the displayed chat separately from the one sent to the LLM. Just like we don’t want to display the system setup or other prompts to the user, those are sent to the LLM but not displayed to the user.</p>
<p>More advanced LLMs could handle a routing prompt inside a conversation, but the simpler LLMs cannot.</p>
<p>To me, it makes the most sense to perform the routing operation as a standalone chat with the LLM. Like you run it on the side, then use the result to define your next prompt. You don’t have to switch to another chain. You may only want the result of the LLM’s topic choice.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="343676" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-343676" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="343676"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="344498" data-post-id="344498">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="acrolink" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/acrolink/120/8985_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  acrolink
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/brainlid" rel="nofollow">@brainlid</a></p>
<p>I have a question, I actually need your advice if this is feasible:</p>
<p>Do you think the logic inside this file (in the demo):<br>
<a href="https://github.com/brainlid/langchain_demo/blob/main/lib/langchain_demo_web/live/agent_chat_live/index.ex" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/brainlid/langchain_demo/blob/main/lib/langchain_demo_web/live/agent_chat_live/index.ex</a></p>
<p>Can it be re-written using Phoenix channels? Do you think the whole <code>LiveView</code> code can be replaced by Phoenix channels and Dart code (on a flutter mobile application) - I mean to write the chat interface natively in Flutter using <a href="https://pub.dev/packages/phoenix_socket" class="inline-onebox" rel="noopener nofollow ugc">phoenix_socket | Dart package</a> ?</p>
<p>I am not sure how to expose the <code>display_messages</code> array to Flutter .. Or is it that the <a href="https://pub.dev/packages/phoenix_socket" class="inline-onebox" rel="noopener nofollow ugc">phoenix_socket | Dart package</a> has limited functionality, for this end?</p>
<p>Thank you.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="344498" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/langchain-an-elixir-langchain-like-library-for-integrating-with-llms-like-chatgpt/58551/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-344498" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="344498"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/58551/load_more?page=3">Load more posts (38 remaining)</a>
</div></template></turbo-stream>