{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "# GigaChat\n", "This notebook shows how to use LangChain with [GigaChat](https://developers.sber.ru/portal/products/gigachat).\n", "To use you need to install ```gigachat``` python package." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%pip install --upgrade --quiet gigachat" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "To get GigaChat credentials you need to [create account](https://developers.sber.ru/studio/login) and [get access to API](https://developers.sber.ru/docs/ru/gigachat/api/integration)\n", "## Example" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n", "from getpass import getpass\n", "\n", "os.environ[\"GIGACHAT_CREDENTIALS\"] = getpass()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from langchain_community.llms import GigaChat\n", "\n", "llm = GigaChat(verify_ssl_certs=False)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The capital of Russia is Moscow.\n" ] } ], "source": [ "from langchain.chains import LLMChain\n", "from langchain.prompts import PromptTemplate\n", "\n", "template = \"What is capital of {country}?\"\n", "\n", "prompt = PromptTemplate(template=template, input_variables=[\"country\"])\n", "\n", "llm_chain = LLMChain(prompt=prompt, llm=llm)\n", "\n", "generated = llm_chain.run(country=\"Russia\")\n", "print(generated)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }