"[Anyscale](https://www.anyscale.com/) is a fully-managed [Ray](https://www.ray.io/) platform, on which you can build, deploy, and manage scalable AI and Python applications\n",
"\n",
"This example goes over how to use LangChain to interact with `Anyscale` [service](https://docs.anyscale.com/productionize/services-v2/get-started)"
"question = \"When was George Washington president?\"\n",
"\n",
"llm_chain.run(question)"
]
},
{
"cell_type": "markdown",
"id": "42f05b34-1a44-4cbd-8342-35c1572b6765",
"metadata": {},
"source": [
"With Ray, we can distribute the queries without asyncrhonized implementation. This not only applies to Anyscale LLM model, but to any other Langchain LLM models which do not have `_acall` or `_agenerate` implemented"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "08b23adc-2b29-4c38-b538-47b3c3d840a6",
"metadata": {},
"outputs": [],
"source": [
"prompt_list = [\n",
" \"When was George Washington president?\",\n",
" \"Explain to me the difference between nuclear fission and fusion.\",\n",
" \"Give me a list of 5 science fiction books I should read next.\",\n",
" \"Explain the difference between Spark and Ray.\",\n",
" \"Suggest some fun holiday ideas.\",\n",
" \"Tell a joke.\",\n",
" \"What is 2+2?\",\n",
" \"Explain what is machine learning like I am five years old.\",\n",
" \"Explain what is artifical intelligence.\",\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b45abb9-b764-497d-af99-0df1d4e335e0",
"metadata": {},
"outputs": [],
"source": [
"import ray\n",
"\n",
"@ray.remote\n",
"def send_query(llm, prompt):\n",
" resp = llm(prompt)\n",
" return resp\n",
"\n",
"futures = [send_query.remote(llm, prompt) for prompt in prompt_list]\n",