" session=\"your-session-name\", # files should be located in this folder on which batch inference will be run\n",
" session=\"your-session-name\", # files should be located in this folder on which batch inference will be run\n",
" role_arn=\"your-role-arn\",\n",
" role_arn=\"your-role-arn\",\n",
" system_prompt=\"your-system-prompt\",\n",
" system_prompt=\"your-system-prompt\",\n",
" region=\"your-bucket-region\",\n",
")"
")"
]
]
},
},
...
@@ -123,6 +124,7 @@
...
@@ -123,6 +124,7 @@
" session=\"your-session-name\", # files should be located in this folder on which batch inference will be run\n",
" session=\"your-session-name\", # files should be located in this folder on which batch inference will be run\n",
" role_arn=\"your-role-arn\",\n",
" role_arn=\"your-role-arn\",\n",
" system_prompt=\"your-system-prompt\",\n",
" system_prompt=\"your-system-prompt\",\n",
" region=\"your-bucket-region\",\n",
" )\n",
" )\n",
" response = await allm.acomplete(\n",
" response = await allm.acomplete(\n",
" question=\"your-question\",\n",
" question=\"your-question\",\n",
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# MyMagic AI LLM
# MyMagic AI LLM
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Introduction
## Introduction
This notebook demonstrates how to use MyMagicAI for batch inference on massive data stored in cloud buckets. The only enpoints implemented are `complete` and `acomplete` which can work on many use cases including Completion, Summariation and Extraction.
This notebook demonstrates how to use MyMagicAI for batch inference on massive data stored in cloud buckets. The only enpoints implemented are `complete` and `acomplete` which can work on many use cases including Completion, Summariation and Extraction.
To use this notebook, you need an API key (Personal Access Token) from MyMagicAI and data stored in cloud buckets.
To use this notebook, you need an API key (Personal Access Token) from MyMagicAI and data stored in cloud buckets.
Sign up by clicking Get Started at [MyMagicAI's website](https://mymagic.ai/) to get your API key.
Sign up by clicking Get Started at [MyMagicAI's website](https://mymagic.ai/) to get your API key.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Setup
## Setup
To set up your bucket and grant MyMagic API a secure access to your cloud storage, please visit [MyMagic docs](https://docs.mymagic.ai/) for reference.
To set up your bucket and grant MyMagic API a secure access to your cloud storage, please visit [MyMagic docs](https://docs.mymagic.ai/) for reference.
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
%pipinstallllama-index-llms-mymagic
%pipinstallllama-index-llms-mymagic
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
!pipinstallllama-index
!pipinstallllama-index
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
fromllama_index.llms.mymagicimportMyMagicAI
fromllama_index.llms.mymagicimportMyMagicAI
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
llm=MyMagicAI(
llm=MyMagicAI(
api_key="your-api-key",
api_key="your-api-key",
storage_provider="s3",# s3, gcs
storage_provider="s3",# s3, gcs
bucket_name="your-bucket-name",
bucket_name="your-bucket-name",
session="your-session-name",# files should be located in this folder on which batch inference will be run
session="your-session-name",# files should be located in this folder on which batch inference will be run
role_arn="your-role-arn",
role_arn="your-role-arn",
system_prompt="your-system-prompt",
system_prompt="your-system-prompt",
region="your-bucket-region",
)
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
resp=llm.complete(
resp=llm.complete(
question="your-question",
question="your-question",
model="chhoose-model",# currently we support mistral7b, llama7b, mixtral8x7b,codellama70b, llama70b, more to come...
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
max_tokens=5,# number of tokens to generate, default is 10
)
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# The response indicated that the final output is stored in your bucket or raises an exception if the job failed
# The response indicated that the final output is stored in your bucket or raises an exception if the job failed
print(resp)
print(resp)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Asynchronous Requests by using `acomplete` endpoint
## Asynchronous Requests by using `acomplete` endpoint
For asynchronous operations, use the following approach.
For asynchronous operations, use the following approach.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
importasyncio
importasyncio
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
asyncdefmain():
asyncdefmain():
allm=MyMagicAI(
allm=MyMagicAI(
api_key="your-api-key",
api_key="your-api-key",
storage_provider="s3",# s3, gcs
storage_provider="s3",# s3, gcs
bucket_name="your-bucket-name",
bucket_name="your-bucket-name",
session="your-session-name",# files should be located in this folder on which batch inference will be run
session="your-session-name",# files should be located in this folder on which batch inference will be run
role_arn="your-role-arn",
role_arn="your-role-arn",
system_prompt="your-system-prompt",
system_prompt="your-system-prompt",
region="your-bucket-region",
)
)
response=awaitallm.acomplete(
response=awaitallm.acomplete(
question="your-question",
question="your-question",
model="chhoose-model",# currently we support mistral7b, llama7b, mixtral8x7b,codellama70b, llama70b, more to come...
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
max_tokens=5,# number of tokens to generate, default is 10
description="The session to use. This is a subfolder in the bucket where your data is located.",
description="The session to use. This is a subfolder in the bucket where your data is located.",
)
)
role_arn:Optional[str]=Field(
role_arn:Optional[str]=Field(
None,description="ARN for role assumption in AWS S3"
None,description="ARN for role assumption in AWS S3."
)
)
system_prompt:str=Field(
system_prompt:str=Field(
default="Answer the question based only on the given content. Do not give explanations or examples. Do not continue generating more text after the answer.",
default="Answer the question based only on the given content. Do not give explanations or examples. Do not continue generating more text after the answer.",
...
@@ -45,6 +45,9 @@ class MyMagicAI(LLM):
...
@@ -45,6 +45,9 @@ class MyMagicAI(LLM):
question_data:Dict[str,Any]=Field(
question_data:Dict[str,Any]=Field(
default_factory=dict,description="The data to send to the MyMagicAI API."
default_factory=dict,description="The data to send to the MyMagicAI API."
)
)
region:Optional[str]=Field(
"eu-west-2",description="The region the bucket is in. Only used for AWS S3."