mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 05:39:11 +00:00
Enable using Stable Diffusion 3 for Image Generation via API (#830)
- Support Stable Diffusion 3 via API Server Admin needs to setup model similar to DALLE-3 via Django Admin Panel - Use shorter prompt generator to prompt SD3 to create better images - Allow users to set paint model to use from web client config page
This commit is contained in:
@@ -235,9 +235,37 @@ class SearchModelConfig(BaseModel):
|
||||
class TextToImageModelConfig(BaseModel):
|
||||
class ModelType(models.TextChoices):
|
||||
OPENAI = "openai"
|
||||
STABILITYAI = "stability-ai"
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
# Custom validation logic
|
||||
error = {}
|
||||
if self.model_type == self.ModelType.OPENAI:
|
||||
if self.api_key and self.openai_config:
|
||||
error[
|
||||
"api_key"
|
||||
] = "Both API key and OpenAI config cannot be set for OpenAI models. Please set only one of them."
|
||||
error[
|
||||
"openai_config"
|
||||
] = "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 error:
|
||||
raise ValidationError(error)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.clean()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class SpeechToTextModelOptions(BaseModel):
|
||||
@@ -264,6 +292,11 @@ class UserSearchModelConfig(BaseModel):
|
||||
setting = models.ForeignKey(SearchModelConfig, on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class UserTextToImageModelConfig(BaseModel):
|
||||
user = models.OneToOneField(KhojUser, on_delete=models.CASCADE)
|
||||
setting = models.ForeignKey(TextToImageModelConfig, on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class Conversation(BaseModel):
|
||||
user = models.ForeignKey(KhojUser, on_delete=models.CASCADE)
|
||||
conversation_log = models.JSONField(default=dict)
|
||||
|
||||
Reference in New Issue
Block a user