mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-04 21:29:12 +00:00
Rename OpenAIProcessorConversationConfig DB model to more apt AiModelApi (#998)
* Rename OpenAIProcessorConversationConfig to more apt AiModelAPI The DB model name had drifted from what it is being used for, a general chat api provider that supports other chat api providers like anthropic and google chat models apart from openai based chat models. This change renames the DB model and updates the docs to remove this confusion. Using Ai Model Api we catch most use-cases including chat, stt, image generation etc.
This commit is contained in:
@@ -181,7 +181,7 @@ class Subscription(DbBaseModel):
|
||||
enabled_trial_at = models.DateTimeField(null=True, default=None, blank=True)
|
||||
|
||||
|
||||
class OpenAIProcessorConversationConfig(DbBaseModel):
|
||||
class AiModelApi(DbBaseModel):
|
||||
name = models.CharField(max_length=200)
|
||||
api_key = models.CharField(max_length=200)
|
||||
api_base_url = models.URLField(max_length=200, default=None, blank=True, null=True)
|
||||
@@ -200,9 +200,7 @@ class ChatModelOptions(DbBaseModel):
|
||||
chat_model = models.CharField(max_length=200, default="bartowski/Meta-Llama-3.1-8B-Instruct-GGUF")
|
||||
model_type = models.CharField(max_length=200, choices=ModelType.choices, default=ModelType.OFFLINE)
|
||||
vision_enabled = models.BooleanField(default=False)
|
||||
openai_config = models.ForeignKey(
|
||||
OpenAIProcessorConversationConfig, on_delete=models.CASCADE, default=None, null=True, blank=True
|
||||
)
|
||||
ai_model_api = models.ForeignKey(AiModelApi, on_delete=models.CASCADE, default=None, null=True, blank=True)
|
||||
|
||||
|
||||
class VoiceModelOption(DbBaseModel):
|
||||
@@ -504,26 +502,24 @@ class TextToImageModelConfig(DbBaseModel):
|
||||
model_name = models.CharField(max_length=200, default="dall-e-3")
|
||||
model_type = models.CharField(max_length=200, choices=ModelType.choices, default=ModelType.OPENAI)
|
||||
api_key = models.CharField(max_length=200, default=None, null=True, blank=True)
|
||||
openai_config = models.ForeignKey(
|
||||
OpenAIProcessorConversationConfig, on_delete=models.CASCADE, default=None, null=True, blank=True
|
||||
)
|
||||
ai_model_api = models.ForeignKey(AiModelApi, on_delete=models.CASCADE, default=None, null=True, blank=True)
|
||||
|
||||
def clean(self):
|
||||
# Custom validation logic
|
||||
error = {}
|
||||
if self.model_type == self.ModelType.OPENAI:
|
||||
if self.api_key and self.openai_config:
|
||||
if self.api_key and self.ai_model_api:
|
||||
error[
|
||||
"api_key"
|
||||
] = "Both API key and OpenAI config cannot be set for OpenAI models. Please set only one of them."
|
||||
] = "Both API key and AI Model API cannot be set for OpenAI models. Please set only one of them."
|
||||
error[
|
||||
"openai_config"
|
||||
"ai_model_api"
|
||||
] = "Both API key and OpenAI config cannot be set for OpenAI models. Please set only one of them."
|
||||
if self.model_type != self.ModelType.OPENAI:
|
||||
if not self.api_key:
|
||||
error["api_key"] = "The API key field must be set for non OpenAI models."
|
||||
if self.openai_config:
|
||||
error["openai_config"] = "OpenAI config cannot be set for non OpenAI models."
|
||||
if self.ai_model_api:
|
||||
error["ai_model_api"] = "AI Model API cannot be set for non OpenAI models."
|
||||
if error:
|
||||
raise ValidationError(error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user