MyMagic AI 大语言模型
本笔记本演示了如何使用MyMagicAI对存储在云存储桶中的海量数据进行批量推理。已实现的唯一端点是complete和acomplete,它们可适用于多种使用场景,包括补全、摘要和提取。
要使用此笔记本,您需要从MyMagicAI获取API密钥(个人访问令牌)以及存储在云存储桶中的数据。
请点击MyMagicAI官网的"开始使用"进行注册以获取您的API密钥。
要设置您的存储桶并授予 MyMagic API 对您云存储的安全访问权限,请访问MyMagic 文档作为参考。 如果您在 Colab 上打开此 Notebook,可能需要安装 LlamaIndex 🦙。
%pip install llama-index-llms-mymagic!pip install llama-indexfrom llama_index.llms.mymagic import MyMagicAIllm = MyMagicAI( api_key="your-api-key", storage_provider="s3", # s3, gcs bucket_name="your-bucket-name", session="your-session-name", # files should be located in this folder on which batch inference will be run role_arn="your-role-arn", system_prompt="your-system-prompt", region="your-bucket-region", return_output=False, # Whether you want MyMagic API to return the output json input_json_file=None, # name of the input file (stored on the bucket) list_inputs=None, # Option to provide inputs as a list in case of small batch structured_output=None, # json schema of the output)注意:如果上面设置了 return_output 为 True,max_tokens 应至少设置为 100
resp = llm.complete( question="your-question", model="chhoose-model", # currently we support mistral7b, llama7b, mixtral8x7b, codellama70b, llama70b, more to come... max_tokens=5, # number of tokens to generate, default is 10)# The response indicated that the final output is stored in your bucket or raises an exception if the job failedprint(resp)通过使用 acomplete 端点进行异步请求
Section titled “Asynchronous Requests by using acomplete endpoint”对于异步操作,请使用以下方法。
import asyncioasync def main(): response = await llm.acomplete( question="your-question", model="choose-model", # supported models constantly updated and are listed at docs.mymagic.ai max_tokens=5, # number of tokens to generate, default is 10 )
print("Async completion response:", response)await main()