? Ask Sage Python Client v1.2.4
Welcome to the Ask Sage Overview repository! ?
This repository is a work in progress project ? and is intended to be a collection of sample code ? and documentation ? on interacting with Ask Sage via the Ask Sage API. Additional content may include actual steps ? within the Ask Sage platform, but for the most part this repository will focus on utilizing the API and creating mini proof-of-concept projects.
Examples provided will cover a wide range of topics related to generative AI and will be designed to be accessible to users with varying levels of experience with AI and programming. At the moment we have provided a list of ideas of what will be covered in this repository and will be updated as more content is added.
Note: Only the Ask Sage API is available to paid subscribers. ??
This is a community-driven effort to provide additional resources and examples for users of Ask Sage .
Visit the official AskSage website here.
If you are interested in contributing to this repository, please see the Contributing Guidelines for more information.
If you have any questions or need help, feel free to reach out to the maintainers of this repository or the Ask Sage team directly.
Additional resources:
Note: the content in this repository may be outdated or incorrect, so please refer to the official AskSage documentation for the most up-to-date information.
AskSage is a agnostic Generative AI platform that gives access to a wide range of AI models and tools. The platform is designed to be easy to use and integrate into existing workflows that can be further customized to meet the needs of the user/organization.
Uniquely designed to be agnostic, Ask Sage provides access to a wide range of models that can be used for a variety of tasks. Some of the models available include but not limited to:
Model Name | Description |
---|---|
Azure OpenAI | Cutting-edge language models developed by OpenAI and hosted on the Azure platform. |
Azure Gov OpenAI | Cutting-edge language models developed by OpenAI and hosted on the Azure Gov platform. |
Google Gemini Pro | Language models developed by Google and optimized for various natural language processing tasks. |
LLMA3 | A large language model developed by Meta that excels in generating high-quality text. |
Mistral | A powerful language model developed by Mistral that can generate creative and coherent text. |
Claude 3 | A language model developed by Anthropic that focuses on generating code and programming-related text. |
Cohere | A language model developed by Cohere Technologies that specializes in generating code. |
OpenAI Whisper | A language model developed by OpenAI that enables speech-to-text capabilities. |
DALL-E v3 | A language model developed by OpenAI that specializes in generating images. |
Here is the actual list of available models on the Ask Sage platform as of Oct 22, 2024:
models = ['aws-bedrock-titan', 'llma3', 'claude2', 'claude-3-opus', 'claude-3-sonnet', 'claude-35-sonnet', 'cohere', 'mistral-large', 'gpt-gov', 'gpt4-gov', 'gpt', 'gpt4', 'gpt4-32k', 'gpt35-16k', 'gpt4-vision', 'gpt-4o', 'gpt-4o-mini', 'dall-e-2', 'dall-e-3', 'google-bison', 'google-gemini-pro', 'gpt-4o-gov', 'groq-70b', 'gpt-o1', 'gpt-o1-mini', 'xai-grok']
More models can be added by the Ask Sage team that are specific to a user's needs. (additional costs may apply)
Note: The models listed above are subject to change and more models may be added in the future.
There are two main ways to interact with Ask Sage:
The Ask Sage API provides a RESTful interface for interacting with the models available through the platform. Users can send requests to the API and receive responses in JSON format. The API is designed to be easy to use and integrate into existing workflows.
Overall, this repository will provide setup instructions, examples, and other resources as one begins to explore the capabilities of Generative AI and how it can be used in real-world scenarios.
The Ask Sage API is documented using Swagger, which provides detailed information about the available endpoints, request parameters, response formats, and authentication methods.
The following table shows the available endpoints in the User API:
Endpoint | Description |
---|---|
/get-token-with-api-key | Get an access token with API Key and email |
/get-user-logins | Get your last logins (limited to 5 by default) |
/get-user-logs | Get your last prompts |
/add-dataset | Add a new dataset |
/assign-dataset | Assign a dataset |
/delete-datasets | Deletes a dataset |
This information is used to interact with the Ask Sage API. The user can query models, select/get personas, get datasets, train models and more.
The following table shows the available endpoints in the Server API:
Endpoint | Description |
---|---|
/get-models | Returns a list of available models via the Ask Sage services |
/query | Main endpoint for generating completions based on the user's input |
/query_with_file | Query with file endpoint for generating completions based on the user's input |
/query-plugin | Query with plugin endpoint for generating completions based on the user's input |
/execute-plugin | Execute a plugin with the provided content |
/follow_up_questions | Endpoint for generating follow-up questions based on the user's input |
/tokenizer | Endpoint for getting tokens of string value |
/get-personas | Endpoint for getting the tokens of string |
/get-datasets | Returns a list of available datasets |
/get-plugins | Returns a list of available plugins |
/get-train | Trains the model based on the user's input |
/file | Converts a supported file to plain/text |
The Python API client is documented and managed via the following link: https://pypi.org/project/asksageclient/
Function Name | Description |
---|---|
get_models |
Get the available models from the Ask Sage service. |
add_dataset |
Adds a new dataset |
delete_dataset |
Deletes a specified dataset |
assign_dataset |
Assigns a dataset |
get_user_logs |
Retrieves all logs for user |
get_user_logins |
Retrieves login information for a specific user |
query |
Interact with the /query endpoint of the Ask Sage API. |
query_with_file |
Executes a query using a file |
query_plugin |
Executes a query using a specific plugin |
execute_plugin |
Executes a plugin with the provided content |
follow_up_questions |
Interact with the /follow-up-questions endpoint of the Ask Sage API. |
tokenizer |
Interact with the /tokenizer endpoint of the Ask Sage API. |
get_personas |
Get the available personas from the Ask Sage service. |
get_datasets |
Get the available datasets from the Ask Sage service. |
get_plugins |
Get the available plugins from the Ask Sage service. |
count_monthly_tokens |
Get the count of monthly training tokens spent for this user from the Ask Sage service. |
count_monthly_teach_tokens |
Counts the number of teach tokens used in a month |
train |
Train the model based on the provided content. |
train_with_file |
Train the dataset based on the provided file. |
file |
Upload a file to the Ask Sage service. |
In the Example section, we will provide examples of how to use these endpoints to interact with the Ask Sage API and generate text using the models available on the platform.
Users can obtain an API key from the Ask Sage platform and use it to generate an access token. The API key is a unique identifier that is used to authenticate the user and grant access to the API endpoints.
Navigate to the menu options and select the 'Account & Tokens' option.
Scroll down to the 'API Keys' section and click on the 'Generate API Key' button.
Create a new API Key by selecting the 'Create a new API Key' button. Provide a unique name for the API Key and click on the 'Submit' button.
The API Key will be generated and displayed on the screen. Copy the API Key and store it in a secure location.
There are three methods to which a user can authenticate with the Ask Sage Endpoints:
The API key and email can be used to authenticate the user and grant access via the Ask Sage Python Client. The API key and user email will be included in the request headers.
For example, the following code snippet demonstrates how to create an instance of the AskSageClient class and authenticate with the Ask Sage API using the API key and email:
import json # Import the json module to work with JSON data
import requests # Import the requests library to send HTTP requests
from asksageclient import AskSageClient # Import the AskSageClient class from the asksageclient module
# Function to load credentials from a JSON file
def load_credentials(filename):
try:
with open(filename) as file:
return json.load(file)
except FileNotFoundError:
raise FileNotFoundError("The credentials file was not found.")
except json.JSONDecodeError:
raise ValueError("Failed to decode JSON from the credentials file.")
# Load the credentials
credentials = load_credentials('../../credentials.json')
# Extract the API key, and email from the credentials to be used in the API request
api_key = credentials['credentials']['api_key']
email = credentials['credentials']['Ask_sage_user_info']['username']
"""
class AskSageClient(
email: email, # The email address of the user
api_key: api_key, # The API key for the Ask Sage API, which can be obtained from the Ask Sage website
user_base_url: str = 'https://api.asksage.ai/user', # The base URL for the user API
server_base_url: str = 'https://api.asksage.ai/server' # The base URL for the server API
)
"""
ask_sage_client = AskSageClient(email, api_key) # Create an instance of the AskSageClient class with the email and api_key
Following this setup the user can now interact with the Ask Sage API using the AskSageClient object.
An access token is generated using the API key and email address with the endpoint '/get-token-with-api-key'. The access token is valid for 24 hours and can be used to authenticate requests to the Ask Sage API.
This is a more secure method of authentication as the access token is only valid for a limited time and must be regenerated periodically.
Here is a sample code snippet in Python that demonstrates how to obtain an access token using your email address and API key:
import requests
# Define the endpoint URL
url = "https://api.asksage.ai/user/get-token-with-api-key"
# Define the payload with the user's email and API key
payload = {
"email": "your_email@your_domain.com",
"api_key": "sdfsdfsfr23456789" # Your API key generated from the Ask Sage platform
}
# Set the headers, if required (e.g., Content-Type)
headers = {
"Content-Type": "application/json"
}
# Make the POST request
response = requests.post(url, json=payload, headers=headers)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
data = response.json()
# raw response
print(data)
# Extract the access token only from the response
access_token = data['response']['access_token']
print(access_token)
The generated access token can be used to authenticate requests to the Ask Sage API for the next 24 hours. Here is an example of how to use the access token to authenticate a request to any of the Ask Sage API endpoints:
import requests
# Define the access token obtained from the previous request - Note: You would want to store this securely and not hardcode it in your script/file.
access_token = "fghjkl4567890" # Replace with the actual access token
# Define the endpoint URL
url = "https://api.asksage.ai/user/get-user-logins" # Replace with the actual base URL of the API
# Define the payload with the limit parameter
payload = {
"limit": 1 # Replace with the desired limit (max is 100)
}
# Set the headers, including the Authorization header with the Bearer token
headers = {
"x-access-tokens": access_token,
"Content-Type": "application/json"
}
# Make the POST request
response = requests.post(url, json=payload, headers=headers)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
data = response.json()
print("User Logins:", data)
else:
print(f"Failed to get user logins. Status code: {response.status_code}")
print(f"Response: {response.text}")
Instead of generating an access token every time you need to access the API, you can pass the static API key where the token is expected. This is not as secure as generating a 24 hour access token, but it is a valid option for some use cases.
Note: The expected header variable is
x-access-tokens
and the value is the API key. There is no time limit on the API key, but it is recommended to regenerate it periodically for security reasons.
import requests
# Define the access token obtained from the previous request - Note: You would want to store this securely and not hardcode it in your script/file.
access_token = api_key #
# Define the endpoint URL
url = "https://api.asksage.ai/user/get-user-logins" # Replace with the actual base URL of the API
# Define the payload with the limit parameter
payload = {
"limit": 1 # Replace with the desired limit (max is 100)
}
# Set the headers, including the Authorization header with the Bearer token
headers = {
"x-access-tokens": access_token,
"Content-Type": "application/json"
}
# Make the POST request
response = requests.post(url, json=payload, headers=headers)
# Check if the request was successful
if response.status_code == 200:
# Parse the JSON response
data = response.json()
print("User Logins:", data)
else:
print(f"Failed to get user logins. Status code: {response.status_code}")
print(f"Response: {response.text}")
These examples will be more focused on how one can interact with the Ask Sage API and what to expect in the response. Additionally, some mini projects will be created to demonstrate the capabilities of Generative AI and how it can be used in real-world scenarios. Although this repository is focused on the Ask Sage API, the examples will be general enough to be applied to other platforms that provide similar services but may have different endpoints or parameters.
Note: The examples at the moment are more focused on text-based models but will be expanded to the interaction of LLM's with other data types like images, audio, and video (multi-modal models). Going into those examples will lead to more complex projects and will require more resources and time to complete.
After installing packages from requirements.txt
, you may need to restart your Jupyter kernel to use the updated packages. This ensures that the newly installed libraries are loaded correctly.
✅ Done ✅
This is not really an example but more of a discussion on the ethical implications of using AI and how to mitigate any potential risks. We place a strong emphasis that a user needs to be well trained on how AI works, but also provide a clear understanding that what is generated through GenAI tools may not always be correct.
✅ Done ✅
This example will cover how to use the Ask Sage API endpoints and what to expect in the responses at a high level. The follow on examples will show how the endpoints can be used in a real-world scenarios to create useful applications, tools, or services.
? In Construction ? --> Full Release Coming Soon!
This example will cover how to interact with a LLM model and how to use prompt engineering to generate high-quality text to be used to guide the model in generating the desired output. Prompt engineering is a powerful and necessary skill that can be used to control the output of a language model and generate text that meets specific criteria or requirements.
? In Construction ?
For the most part, LLM models are trained on large datasets that contain a wide range of text from various sources and are not guaranteed to be relevant to the user's specific needs. However, on Ask Sage, users can create custom datasets that contain text that is relevant to their domain or use case and use it with methods like Retrieval-Augmented Generation (RAG) to improve the performance of the model. Thus, this example will cover how to create a custom dataset and use it with a LLM model to generate text that is more relevant to the user's needs. More detailed information will be provided within the example on how the model works/integrates with the dataset.
? In Construction ?
The number of LLM models available in today is vast and will continue to grow as more research is done in the field of generative AI. This example will cover how to compare different LLM models using Ask Sage agnostic API method, and evaluate their performance based on various criteria such as text quality, coherence, creativity, and more. Users can use this information to select the best model for their needs and make informed decisions about which model to use in their projects.
To go to this section click Comparing LLM Models
? In Construction ?
This is a unique project and will probably be outdated in the future but, LLMs are text-based models that generate text based on the input provided by the user, but what if we wanted to generate a diagram without having to manually create it? For example let's say we wanted a flowchart, mind map, Gantt chart, or any other type of diagram. This example will cover how we use mermaid.js a text-based diagram creation tool to generate diagrams based on the text generated by the LLM model.
To go to this section click Diagram Creation With LLMs
? In Construction ?
What about being able to deploy a LLM model on a edge device like a Raspberry Pi or Jetson Nano? This example will cover how to deploy a LLM model on a edge device and generate text utilizing the Ask Sage API.
To go to this section click LLM Deployment On A Edge Device
? In Construction ?
How do we evaluate the performance of a LLM model and monitor its progress over time? This example will cover how to create a dashboard that displays key metrics and insights about the LLM model. Users can use this dashboard to track the performance of the model and make informed decisions about how to improve it over time.
But first, we will use @arize-ai phoenix open source tool to create a dashboard that displays key metrics and insights about the LLM model.
? In Construction ?
Let's create a network of chatbots that can communicate with each other and generate text based on each other's output. This example will cover how to create a chatbot network using LLM models and simulate a conversation between the chatbots. Users can use this network to generate creative and engaging text that can be used in a variety of applications, scenarios, and modeling use cases.
To go to this section click LLM Chatbot Network
Here we are providing a list of additional examples that originate from users asking for specific examples or use cases. If you have a specific example or use case you would like to see, please reach out to us and we will do our best to create an example that meets your needs. The best way to reach out to us is by joining our discord server and posting your request there Discord - Ask Sage :
The AskSage API may return errors in certain situations, such as when an invalid request is made or when the rate limit is exceeded. Users should be familiar with the error codes and messages returned by the API and handle them appropriately in their code.
Here are some best practices to keep in mind when working with the Ask Sage API:
We will provide additional pdf documents that will contain resources related to GenerativeAI (GenAI). This document will include links to articles, books, tutorials, videos, and other content that may be helpful for users who are interested in learning more about generative AI and how to use it effectively.
Our goal is to provide a comprehensive list of resources that cover a wide range of topics related to generative AI, including natural language processing, computer vision, reinforcement learning, and more. We will also include resources that cover specific models and tools that are commonly used in the field of generative AI.
If you have any suggestions for resources to include in this document, please feel free to reach out to us and we will do my best to add them to the list.
Happy learning! ?
We will be providing a list of vocabulary that are important to know when working with Generative AI or Machine Learning. These terms will help users understand the terminology used in the field of AI/Machine Learning and how to apply it in their projects.
For example here are some terms to know when working with Generative AI:
To view the full list of definitions click Defintions To Know
Here are some features or enhancements that we would like to see added to the Ask Sage API:
Each item will have a link to the example that will be created to demonstrate where the feature or enhancement can be used.
Any bugs or issues found in the Ask Sage API should be reported to the Ask Sage team directly. If you encounter any problems with the API, please reach out to the Ask Sage team for assistance. Additionally, you can report bugs or issues in this repository and we will test and verify them before forwarding them to the Ask Sage team.
This repository is licensed under the MIT License. See the LICENSE file for more information.