Aleph Alpha¶
Aleph Alpha是一个强大的语言模型,可以生成类似人类的文本。阿列夫阿尔法能够以多种语言和风格生成文本,并且可以进行微调以生成特定领域的文本。
如果您在colab上打开这个笔记本,您可能需要安装LlamaIndex 🦙。
In [ ]:
Copied!
%pip install llama-index-llms-alephalpha
%pip install llama-index-llms-alephalpha
In [ ]:
Copied!
!pip install llama-index
!pip install llama-index
设置您的 Aleph Alpha 令牌¶
In [ ]:
Copied!
import os
os.environ["AA_TOKEN"] = "your_token_here"
import os
os.environ["AA_TOKEN"] = "your_token_here"
使用提示调用complete
¶
In [ ]:
Copied!
from llama_index.llms.alephalpha import AlephAlpha
# 要自定义您的令牌,请执行以下操作
# 否则它将查找您环境变量中的AA_TOKEN
# llm = AlephAlpha(token="<aa_token>")
llm = AlephAlpha(model="luminous-base-control")
resp = llm.complete("Paul Graham is ")
from llama_index.llms.alephalpha import AlephAlpha
# 要自定义您的令牌,请执行以下操作
# 否则它将查找您环境变量中的AA_TOKEN
# llm = AlephAlpha(token="")
llm = AlephAlpha(model="luminous-base-control")
resp = llm.complete("Paul Graham is ")
In [ ]:
Copied!
print(resp)
print(resp)
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. 1. Lack of a clear vision: Startups often lack a clear vision of what they
附加响应细节¶
要访问详细的响应信息,比如对数概率,确保你的 AlephAlpha 实例是用 log_probs
参数初始化的。CompletionResponse
的 logprobs
属性将包含这些数据。如果模型版本和原始完成文本是响应的一部分,或者通过 additional_kwargs
访问。
In [ ]:
Copied!
from llama_index.llms.alephalpha import AlephAlpha
llm = AlephAlpha(model="luminous-base-control", log_probs=0)
resp = llm.complete("Paul Graham is ")
if resp.logprobs is not None:
print("\nLog Probabilities:")
for lp_list in resp.logprobs:
for lp in lp_list:
print(f"Token: {lp.token}, LogProb: {lp.logprob}")
if "model_version" in resp.additional_kwargs:
print("\nModel Version:")
print(resp.additional_kwargs["model_version"])
if "raw_completion" in resp.additional_kwargs:
print("\nRaw Completion:")
print(resp.additional_kwargs["raw_completion"])
from llama_index.llms.alephalpha import AlephAlpha
llm = AlephAlpha(model="luminous-base-control", log_probs=0)
resp = llm.complete("Paul Graham is ")
if resp.logprobs is not None:
print("\nLog Probabilities:")
for lp_list in resp.logprobs:
for lp in lp_list:
print(f"Token: {lp.token}, LogProb: {lp.logprob}")
if "model_version" in resp.additional_kwargs:
print("\nModel Version:")
print(resp.additional_kwargs["model_version"])
if "raw_completion" in resp.additional_kwargs:
print("\nRaw Completion:")
print(resp.additional_kwargs["raw_completion"])
Log Probabilities: Token: a, LogProb: -0.95955 Token: well, LogProb: -1.9219251 Token: -, LogProb: -0.1312752 Token: known, LogProb: -0.022855662 Token: computer, LogProb: -0.9569155 Token: scientist, LogProb: -0.06721641 Token: and, LogProb: -0.56296504 Token: entrepreneur, LogProb: -0.65574974 Token: ., LogProb: -0.5926046 Token: He, LogProb: -0.1885516 Token: is, LogProb: -0.3927348 Token: the, LogProb: -0.46820825 Token: co, LogProb: -0.465878 Token: -, LogProb: -0.024082167 Token: founder, LogProb: -0.009869587 Token: of, LogProb: -0.31641242 Token: PayPal, LogProb: -1.0825713 Token: and, LogProb: -0.39408743 Token: a, LogProb: -1.45493 Token: co, LogProb: -1.0837904 Token: -, LogProb: -0.0011430404 Token: founder, LogProb: -0.074010715 Token: of, LogProb: -0.038962167 Token: the, LogProb: -1.7761776 Token: Y, LogProb: -0.41853565 Token: Combin, LogProb: -0.17868777 Token: ator, LogProb: -2.0265374e-05 Token: startup, LogProb: -0.24595682 Token: acceler, LogProb: -0.5855012 Token: ator, LogProb: -6.675698e-06 Token: ., LogProb: -0.022597663 Token: He, LogProb: -0.8310143 Token: has, LogProb: -1.5842702 Token: also, LogProb: -0.5774656 Token: been, LogProb: -1.3938092 Token: a, LogProb: -0.67207164 Token: professor, LogProb: -1.0511048 Token: at, LogProb: -0.13273911 Token: the, LogProb: -0.7993539 Token: MIT, LogProb: -1.2281163 Token: Media, LogProb: -0.7707413 Token: Lab, LogProb: -0.06716257 Token: ., LogProb: -0.9140582 Token: Paul, LogProb: -0.8244309 Token: Graham, LogProb: -0.15202633 Token: has, LogProb: -1.3735206 Token: written, LogProb: -0.77148163 Token: several, LogProb: -0.7167357 Token: books, LogProb: -0.24542983 Token: on, LogProb: -0.77700675 Token: computer, LogProb: -0.8485363 Token: science, LogProb: -0.026196867 Token: and, LogProb: -0.4796574 Token: entrepreneurs, LogProb: -0.48952234 Token: hip, LogProb: -1.0847986e-05 Token: ,, LogProb: -0.1426171 Token: including, LogProb: -0.10799221 Token: ", LogProb: -0.4733107 Token: Program, LogProb: -0.9295699 Token: ming, LogProb: -0.00090034 Token: the, LogProb: -1.5219054 Token: Universe, LogProb: -1.2475122 Token: ", LogProb: -0.8377396 Token: and, LogProb: -0.014596111 Token: ", LogProb: -0.0034322182 Token: The, LogProb: -0.97810173 Token: Art, LogProb: -1.4708842 Token: of, LogProb: -0.0017665509 Token: Computer, LogProb: -0.027323013 Token: Programming, LogProb: -0.09090222 Token: "., LogProb: -0.2312944 Token: He, LogProb: -0.9431941 Token: is, LogProb: -0.52350885 Token: also, LogProb: -0.8409716 Token: the, LogProb: -1.2813272 Token: founder, LogProb: -0.8080497 Token: of, LogProb: -0.12735468 Token: the, LogProb: -0.26858208 Token: startup, LogProb: -1.7183943 Token: incub, LogProb: -0.71643037 Token: ator, LogProb: -0.00013922676 Token: ,, LogProb: -1.6374074 Token: Y, LogProb: -1.3464186 Token: Combin, LogProb: -0.043204635 Token: ator, LogProb: -1.490105e-05 Token: ., LogProb: -0.48073012 Token: <|endoftext|>, LogProb: -0.30235213 Model Version: 20240215 Raw Completion: 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.
异步¶
在计算机编程中,异步操作是指不按照程序的顺序执行的操作。在异步编程中,程序可以继续执行其他操作,而不必等待当前操作完成。这种编程模型通常用于处理I/O操作或长时间运行的任务,以避免阻塞程序的执行。Python提供了多种方式来实现异步编程,包括async/await关键字、asyncio库和第三方库(如aiohttp和asyncpg)。通过使用这些工具,开发人员可以编写高效的异步代码,提高程序的性能和响应速度。
In [ ]:
Copied!
from llama_index.llms.alephalpha import AlephAlpha
llm = AlephAlpha(model="luminous-base-control")
resp = await llm.acomplete("Paul Graham is ")
from llama_index.llms.alephalpha import AlephAlpha
llm = AlephAlpha(model="luminous-base-control")
resp = await llm.acomplete("Paul Graham is ")
In [ ]:
Copied!
print(resp)
print(resp)
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.