"The [Modal cloud platform](https://modal.com/docs/guide) provides convenient, on-demand access to serverless cloud compute from Python scripts on your local computer. \n",
"Use `modal` to run your own custom LLM models instead of depending on LLM APIs.\n",
"[_Question-answering with LangChain_](https://modal.com/docs/guide/ex/potus_speech_qanda) is another example of how to use LangChain alonside `Modal`. In that example, Modal runs the LangChain application end-to-end and uses OpenAI as its LLM API."
"The [`langchain.llms.modal.Modal`](https://github.com/hwchase17/langchain/blame/master/langchain/llms/modal.py) integration class requires that you deploy a Modal application with a web endpoint that complies with the following JSON interface:\n",
"\n",
"1. The LLM prompt is accepted as a `str` value under the key `\"prompt\"`\n",
"2. The LLM response returned as a `str` value under the key `\"prompt\"`\n",
"\n",
"**Example request JSON:**\n",
"\n",
"```json\n",
"{\n",
" \"prompt\": \"Identify yourself, bot!\",\n",
" \"extra\": \"args are allowed\",\n",
"}\n",
"```\n",
"\n",
"**Example response JSON:**\n",
"\n",
"```json\n",
"{\n",
" \"prompt\": \"This is the LLM speaking\",\n",
"}\n",
"```\n",
"\n",
"An example 'dummy' Modal web endpoint function fulfilling this interface would be\n",
"\n",
"```python\n",
"...\n",
"...\n",
"\n",
"class Request(BaseModel):\n",
" prompt: str\n",
"\n",
"@stub.function()\n",
"@modal.web_endpoint(method=\"POST\")\n",
"def web(request: Request):\n",
" _ = request # ignore input\n",
" return {\"prompt\": \"hello world\"}\n",
"```\n",
"\n",
"* See Modal's [web endpoints](https://modal.com/docs/guide/webhooks#passing-arguments-to-web-endpoints) guide for the basics of setting up an endpoint that fulfils this interface.\n",
"* See Modal's ['Run Falcon-40B with AutoGPTQ'](https://modal.com/docs/guide/ex/falcon_gptq) open-source LLM example as a starting point for your custom LLM!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you have a deployed Modal web endpoint, you can pass its URL into the `langchain.llms.modal.Modal` LLM class. This class can then function as a building block in your chain."