YandexGPT
This notebook goes over how to use Langchain with YandexGPT.
To use, you should have the yandexcloud
python package installed.
%pip install yandexcloud
First, you should create service account with the ai.languageModels.user
role.
Next, you have two authentication options:
- IAM token.
You can specify the token in a constructor parameter
iam_token
or in an environment variableYC_IAM_TOKEN
. - API key
You can specify the key in a constructor parameter
api_key
or in an environment variableYC_API_KEY
.
from langchain.chains import LLMChain
from langchain.llms import YandexGPT
from langchain.prompts import PromptTemplate
template = "What is the capital of {country}?"
prompt = PromptTemplate(template=template, input_variables=["country"])
llm = YandexGPT()
llm_chain = LLMChain(prompt=prompt, llm=llm)
country = "Russia"
llm_chain.run(country)
'Moscow'