{"cells": [{"cell_type": "markdown", "id": "6453d3d5", "metadata": {}, "source": ["\n"]}, {"cell_type": "markdown", "id": "731d44db9e0d236c", "metadata": {}, "source": ["# Aleph Alpha\n", "\n", "Aleph Alpha是一个强大的语言模型,可以生成类似人类的文本。阿列夫阿尔法能够以多种语言和风格生成文本,并且可以进行微调以生成特定领域的文本。\n"]}, {"cell_type": "markdown", "id": "c78b172f", "metadata": {}, "source": ["如果您在colab上打开这个笔记本,您可能需要安装LlamaIndex 🦙。\n"]}, {"cell_type": "code", "execution_count": null, "id": "8e31874a", "metadata": {}, "outputs": [], "source": ["%pip install llama-index-llms-alephalpha"]}, {"cell_type": "code", "execution_count": null, "id": "50fc1a30", "metadata": {}, "outputs": [], "source": ["!pip install llama-index"]}, {"cell_type": "markdown", "id": "4f2a12560669efa6", "metadata": {}, "source": ["#### 设置您的 Aleph Alpha 令牌\n"]}, {"cell_type": "code", "execution_count": null, "id": "85fbba23", "metadata": {}, "outputs": [], "source": ["import os\n", "\n", "os.environ[\"AA_TOKEN\"] = \"your_token_here\""]}, {"cell_type": "markdown", "id": "b81a3ef6-2ee5-460d-9aa4-f73708774014", "metadata": {}, "source": ["#### 使用提示调用`complete`\n"]}, {"cell_type": "code", "execution_count": null, "id": "910b50ad-c55e-487e-8808-5905dfaa78b4", "metadata": {}, "outputs": [], "source": ["from llama_index.llms.alephalpha import AlephAlpha\n", "\n", "# 要自定义您的令牌,请执行以下操作\n", "# 否则它将查找您环境变量中的AA_TOKEN\n", "# llm = AlephAlpha(token=\"\")\n", "llm = AlephAlpha(model=\"luminous-base-control\")\n", "\n", "resp = llm.complete(\"Paul Graham is \")\n"]}, {"cell_type": "code", "execution_count": null, "id": "dfda925e-89c5-47a6-9311-16916ab08b66", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": [" a well-known computer scientist and entrepreneur. He is the co-founder of PayPal and a co-founder of the Y Combinator startup accelerator. He has also co-authored the book \"Programming the Web\". Paul Graham is also a frequent speaker and writer on topics related to computer science, entrepreneurship, and startups. He has written several blog posts on the topic of \"Why Startups Fail\". In this post, I will summarize some of the key points from Paul Graham's blog post on why startups fail.\n", "\n", "1. Lack of a clear vision: Startups often lack a clear vision of what they\n"]}], "source": ["print(resp)"]}, {"cell_type": "markdown", "id": "413fbe0a60a8e449", "metadata": {}, "source": ["#### 附加响应细节\n", "要访问详细的响应信息,比如对数概率,确保你的 AlephAlpha 实例是用 `log_probs` 参数初始化的。`CompletionResponse` 的 `logprobs` 属性将包含这些数据。如果模型版本和原始完成文本是响应的一部分,或者通过 `additional_kwargs` 访问。\n"]}, {"cell_type": "code", "execution_count": null, "id": "de81c4b2e2c36894", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": ["\n", "Log Probabilities:\n", "Token: a, LogProb: -0.95955\n", "Token: well, LogProb: -1.9219251\n", "Token: -, LogProb: -0.1312752\n", "Token: known, LogProb: -0.022855662\n", "Token: computer, LogProb: -0.9569155\n", "Token: scientist, LogProb: -0.06721641\n", "Token: and, LogProb: -0.56296504\n", "Token: entrepreneur, LogProb: -0.65574974\n", "Token: ., LogProb: -0.5926046\n", "Token: He, LogProb: -0.1885516\n", "Token: is, LogProb: -0.3927348\n", "Token: the, LogProb: -0.46820825\n", "Token: co, LogProb: -0.465878\n", "Token: -, LogProb: -0.024082167\n", "Token: founder, LogProb: -0.009869587\n", "Token: of, LogProb: -0.31641242\n", "Token: PayPal, LogProb: -1.0825713\n", "Token: and, LogProb: -0.39408743\n", "Token: a, LogProb: -1.45493\n", "Token: co, LogProb: -1.0837904\n", "Token: -, LogProb: -0.0011430404\n", "Token: founder, LogProb: -0.074010715\n", "Token: of, LogProb: -0.038962167\n", "Token: the, LogProb: -1.7761776\n", "Token: Y, LogProb: -0.41853565\n", "Token: Combin, LogProb: -0.17868777\n", "Token: ator, LogProb: -2.0265374e-05\n", "Token: startup, LogProb: -0.24595682\n", "Token: acceler, LogProb: -0.5855012\n", "Token: ator, LogProb: -6.675698e-06\n", "Token: ., LogProb: -0.022597663\n", "Token: He, LogProb: -0.8310143\n", "Token: has, LogProb: -1.5842702\n", "Token: also, LogProb: -0.5774656\n", "Token: been, LogProb: -1.3938092\n", "Token: a, LogProb: -0.67207164\n", "Token: professor, LogProb: -1.0511048\n", "Token: at, LogProb: -0.13273911\n", "Token: the, LogProb: -0.7993539\n", "Token: MIT, LogProb: -1.2281163\n", "Token: Media, LogProb: -0.7707413\n", "Token: Lab, LogProb: -0.06716257\n", "Token: ., LogProb: -0.9140582\n", "Token: Paul, LogProb: -0.8244309\n", "Token: Graham, LogProb: -0.15202633\n", "Token: has, LogProb: -1.3735206\n", "Token: written, LogProb: -0.77148163\n", "Token: several, LogProb: -0.7167357\n", "Token: books, LogProb: -0.24542983\n", "Token: on, LogProb: -0.77700675\n", "Token: computer, LogProb: -0.8485363\n", "Token: science, LogProb: -0.026196867\n", "Token: and, LogProb: -0.4796574\n", "Token: entrepreneurs, LogProb: -0.48952234\n", "Token: hip, LogProb: -1.0847986e-05\n", "Token: ,, LogProb: -0.1426171\n", "Token: including, LogProb: -0.10799221\n", "Token: \", LogProb: -0.4733107\n", "Token: Program, LogProb: -0.9295699\n", "Token: ming, LogProb: -0.00090034\n", "Token: the, LogProb: -1.5219054\n", "Token: Universe, LogProb: -1.2475122\n", "Token: \", LogProb: -0.8377396\n", "Token: and, LogProb: -0.014596111\n", "Token: \", LogProb: -0.0034322182\n", "Token: The, LogProb: -0.97810173\n", "Token: Art, LogProb: -1.4708842\n", "Token: of, LogProb: -0.0017665509\n", "Token: Computer, LogProb: -0.027323013\n", "Token: Programming, LogProb: -0.09090222\n", "Token: \"., LogProb: -0.2312944\n", "Token: He, LogProb: -0.9431941\n", "Token: is, LogProb: -0.52350885\n", "Token: also, LogProb: -0.8409716\n", "Token: the, LogProb: -1.2813272\n", "Token: founder, LogProb: -0.8080497\n", "Token: of, LogProb: -0.12735468\n", "Token: the, LogProb: -0.26858208\n", "Token: startup, LogProb: -1.7183943\n", "Token: incub, LogProb: -0.71643037\n", "Token: ator, LogProb: -0.00013922676\n", "Token: ,, LogProb: -1.6374074\n", "Token: Y, LogProb: -1.3464186\n", "Token: Combin, LogProb: -0.043204635\n", "Token: ator, LogProb: -1.490105e-05\n", "Token: ., LogProb: -0.48073012\n", "Token: <|endoftext|>, LogProb: -0.30235213\n", "\n", "Model Version:\n", "20240215\n", "\n", "Raw Completion:\n", " a well-known computer scientist and entrepreneur. He is the co-founder of PayPal and a co-founder of the Y Combinator startup accelerator. He has also been a professor at the MIT Media Lab. Paul Graham has written several books on computer science and entrepreneurship, including \"Programming the Universe\" and \"The Art of Computer Programming\". He is also the founder of the startup incubator, Y Combinator.\n"]}], "source": ["from llama_index.llms.alephalpha import AlephAlpha\n", "\n", "llm = AlephAlpha(model=\"luminous-base-control\", log_probs=0)\n", "\n", "resp = llm.complete(\"Paul Graham is \")\n", "\n", "if resp.logprobs is not None:\n", " print(\"\\nLog Probabilities:\")\n", " for lp_list in resp.logprobs:\n", " for lp in lp_list:\n", " print(f\"Token: {lp.token}, LogProb: {lp.logprob}\")\n", "\n", "if \"model_version\" in resp.additional_kwargs:\n", " print(\"\\nModel Version:\")\n", " print(resp.additional_kwargs[\"model_version\"])\n", "\n", "if \"raw_completion\" in resp.additional_kwargs:\n", " print(\"\\nRaw Completion:\")\n", " print(resp.additional_kwargs[\"raw_completion\"])"]}, {"cell_type": "markdown", "id": "5152a2b4-78e6-47a5-933d-f5186ec0f775", "metadata": {}, "source": ["## 异步\n", "\n", "在计算机编程中,异步操作是指不按照程序的顺序执行的操作。在异步编程中,程序可以继续执行其他操作,而不必等待当前操作完成。这种编程模型通常用于处理I/O操作或长时间运行的任务,以避免阻塞程序的执行。Python提供了多种方式来实现异步编程,包括async/await关键字、asyncio库和第三方库(如aiohttp和asyncpg)。通过使用这些工具,开发人员可以编写高效的异步代码,提高程序的性能和响应速度。\n"]}, {"cell_type": "code", "execution_count": null, "id": "7df04c0e-43ee-4176-9aad-94781d0ed36d", "metadata": {}, "outputs": [], "source": ["from llama_index.llms.alephalpha import AlephAlpha\n", "\n", "llm = AlephAlpha(model=\"luminous-base-control\")\n", "resp = await llm.acomplete(\"Paul Graham is \")"]}, {"cell_type": "code", "execution_count": null, "id": "be09c52b-604a-4f05-8f93-36e6ea882ff5", "metadata": {}, "outputs": [{"name": "stdout", "output_type": "stream", "text": [" a computer scientist and entrepreneur who is known for his work in the field of artificial intelligence and computer science. He is the co-founder of the company Y Combinator, which is a startup accelerator that helps startups get funding and resources. Paul Graham has also written several books on computer science and entrepreneurship, including \"Programming: Principles and Practice\" and \"The Art of Computer Programming\". He is a well-known figure in the computer science community and has made significant contributions to the field.\n"]}], "source": ["print(resp)"]}], "metadata": {"kernelspec": {"display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3"}, "vscode": {"interpreter": {"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"}}}, "nbformat": 4, "nbformat_minor": 5}