2023-02-24 14:58:58 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# StochasticAI\n",
2023-04-18 03:25:32 +00:00
"\n",
">[Stochastic Acceleration Platform](https://docs.stochastic.ai/docs/introduction/) aims to simplify the life cycle of a Deep Learning model. From uploading and versioning the model, through training, compression and acceleration to putting it into production.\n",
"\n",
"This example goes over how to use LangChain to interact with `StochasticAI` models."
2023-02-24 14:58:58 +00:00
]
},
{
2023-04-18 03:25:32 +00:00
"cell_type": "markdown",
2023-02-24 14:58:58 +00:00
"metadata": {},
2023-04-18 03:25:32 +00:00
"source": [
"You have to get the API_KEY and the API_URL [here](https://app.stochastic.ai/workspace/profile/settings?tab=profile)."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
" ········\n"
]
}
],
"source": [
"from getpass import getpass\n",
"\n",
"STOCHASTICAI_API_KEY = getpass()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ[\"STOCHASTICAI_API_KEY\"] = STOCHASTICAI_API_KEY"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
" ········\n"
]
}
],
"source": [
"YOUR_API_URL = getpass()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"tags": []
},
2023-02-24 14:58:58 +00:00
"outputs": [],
"source": [
"from langchain.llms import StochasticAI\n",
2023-09-17 00:22:48 +00:00
"from langchain.prompts import PromptTemplate\nfrom langchain.chains import LLMChain"
2023-02-24 14:58:58 +00:00
]
},
{
"cell_type": "code",
2023-04-18 03:25:32 +00:00
"execution_count": 6,
"metadata": {
"tags": []
},
2023-02-24 14:58:58 +00:00
"outputs": [],
"source": [
"template = \"\"\"Question: {question}\n",
"\n",
"Answer: Let's think step by step.\"\"\"\n",
"\n",
"prompt = PromptTemplate(template=template, input_variables=[\"question\"])"
]
},
{
"cell_type": "code",
2023-04-18 03:25:32 +00:00
"execution_count": 11,
"metadata": {
"tags": []
},
2023-02-24 14:58:58 +00:00
"outputs": [],
"source": [
2023-04-18 03:25:32 +00:00
"llm = StochasticAI(api_url=YOUR_API_URL)"
2023-02-24 14:58:58 +00:00
]
},
{
"cell_type": "code",
2023-04-18 03:25:32 +00:00
"execution_count": 12,
"metadata": {
"tags": []
},
2023-02-24 14:58:58 +00:00
"outputs": [],
"source": [
"llm_chain = LLMChain(prompt=prompt, llm=llm)"
]
},
{
"cell_type": "code",
2023-04-18 03:25:32 +00:00
"execution_count": 13,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"\"\\n\\nStep 1: In 1999, the St. Louis Rams won the Super Bowl.\\n\\nStep 2: In 1999, Beiber was born.\\n\\nStep 3: The Rams were in Los Angeles at the time.\\n\\nStep 4: So they didn't play in the Super Bowl that year.\\n\""
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
2023-02-24 14:58:58 +00:00
"source": [
"question = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\n",
"\n",
"llm_chain.run(question)"
]
2023-04-18 03:25:32 +00:00
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
2023-02-24 14:58:58 +00:00
}
],
"metadata": {
"kernelspec": {
2023-04-18 03:25:32 +00:00
"display_name": "Python 3 (ipykernel)",
2023-02-24 14:58:58 +00:00
"language": "python",
"name": "python3"
},
"language_info": {
2023-04-18 03:25:32 +00:00
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
2023-02-24 14:58:58 +00:00
"name": "python",
2023-04-18 03:25:32 +00:00
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
2023-02-24 14:58:58 +00:00
},
"vscode": {
"interpreter": {
"hash": "a0a0263b650d907a3bfe41c0f8d6a63a071b884df3cfdc1579f00cdc1aed6b03"
}
}
},
"nbformat": 4,
2023-04-18 03:25:32 +00:00
"nbformat_minor": 4
2023-02-24 14:58:58 +00:00
}