Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions backend/openedx_ai_extensions/processors/litellm_base_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,36 @@ class LitellmProcessor:

def __init__(self, config=None, user_session=None):
config = config or {}

class_name = self.__class__.__name__
self.config = config.get(class_name, {})
self.config = config.get(self.__class__.__name__, {})
self.user_session = user_session

self.config_profile = self.config.get("config", "default")
provider_spec = self.config.get("provider", "default")
self.config_profile = provider_spec
if isinstance(provider_spec, str):
providers = getattr(settings, "AI_EXTENSIONS", {})
provider = providers.get(provider_spec)

if provider is None and provider_spec != "default":
raise ValueError(f"Unknown AI_EXTENSIONS profile '{provider_spec}'")

provider = provider or {}
else:
raise TypeError("`provider` must be a string")

options = self.config.get("options", {}) or {}

if "MODEL" not in settings.AI_EXTENSIONS[self.config_profile]:
base_params = {k.lower(): v for k, v in provider.items()}
override_params = {k.lower(): v for k, v in options.items()}
self.extra_params = {**base_params, **override_params}

model = self.extra_params.get("model")
if not isinstance(model, str) or "/" not in model:
raise ValueError(
f"AI_EXTENSIONS config '{self.config_profile}' missing 'MODEL' setting."
"MODEL must be defined and have the format 'provider/model_name'. "
"e.g., 'openai/gpt-4'"
)
try:
self.provider = settings.AI_EXTENSIONS[self.config_profile].get("MODEL").split("/")[0]
except Exception as exc:
raise ValueError(
"MODEL setting must be in the format 'provider/model_name'. e.g., 'openai/gpt-4'"
) from exc

self.extra_params = {}
for key, value in settings.AI_EXTENSIONS[self.config_profile].items():
self.extra_params[key.lower()] = value

self.provider = model.split("/")[0]
self.custom_prompt = self.config.get("prompt", None)
self.stream = self.config.get("stream", False)

Expand All @@ -60,7 +68,7 @@ def __init__(self, config=None, user_session=None):
if allowed_mcp_configs:
self.mcp_configs = {
key: value
for key, value in settings.AI_EXTENSIONS_MCP_CONFIGS.items()
for key, value in getattr(settings, 'AI_EXTENSIONS_MCP_CONFIGS', {}).items()
if key in allowed_mcp_configs
}
self.extra_params["tools"] = [
Expand Down
4 changes: 0 additions & 4 deletions backend/openedx_ai_extensions/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ class AIWorkflowProfile(models.Model):
help_text="JSON5 Merge Patch (RFC 7386) to apply to base template. Supports comments and trailing commas."
)

class Meta:
verbose_name = "AI Workflow Profile"
verbose_name_plural = "AI Workflow Profiles"

