Create New OpenAI Context Class Via REST API
NOTE: This API is a part of the Mona-OpenAI integration client. Please read Mona-OpenAI integration documentation first to learn how to work with Mona and OpenAI.
OpenAI's API serves as a powerful tool for developers and AI enthusiasts, offering access to advanced artificial intelligence models and capabilities. By integrating the OpenAI API with Mona, users gain a valuable solution to track and optimize the performance of their AI systems. This integration facilitates the seamless transmission of data and metadata from user calls, enabling users to monitor both the OpenAI API and their own projects effectively.
For this, users can now leverage Mona's /create_openai_context_class REST API endpoint and create a new context class to monitor their OpenAI project on Mona.
To access Mona's API, first, an accessToken must be generated and added to the request.
Once users have their accessToken they can add it to their authorization and send a POST request with the following mandatory params:
- "context_class" - the name of class being created
- "openai_api_type" - the type of endpoint used on OpenAI
curl --location --request POST 'https://api{YOUR-USER-ID}.monalabs.io/create_openai_context_class' \
--header 'Authorization: Bearer {YOUR-ACCESS-TOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
"context_class": "YOUR-CONTEXT-CLASS-NAME",
"openai_api_type": "YOUR-OPENAI-TYPE"
}'
import requests
import json
url = "https://api{YOUR-USER-ID}.monalabs.io/create_openai_context_class"
payload = json.dumps({
"context_class": {YOUR-CONTEXT-CLASS-NAME},
"openai_api_type": {YOUR-OPENAI-TYPE}
})
headers = {
'Authorization': 'Bearer {YOUR-ACCESS-TOKEN}',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
from mona_sdk.client import Client
api_key = <YOUR-API-KEY>
secret = <YOUR-SECRET>
my_mona_client = Client(api_key, secret)
my_mona_client.create_openai_context_class(
context_class=<YOUR-CONTEXT-CLASS-NAME>,
openai_api_type=<YOUR-OPENAI-TYPE>
)
The response will be the config that was uploaded to Mona:
{
"YOUR-USER-ID": {
"YOUR-CONTEXT-CLASS-NAME": {
"fields": {
"input_model": {
"type": "string",
"sources": [
{
"names": [
"input.model",
"input.engine"
],
"default_value": null
}
]
},
"input_max_tokens": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 10,
"min_value": 10,
"max_value": 100
}
},
"source": "input.max_tokens"
},
"input_n": {
"type": "numeric",
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.4,
"min_value": 1,
"max_value": 5
}
},
"source": "input.n"
},
"input_temperature": {
"type": "numeric",
"function": "identity",
"args": [],
"segmentations": {
"original": {
"default": true,
"bucket_size": 0.2,
"min_value": 0,
"max_value": 2
}
},
"source": "input.temperature"
},
"api_name": {
"type": "string"
},
"is_async": {
"type": "boolean",
"function": "use_value_mapping",
"source": "is_async",
"args": [
"internal_possible_boolean_values"
]
},
"is_exception": {
"type": "boolean",
"function": "use_value_mapping",
"source": "is_exception",
"args": [
"internal_possible_boolean_values"
]
},
"latency": {
"type": "numeric",
"segmentations": {
"original": {
"bucket_size": 0.1,
"bucket_offset": 0,
"default": true
}
}
},
"response_finish_reason": {
"type": "string",
"source": "response.choices",
"function": "all_values_field_in_array",
"args": [
"finish_reason"
]
},
"response_created": {
"type": "timestamp",
"source": "response.created"
},
"response_id": {
"type": "string",
"source": "response.id"
},
"response_model": {
"type": "string",
"source": "response.model"
},
"response_object": {
"type": "string",
"source": "response.object"
},
"response_completion_tokens": {
"type": "numeric",
"source": "response.usage.completion_tokens",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1
}
}
},
"response_prompt_tokens": {
"type": "numeric",
"source": "response.usage.prompt_tokens",
"segmentations": {
"original": {
"default": true,
"bucket_size": 1
}
}
},
"response_total_tokens": {
"type": "numeric",
"source": "response.usage.total_tokens",
"segmentations": {
"original": {
"default": true,
"bucket_size": 2
}
}
},
"analysis_prompt_email_count": {
"type": "numeric",
"source": "analysis.privacy.prompt_email_count",
"segmentations": {
"original": {
"default": true,
"bucket_size": 2
}
}
},
"analysis_prompt_phone_number_count": {
"type": "numeric",
"source": "analysis.privacy.prompt_phone_number_count",
"segmentations": {
"original": {
"default": true,
"bucket_size": 2
}
}
},
"analysis_answer_unknown_email_count": {
"type": "numeric",
"source": "analysis.privacy.answer_unkown_email_count",
"segmentations": {
"original": {
"default": true,
"bucket_size": 2
}
}
},
"analysis_answer_unknown_phone_number_count": {
"type": "numeric",
"source": "analysis.privacy.answer_unknown_phone_number_count",
"segmentations": {
"original": {
"default": true,
"bucket_size": 2
}
}
},
"analysis_prompt_profanity_prob": {
"type": "numeric",
"source": "analysis.profanity.prompt_profanity_prob",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"prompt_is_profanity": {
"type": "boolean",
"function": "range_check",
"source": "analysis_prompt_profanity_prob",
"args": [
[
{
"left": {
"value": 0.5,
"inclusive": false
}
}
]
]
},
"analysis_answer_profanity_prob": {
"type": "numeric",
"source": "analysis.profanity.answer_profanity_prob",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_prompt_length": {
"type": "numeric",
"source": "analysis.textual.prompt_length",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_prompt_preposition_count": {
"type": "numeric",
"source": "analysis.textual.prompt_preposition_count",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_prompt_preposition_factor": {
"type": "numeric",
"source": "analysis.textual.prompt_preposition_factor",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_prompt_preposition_ratio": {
"type": "numeric",
"source": "analysis.textual.prompt_preposition_ratio",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_prompt_word_count": {
"type": "numeric",
"source": "analysis.textual.prompt_word_count",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_answer_words_not_in_prompt_count": {
"type": "numeric",
"source": "analysis.textual.answer_words_not_in_prompt_count",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_answer_length": {
"type": "numeric",
"source": "analysis.textual.answer_length",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_answer_preposition_count": {
"type": "numeric",
"source": "analysis.textual.answer_preposition_count",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_answer_preposition_factor": {
"type": "numeric",
"source": "analysis.textual.answer_preposition_factor",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_answer_preposition_ratio": {
"type": "numeric",
"source": "analysis.textual.answer_preposition_ratio",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_answer_word_count": {
"type": "numeric",
"source": "analysis.textual.answer_word_count",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
},
"analysis_answer_words_not_in_prompt_ratio": {
"type": "numeric",
"source": "analysis.textual.answer_words_not_in_prompt_ratio",
"segmentations": {
"original": {
"default": true,
"should_log": true
}
}
}
},
"data": {
"internal_possible_boolean_values": {
"True": true,
"true": true,
"False": false,
"false": false
}
},
"main_kpis": [
{
"chart_type": "time_series",
"warnings": {},
"data_segment": {},
"metric": {
"type": "amount"
},
"time_period": "1w"
},
{
"chart_type": "time_series",
"warnings": {
"low_severity": {
"above": 0.55
},
"high_severity": {
"above": 0.6
}
},
"data_segment": {},
"metric": {
"type": "average",
"field": "latency"
},
"time_period": "1d"
},
{
"chart_type": "time_series",
"warnings": {
"low_severity": {
"below": 20
},
"high_severity": {
"below": 10
}
},
"data_segment": {},
"metric": {
"type": "average",
"field": "analysis_textual_answer_word_count"
},
"time_period": "1d"
}
]
}
}
}
Updated 25 days ago