{"id":90669,"date":"2024-12-31T15:17:43","date_gmt":"2024-12-31T11:47:43","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/%d9%81%d8%b1%d8%a7%d8%ae%d9%88%d8%a7%d9%86%db%8c-langchain-%d8%a7%d8%b2-go-%d9%82%d8%b3%d9%85%d8%aa-1\/"},"modified":"2024-12-31T15:17:43","modified_gmt":"2024-12-31T11:47:43","slug":"%d9%81%d8%b1%d8%a7%d8%ae%d9%88%d8%a7%d9%86%db%8c-langchain-%d8%a7%d8%b2-go-%d9%82%d8%b3%d9%85%d8%aa-1","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/%d9%81%d8%b1%d8%a7%d8%ae%d9%88%d8%a7%d9%86%db%8c-langchain-%d8%a7%d8%b2-go-%d9%82%d8%b3%d9%85%d8%aa-1\/","title":{"rendered":"\u0641\u0631\u0627\u062e\u0648\u0627\u0646\u06cc LangChain \u0627\u0632 Go (\u0642\u0633\u0645\u062a 1)"},"content":{"rendered":"<div data-article-id=\"2183133\" id=\"article-body\">\n<p><img decoding=\"async\" src=\"https:\/\/media2.dev.to\/dynamic\/image\/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto\/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F29r0rmz89z4y9sed23ij.png\" alt=\"\u062a\u0648\u0636\u06cc\u062d\u0627\u062a \u062a\u0635\u0648\u06cc\u0631\" loading=\"lazy\" width=\"800\" height=\"467\" title=\"\"><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter-rtl ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u0641\u0647\u0631\u0633\u062a \u0645\u0637\u0627\u0644\u0628<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"\u062a\u063a\u06cc\u06cc\u0631 \u0648\u0636\u0639\u06cc\u062a \u0641\u0647\u0631\u0633\u062a \u0645\u0637\u0627\u0644\u0628\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/nabfollower.com\/blog\/%d9%81%d8%b1%d8%a7%d8%ae%d9%88%d8%a7%d9%86%db%8c-langchain-%d8%a7%d8%b2-go-%d9%82%d8%b3%d9%85%d8%aa-1\/#%D8%A7%D9%86%DA%AF%DB%8C%D8%B2%D9%87\" >\u0627\u0646\u06af\u06cc\u0632\u0647<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/nabfollower.com\/blog\/%d9%81%d8%b1%d8%a7%d8%ae%d9%88%d8%a7%d9%86%db%8c-langchain-%d8%a7%d8%b2-go-%d9%82%d8%b3%d9%85%d8%aa-1\/#%D9%BE%DB%8C%D8%A7%D8%AF%D9%87_%D8%B3%D8%A7%D8%B2%DB%8C\" >\u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/nabfollower.com\/blog\/%d9%81%d8%b1%d8%a7%d8%ae%d9%88%d8%a7%d9%86%db%8c-langchain-%d8%a7%d8%b2-go-%d9%82%d8%b3%d9%85%d8%aa-1\/#%D9%85%D8%B1%D8%A7%D8%AD%D9%84_%D8%A8%D8%B9%D8%AF%DB%8C\" >\u0645\u0631\u0627\u062d\u0644 \u0628\u0639\u062f\u06cc<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/nabfollower.com\/blog\/%d9%81%d8%b1%d8%a7%d8%ae%d9%88%d8%a7%d9%86%db%8c-langchain-%d8%a7%d8%b2-go-%d9%82%d8%b3%d9%85%d8%aa-1\/#%D9%86%D8%AA%DB%8C%D8%AC%D9%87_%DA%AF%DB%8C%D8%B1%DB%8C\" >\u0646\u062a\u06cc\u062c\u0647 \u06af\u06cc\u0631\u06cc<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%D8%A7%D9%86%DA%AF%DB%8C%D8%B2%D9%87\"><\/span>\n<p>  \u0627\u0646\u06af\u06cc\u0632\u0647<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u0628\u0647 \u062f\u0646\u0628\u0627\u0644 \u0622\u0632\u0645\u0627\u06cc\u0634\u200c\u0647\u0627\u06cc \u00ab\u062a\u0639\u0637\u06cc\u0644\u0627\u062a\u00bb (\u067e\u0633\u062a\u200c\u0647\u0627\u06cc \u0642\u0628\u0644\u06cc&#8230;) \u062f\u0631 \u0645\u0648\u0631\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 Golang \u0648 LLM\u060c \u0628\u0647 \u062f\u0646\u0628\u0627\u0644 \u0631\u0627\u0647\u06cc \u0622\u0633\u0627\u0646 \u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647\u200c\u0633\u0627\u0632\u06cc \u062a\u0645\u0627\u0633 LangChain \u062f\u0631 Go \u0648 \u062a\u0631\u062c\u06cc\u062d\u0627\u064b \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0622\u0646 \u0628\u0648\u062f\u0645. <strong>watsonx.ai<\/strong>.<\/p>\n<p>\u062e\u0648\u0634\u0628\u062e\u062a\u0627\u0646\u0647 \u0645\u0646 \u0645\u062e\u0632\u0646 Github \u0632\u06cc\u0631 \u0631\u0627 \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062f\u0645: https:\/\/github.com\/tmc\/langchaingo (\u0628\u0647 \u062a\u0631\u0627\u0648\u06cc\u0633 \u06a9\u0644\u06cc\u0646 https:\/\/github.com\/tmc).<\/p>\n<p>\u062f\u0631 \u0645\u062e\u0632\u0646 \u0627\u0648\u060c \u0627\u06cc\u0646 \u067e\u0648\u0634\u0647 \u062e\u0627\u0635 \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f: https:\/\/github.com\/tmc\/langchaingo\/blob\/main\/examples\/watsonx-llm-example\/watsonx_example.go \u06a9\u0647 \u062a\u0648\u062c\u0647 \u0645\u0646 \u0631\u0627 \u0628\u0647 \u062e\u0648\u062f \u062c\u0644\u0628 \u06a9\u0631\u062f!<\/p>\n<p>\u0628\u0646\u0627\u0628\u0631\u0627\u06cc\u0646 \u0637\u0628\u0642 \u0645\u0639\u0645\u0648\u0644 \u06cc\u06a9 \u067e\u0631\u0648\u0698\u0647 \u0633\u0627\u062e\u062a\u0645 \u0648 \u0633\u0639\u06cc \u06a9\u0631\u062f\u0645 \u0622\u0646 \u0631\u0627 \u067e\u06cc\u0627\u062f\u0647 \u06a9\u0646\u0645 \u0648 \u0647\u0645\u0686\u0646\u06cc\u0646 \u0627\u06cc\u062f\u0647 \u0647\u0627\u06cc \u062e\u0648\u062f\u0645 \u0631\u0627 \u0642\u0631\u0627\u0631 \u062f\u0627\u062f\u0645 (\u0622\u0645\u0627 \u0633\u0633 \ud83d\ude04).<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%D9%BE%DB%8C%D8%A7%D8%AF%D9%87_%D8%B3%D8%A7%D8%B2%DB%8C\"><\/span>\n<p>  \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u0637\u0628\u0642 \u0645\u0639\u0645\u0648\u0644 \u0637\u0628\u0642 \u0646\u06cc\u0627\u0632 \u0628\u0647 \u0645\u062a\u063a\u06cc\u0631\u0647\u0627\u06cc \u0645\u062d\u06cc\u0637\u06cc\u060c \u0645\u0646 \u06cc\u06a9 \u0631\u0627 \u0631\u0627\u0647 \u0627\u0646\u062f\u0627\u0632\u06cc \u06a9\u0631\u062f\u0645 <strong>env<\/strong> \u0641\u0627\u06cc\u0644\u06cc \u06a9\u0647 \u0628\u0639\u062f\u0627\u064b \u062f\u0631 \u0628\u0631\u0646\u0627\u0645\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f.<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>export WATSONX_API_KEY=\"your-watsonx-api-key\"\nexport WATSONX_PROJECT_ID=\"your-watsonx-projectid\"\n# I used the US-SOUTH, could be any other region of IBM Cloud\nexport SERVICE_URL=\"https:\/\/us-south.ml.cloud.ibm.com\" \n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u062f\u0631 \u067e\u0633\u062a \u0642\u0628\u0644\u06cc \u0628\u0647 \u062a\u0644\u0627\u0634 \u0628\u0631\u0627\u06cc \u0634\u0645\u0627\u0631\u0634 \u062a\u0639\u062f\u0627\u062f \u062a\u0648\u06a9\u0646 \u0647\u0627\u06cc \u0627\u0631\u0633\u0627\u0644 \u0634\u062f\u0647 \u0648 \u062f\u0631\u06cc\u0627\u0641\u062a \u0634\u062f\u0647 \u0627\u0632 \u06cc\u06a9 LLM \u0627\u0634\u0627\u0631\u0647 \u06a9\u0631\u062f\u0645. \u0622\u0646 \u06a9\u0627\u0631 \u0647\u0646\u0648\u0632 WIP \u0627\u0633\u062a\u060c \u0628\u0646\u0627\u0628\u0631\u0627\u06cc\u0646 \u0645\u0646 \u0645\u0633\u062a\u0642\u06cc\u0645\u0627\u064b \u0627\u0632 &#8221; \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f\u0645<strong>tiktoken-go<\/strong>\u201d \u06a9\u062a\u0627\u0628\u062e\u0627\u0646\u0647 \u062f\u0627\u062e\u0644 \u0628\u0631\u0646\u0627\u0645\u0647 \u0645\u0646 \u0628\u0627 \u0627\u06cc\u062f\u0647 \u0627\u06cc\u062c\u0627\u062f \u0628\u0631\u062e\u06cc \u062a\u063a\u06cc\u06cc\u0631\u0627\u062a \u062f\u0631 \u0622\u0646 (\u062f\u0631 \u0622\u06cc\u0646\u062f\u0647 \u0627\u06cc \u0646\u0632\u062f\u06cc\u06a9\u061f). \u0628\u0647 \u0647\u0631 \u062d\u0627\u0644\u060c \u062f\u0631 \u0645\u0648\u0631\u062f \u0648\u0636\u0639\u06cc\u062a \u0641\u0639\u0644\u06cc \u067e\u06cc\u0634\u0631\u0641\u062a \u0645\u0646 \u0648\u0627\u0642\u0639\u0627\u064b \u06a9\u0627\u0631 \u0646\u0645\u06cc \u06a9\u0646\u062f\u060c \u0627\u0645\u0627 \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f.<\/p>\n<p>\u0628\u0631\u0627\u06cc \u0628\u0631\u0646\u0627\u0645\u0647 \u0628\u0647 \u062a\u0646\u0647\u0627\u06cc\u06cc\u060c \u0645\u0646 \u0627\u0632 \u06a9\u062f \u062a\u0631\u0627\u0648\u06cc\u0633 \u0627\u0632 \u0645\u062e\u0632\u0646 \u0627\u0648 \u062a\u0642\u0631\u06cc\u0628\u0627\u064b \u0647\u0645\u0627\u0646\u0637\u0648\u0631 \u06a9\u0647 \u0647\u0633\u062a \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f\u0645 \u0648 \u0622\u0646 \u0631\u0627 \u0628\u0627 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0632\u06cc\u0631 \u0627\u0636\u0627\u0641\u0647 \u0648 \u067e\u06cc\u0686\u06cc\u062f\u0647 \u06a9\u0631\u062f\u0645.<\/p>\n<ul>\n<li>\u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u06cc\u06a9 \u06a9\u0627\u062f\u0631 \u0645\u062d\u0627\u0648\u0631\u0647 \u0627\u06cc \u0628\u0631\u0627\u06cc \u0648\u0631\u0648\u062f\u06cc \u0633\u0631\u06cc\u0639 (\ud83d\ude44 \u0645\u0646 \u0639\u0627\u0634\u0642 \u062c\u0639\u0628\u0647 \u0647\u0627\u06cc \u06af\u0641\u062a\u06af\u0648 \u0647\u0633\u062a\u0645 \ud83d\ude02)<\/li>\n<li>&#8220;<strong>\u062a\u0644\u0627\u0634<\/strong>\u0628\u0631\u0627\u06cc \u0634\u0645\u0627\u0631\u0634 \u062a\u0639\u062f\u0627\u062f \u00ab\u062a\u0648\u06a9\u0646\u200c\u0647\u0627\u06cc\u00bb \u0627\u0631\u0633\u0627\u0644 \u0634\u062f\u0647 \u0648 \u062f\u0631\u06cc\u0627\u0641\u062a\u06cc \u0627\u0632 LLM. \u06a9\u062f \u0628\u0647 \u062e\u0648\u062f\u06cc \u062e\u0648\u062f \u0628\u0647 \u0634\u0631\u062d \u0632\u06cc\u0631 \u0627\u0633\u062a\u061b\n<\/li>\n<\/ul>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>package main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n    \"os\"\n    \"os\/exec\"\n    \"runtime\"\n\n    \"fyne.io\/fyne\/v2\"\n    \"fyne.io\/fyne\/v2\/app\"\n    \"fyne.io\/fyne\/v2\/container\"\n    \"fyne.io\/fyne\/v2\/dialog\"\n    \"fyne.io\/fyne\/v2\/widget\"\n\n    \"github.com\/joho\/godotenv\"\n    \"github.com\/pkoukk\/tiktoken-go\"\n    \"github.com\/tmc\/langchaingo\/llms\"\n    \"github.com\/tmc\/langchaingo\/llms\/watsonx\"\n)\n\nconst (\n    _tokenApproximation = 4\n)\n\nconst (\n    _gpt35TurboContextSize   = 4096\n    _gpt432KContextSize      = 32768\n    _gpt4ContextSize         = 8192\n    _textDavinci3ContextSize = 4097\n    _textBabbage1ContextSize = 2048\n    _textAda1ContextSize     = 2048\n    _textCurie1ContextSize   = 2048\n    _codeDavinci2ContextSize = 8000\n    _codeCushman1ContextSize = 2048\n    _textBisonContextSize    = 2048\n    _chatBisonContextSize    = 2048\n    _defaultContextSize      = 2048\n)\n\n\/\/ nolint:gochecknoglobals\nvar modelToContextSize = map[string]int{\n    \"gpt-3.5-turbo\":    _gpt35TurboContextSize,\n    \"gpt-4-32k\":        _gpt432KContextSize,\n    \"gpt-4\":            _gpt4ContextSize,\n    \"text-davinci-003\": _textDavinci3ContextSize,\n    \"text-curie-001\":   _textCurie1ContextSize,\n    \"text-babbage-001\": _textBabbage1ContextSize,\n    \"text-ada-001\":     _textAda1ContextSize,\n    \"code-davinci-002\": _codeDavinci2ContextSize,\n    \"code-cushman-001\": _codeCushman1ContextSize,\n}\n\nvar tokens int\n\nfunc runCmd(name string, arg ...string) {\n    cmd := exec.Command(name, arg...)\n    cmd.Stdout = os.Stdout\n    cmd.Run()\n}\n\nfunc ClearTerminal() {\n    switch runtime.GOOS {\n    case \"darwin\":\n        runCmd(\"clear\")\n    case \"linux\":\n        runCmd(\"clear\")\n    case \"windows\":\n        runCmd(\"cmd\", \"\/c\", \"cls\")\n    default:\n        runCmd(\"clear\")\n    }\n}\n\nfunc promptEntryDialog() string {\n\n    var promptEntry string\n\n    \/\/ Create a new Fyne application\n    myApp := app.New()\n    myWindow := myApp.NewWindow(\"Prompt Entry Dialog\")\n\n    \/\/ Variable to store user input\n    var userInput string\n\n    \/\/ Button to show the dialog\n    button := widget.NewButton(\"Click to Enter your prompt's text\", func() {\n        entry := widget.NewEntry()\n        dialog.ShowCustomConfirm(\"Input Dialog\", \"OK\", \"Cancel\", entry, func(confirm bool) {\n            if confirm {\n                userInput = entry.Text\n                promptEntry = userInput\n                fmt.Println(\"User Input:\", userInput) \/\/ Print to the console\n                myWindow.Close()\n            }\n        }, myWindow)\n    })\n\n    \/\/ Add the button to the window\n    myWindow.SetContent(container.NewVBox(\n        widget.NewLabel(\"Click the button below to enter text:\"),\n        button,\n    ))\n\n    \/\/ Set the window size and run the application\n    myWindow.Resize(fyne.NewSize(400, 200))\n    myWindow.ShowAndRun()\n    return promptEntry\n}\n\nfunc CountTokens(model, text string, inorout string) int {\n    var txtLen int\n    e, err := tiktoken.EncodingForModel(model)\n    if err != nil {\n        e, err = tiktoken.GetEncoding(\"gpt2\")\n        if err != nil {\n            log.Printf(\"[WARN] Failed to calculate number of tokens for model, falling back to approximate count\")\n            txtLen = len([]rune(text))\n\n            fmt.Println(\"Guessed tokens for the \"+inorout+\" text:\", txtLen\/_tokenApproximation)\n\n            return txtLen\n        }\n    }\n    return len(e.Encode(text, nil, nil))\n}\n\nfunc GetModelContextSize(model string) int {\n    contextSize, ok := modelToContextSize[model]\n    if !ok {\n        return _defaultContextSize\n    }\n    return contextSize\n}\n\nfunc CalculateMaxTokens(model, text string) int {\n    return GetModelContextSize(model) - CountTokens(model, text, text)\n}\n\nfunc main() {\n    var prompt, model string\n\n    \/\/ read the '.env' file\n    err := godotenv.Load()\n    if err != nil {\n        log.Fatal(\"Error loading .env file\")\n    }\n\n    ApiKey := os.Getenv(\"WATSONX_API_KEY\")\n    if ApiKey == \"\" {\n        log.Fatal(\"WATSONX_API_KEY environment variable is not set\")\n    }\n    ServiceURL := os.Getenv(\"SERVICE_URL\")\n    if ServiceURL == \"\" {\n        log.Fatal(\"SERVICE_URL environment variable is not set\")\n    }\n    ProjectID := os.Getenv(\"WATSONX_PROJECT_ID\")\n    if ProjectID == \"\" {\n        log.Fatal(\"WATSONX_PROJECT_ID environment variable is not set\")\n    }\n\n    \/\/ LLM from watsonx.ai\n    model = \"ibm\/granite-13b-instruct-v2\"\n    \/\/ model = \"meta-llama\/llama-3-70b-instruct\"\n\n    llm, err := watsonx.New(\n        model,\n        \/\/\/\/ Optional parameters: to be implemented if needed - Not used at this stage but all ready\n        \/\/ wx.WithWatsonxAPIKey(ApiKey),\n        \/\/ wx.WithWatsonxProjectID(\"YOUR WATSONX PROJECT ID\"),\n    )\n\n    if err != nil {\n        log.Fatal(err)\n    }\n    ctx := context.Background()\n\n    prompt = promptEntryDialog()\n\n    \/\/ for the output visibility on the consol - getting rid of system messages\n    ClearTerminal()\n\n    \/\/ Use the entry variable here\n    fmt.Println(\"Calling the llm with the user's prompt:\", prompt)\n\n    tokens = CountTokens(model, prompt, \"input\")\n\n    completion, err := llms.GenerateFromSinglePrompt(\n        ctx,\n        llm,\n        prompt,\n        llms.WithTopK(10),\n        llms.WithTopP(0.95),\n        llms.WithSeed(25),\n    )\n    \/\/ Check for errors\n    if err != nil {\n        log.Fatal(err)\n    }\n    fmt.Println(completion)\n\n    tokens = CountTokens(model, completion, \"output\")\n\n}\n\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u06a9\u0647 \u0628\u0647 \u062e\u0648\u0628\u06cc \u06a9\u0627\u0631 \u0645\u06cc \u06a9\u0646\u062f \u0647\u0645\u0627\u0646\u0637\u0648\u0631 \u06a9\u0647 \u062e\u0631\u0648\u062c\u06cc \u062f\u0631 \u0632\u06cc\u0631 \u0646\u0634\u0627\u0646 \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0627\u0633\u062a.<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>Calling the llm with the user's prompt: What is the distance in Kilmometers from Earth to Moon?\n2024\/12\/31 11:08:04 [WARN] Failed to calculate number of tokens for model, falling back to approximate count\nGuessed tokens for the input text: 13\nThe distance from Earth to the Moon is about 384,400 kilometers.\n2024\/12\/31 11:08:04 [WARN] Failed to calculate number of tokens for model, falling back to approximate count\nGuessed tokens for the output text: 16\n\n#####\n\n\nCalling the llm with the user's prompt: What is the name of the capital city of France?\n2024\/12\/31 11:39:28 [WARN] Failed to calculate number of tokens for model, falling back to approximate count\nGuessed tokens for the input text: 11\nParis\n2024\/12\/31 11:39:28 [WARN] Failed to calculate number of tokens for model, falling back to approximate count\nGuessed tokens for the output text: 1\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>Voil\u00e0!<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%D9%85%D8%B1%D8%A7%D8%AD%D9%84_%D8%A8%D8%B9%D8%AF%DB%8C\"><\/span>\n<p>  \u0645\u0631\u0627\u062d\u0644 \u0628\u0639\u062f\u06cc<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u0645\u0646 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0632\u06cc\u0631 \u0631\u0627 \u0628\u0631\u0627\u06cc \u0646\u0633\u062e\u0647 0.2 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0645\u06cc \u06a9\u0646\u0645.<\/p>\n<ul>\n<li>\u067e\u06cc\u0634\u0646\u0647\u0627\u062f \u0645\u062f\u0644\u06cc \u06a9\u0647 \u06a9\u0627\u0631\u0628\u0631 \u0645\u06cc \u062e\u0648\u0627\u0647\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u062f\u060c<\/li>\n<li>\u06cc\u06a9 \u0631\u0627\u0647 \u062f\u0642\u06cc\u0642 \u062a\u0631 \u0628\u0631\u0627\u06cc \u062a\u0639\u06cc\u06cc\u0646 # \u062a\u0648\u06a9\u0646\u060c<\/li>\n<li>\u0628\u0631\u062e\u06cc \u0627\u0632 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0648\u0627\u0642\u0639\u06cc LangChain.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"%D9%86%D8%AA%DB%8C%D8%AC%D9%87_%DA%AF%DB%8C%D8%B1%DB%8C\"><\/span>\n<p>  \u0646\u062a\u06cc\u062c\u0647 \u06af\u06cc\u0631\u06cc<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u0627\u06cc\u0646 \u0628\u0627\u0632\u062a\u0627\u0628\u06cc \u0628\u0633\u06cc\u0627\u0631 \u0633\u0627\u062f\u0647 \u0627\u0632 \u06a9\u0627\u0631 \u0645\u0646 \u062f\u0631 \u0645\u0648\u0631\u062f \u0641\u0631\u0627\u062e\u0648\u0627\u0646\u06cc LangChain \u0627\u0632 \u06cc\u06a9 \u0628\u0631\u0646\u0627\u0645\u0647 Go \u0627\u0633\u062a.<\/p>\n<p>\u0645\u0646\u062a\u0638\u0631 \u0645\u0637\u0627\u0644\u0628 \u0628\u06cc\u0634\u062a\u0631 \u0628\u0627\u0634\u06cc\u062f\ud83d\udca1<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0627\u0646\u06af\u06cc\u0632\u0647 \u0628\u0647 \u062f\u0646\u0628\u0627\u0644 \u0622\u0632\u0645\u0627\u06cc\u0634\u200c\u0647\u0627\u06cc \u00ab\u062a\u0639\u0637\u06cc\u0644\u0627\u062a\u00bb (\u067e\u0633\u062a\u200c\u0647\u0627\u06cc \u0642\u0628\u0644\u06cc&#8230;) \u062f\u0631 \u0645\u0648\u0631\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 Golang \u0648 LLM\u060c \u0628\u0647 \u062f\u0646\u0628\u0627\u0644 \u0631\u0627\u0647\u06cc \u0622\u0633\u0627\u0646 \u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647\u200c\u0633\u0627\u0632\u06cc \u062a\u0645\u0627\u0633 LangChain \u062f\u0631 Go \u0648 \u062a\u0631\u062c\u06cc\u062d\u0627\u064b \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0622\u0646 \u0628\u0648\u062f\u0645. watsonx.ai. \u062e\u0648\u0634\u0628\u062e\u062a\u0627\u0646\u0647 \u0645\u0646 \u0645\u062e\u0632\u0646 Github \u0632\u06cc\u0631 \u0631\u0627 \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062f\u0645: https:\/\/github.com\/tmc\/langchaingo (\u0628\u0647 \u062a\u0631\u0627\u0648\u06cc\u0633 \u06a9\u0644\u06cc\u0646 https:\/\/github.com\/tmc). \u062f\u0631 \u0645\u062e\u0632\u0646 \u0627\u0648\u060c \u0627\u06cc\u0646 \u067e\u0648\u0634\u0647 \u062e\u0627\u0635 \u0648\u062c\u0648\u062f \u062f\u0627\u0631\u062f: https:\/\/github.com\/tmc\/langchaingo\/blob\/main\/examples\/watsonx-llm-example\/watsonx_example.go \u06a9\u0647 \u062a\u0648\u062c\u0647 &hellip;<\/p>\n","protected":false},"author":2,"featured_media":90670,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/media2.dev.to\/dynamic\/image\/width=1000,height=500,fit=cover,gravity=auto,format=auto\/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwuct46laf7562k5913l9.png","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-90669","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/90669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=90669"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/90669\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/90670"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=90669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=90669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=90669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}