mirror of
https://github.com/hanzo-io/team.git
synced 2026-10-30 18:56:23 +00:00
67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
import frappe
|
|
import openai
|
|
|
|
from raven.ai.handler import get_variables_for_instructions
|
|
|
|
|
|
@frappe.whitelist()
|
|
def get_instruction_preview(instruction):
|
|
"""
|
|
Function to get the rendered instructions for the bot
|
|
"""
|
|
frappe.has_permission(doctype="Raven Bot", ptype="write", throw=True)
|
|
|
|
instructions = frappe.render_template(instruction, get_variables_for_instructions())
|
|
return instructions
|
|
|
|
|
|
@frappe.whitelist()
|
|
def get_saved_prompts(bot: str = None):
|
|
"""
|
|
API to get the saved prompt for a user/bot/global
|
|
"""
|
|
or_filters = [["is_global", "=", 1], ["owner", "=", frappe.session.user]]
|
|
|
|
prompts = frappe.get_list(
|
|
"Raven Bot AI Prompt", or_filters=or_filters, fields=["name", "prompt", "is_global", "raven_bot"]
|
|
)
|
|
|
|
# Order by ones with the given bot
|
|
prompts = sorted(prompts, key=lambda x: x.get("raven_bot") == bot, reverse=True)
|
|
|
|
return prompts
|
|
|
|
|
|
@frappe.whitelist()
|
|
def get_open_ai_version():
|
|
"""
|
|
API to get the version of the OpenAI Python client
|
|
"""
|
|
frappe.has_permission(doctype="Raven Bot", ptype="read", throw=True)
|
|
return openai.__version__
|
|
|
|
|
|
@frappe.whitelist()
|
|
def get_openai_available_models():
|
|
"""
|
|
API to get the available OpenAI models for assistants
|
|
"""
|
|
frappe.has_permission(doctype="Raven Bot", ptype="read", throw=True)
|
|
from raven.ai.openai_client import get_openai_models
|
|
|
|
models = get_openai_models()
|
|
|
|
valid_prefixes = ["gpt-4", "gpt-3.5", "o1", "o3-mini"]
|
|
|
|
# Model should not contain these words
|
|
invalid_models = ["realtime", "transcribe", "search", "audio"]
|
|
|
|
compatible_models = []
|
|
|
|
for model in models:
|
|
if any(model.id.startswith(prefix) for prefix in valid_prefixes):
|
|
if not any(word in model.id for word in invalid_models):
|
|
compatible_models.append(model.id)
|
|
|
|
return compatible_models
|