def __str__(self):
return f"{self.slug} ({self.base_filepath})"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ have it explain in a different with this prompt.
"function": "get_location_content"
},
"LLMProcessor": {
"config": "default",
"provider": "default",
"stream": true,
"prompt": "\
You are an educational assistant embedded in an online course. \
Expand All @@ -33,14 +33,14 @@ Output only the rephrased content. \
"UIComponents": {
"request": {
"component": "AIRequestComponent",
"config": {
"provider": {
"buttonText": "Rephrase",
"customMessage": "Explain this but differently"
}
},
"response": {
"component": "AIResponseComponent",
"config": {
"provider": {
"customMessage": "In other words"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Works only in studio UI and over the CMS service_variant.
},
"EducatorAssistantProcessor": {
"function": "generate_quiz_questions",
"config": "default"
"provider": "default"
}
},
"actuator_config": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
A profile that stores the config directy in json.
Useful for getting started or testing API_KEYS
*/
{
"orchestrator_class": "DirectLLMResponse",
"processor_config": {
"OpenEdXProcessor": {
},
"LLMProcessor": {
"stream": true,
"prompt": "Say hi and tell me: which LLM model are you? Be specific.",
"options": {
"MODEL": "openai/gpt-4.1-mini",
"API_KEY": "sk-proj-put-your-api-key-here",
},
}
},
"actuator_config": {
"UIComponents": {
"request": {
"component": "AIRequestComponent",
"config": {
"buttonText": "Hello AI",
"customMessage": "Call any AI with any config"
}
},
"response": {
"component": "AIResponseComponent",
"config": {
"customMessage": "The response from AI"
}
}
}
},
"schema_version": "1.0",
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ present the streaming answer in the same box.
},
"LLMProcessor": {
"function": "summarize_content",
"config": "default",
"provider": "default",
"stream": true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ to retrieve context from the current unit and the course outline
},
"LLMProcessor": {
"function": "answer_question",
"config": "anthropic",
"provider": "anthropic",
"enabled_tools": [
"get_context",
"get_location_content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Test experience. Ask claude to say which llm model is answering
},
"LLMProcessor": {
"function": "greet_from_llm",
"config": "anthropic"
"provider": "anthropic"
}
},
"actuator_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Test experience. Ask claude to chat having given it the current unit context
},
"LLMProcessor": {
"function": "chat_with_context",
"config": "anthropic"
"provider": "anthropic"
},
"SubmissionProcessor": {
"function": "get_chat_history",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ to retrieve context from the current unit and the course outline
},
"LLMProcessor": {
"function": "chat_with_context",
"config": "anthropic",
"provider": "anthropic",
"enabled_tools": [
"get_context",
"get_location_content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Test experience. Use a hosted DeepSeek to chat having given it the current unit
},
"LLMProcessor": {
"function": "chat_with_context",
"config": "deepseek"
"provider": "deepseek"
},
"SubmissionProcessor": {
"function": "get_chat_history",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Test experience. Use a hugging face hosted version of DeepSeek to say which llm
},
"LLMProcessor": {
"function": "greet_from_llm",
"config": "deepseek"
"provider": "deepseek"
}
},
"actuator_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ to retrieve context from the current unit and the course outline
},
"LLMProcessor": {
"function": "answer_question",
"config": "openai",
"provider": "openai",
"enabled_tools": [
"get_context",
"get_location_content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Test experience. Ask ChatGPT to say which llm model is answering
},
"LLMProcessor": {
"function": "greet_from_llm",
"config": "openai"
"provider": "openai"
}
},
"actuator_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Test experience. Ask ChatGPT to chat having given it the current unit context
},
"LLMProcessor": {
"function": "chat_with_context",
"config": "openai",
"provider": "openai",
"stream": true
},
"SubmissionProcessor": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ to retrieve context from the current unit and the course outline
},
"LLMProcessor": {
"function": "chat_with_context",
"config": "openai",
"provider": "openai",
"enabled_tools": [
"get_context",
"get_location_content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See: https://gist.github.com/felipemontoya/509495d3fbaa696fa2b684880a8388da
},
"LLMProcessor": {
"function": "greet_from_llm",
"config": "ollama"
"provider": "ollama"
}
},
"actuator_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See: https://gist.github.com/felipemontoya/509495d3fbaa696fa2b684880a8388da
},
"LLMProcessor": {
"function": "greet_from_llm",
"config": "qwen25"
"provider": "qwen25"
}
},
"actuator_config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See: https://gist.github.com/felipemontoya/509495d3fbaa696fa2b684880a8388da
},
"LLMProcessor": {
"function": "summarize_content",
"config": "qwen25"
"provider": "qwen25"
}
},
"actuator_config": {
Expand Down
2 changes: 1 addition & 1 deletion backend/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def root(*args):
AI_EXTENSIONS = {
"default": {
"API_KEY": "test-api-key",
"MODEL": "gpt-3.5-turbo",
"MODEL": "openai/gpt-3.5-turbo",
"TIMEOUT": 30,
"TEMPERATURE": 0.7,
"MAX_TOKENS": 1000,
Expand Down
Loading