Feat: add Langfuse APIs (#6460)

### What problem does this PR solve?

Add Langfuse APIs

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
Yongteng Lei
2025-03-24 18:25:43 +08:00
committed by GitHub
parent 66e557b6c0
commit 5e0a77df2b
3 changed files with 44 additions and 5 deletions

View File

@ -524,9 +524,7 @@ class TenantLangfuse(DataBaseModel):
tenant_id = CharField(max_length=32, null=False, primary_key=True)
secret_key = CharField(max_length=2048, null=False, help_text="SECRET KEY", index=True)
public_key = CharField(max_length=2048, null=False, help_text="PUBLIC KEY", index=True)
host = CharField(max_length=128, null=False, help_text="host", index=True)
# max_tokens = IntegerField(default=8192, index=True)
# used_tokens = IntegerField(default=0, index=True)
host = CharField(max_length=128, null=False, help_text="HOST", index=True)
def __str__(self):
return "Langfuse host" + self.host

View File

@ -34,13 +34,23 @@ class TenantLangfuseService(CommonService):
@classmethod
@DB.connection_context()
def filter_by_tenant(cls, tenant_id):
fields = [cls.model.host, cls.model.secret_key, cls.model.public_key]
fields = [cls.model.tenant_id, cls.model.host, cls.model.secret_key, cls.model.public_key]
try:
keys = cls.model.select(*fields).where(cls.model.tenant_id == tenant_id).first()
return keys
except peewee.DoesNotExist:
return None
@classmethod
@DB.connection_context()
def filter_by_tenant_with_info(cls, tenant_id):
fields = [cls.model.tenant_id, cls.model.host, cls.model.secret_key, cls.model.public_key]
try:
keys = cls.model.select(*fields).where(cls.model.tenant_id == tenant_id).dicts().first()
return keys
except peewee.DoesNotExist:
return None
@classmethod
def update_by_tenant(cls, tenant_id, langfuse_keys):
langfuse_keys["update_time"] = current_timestamp()
@ -55,3 +65,7 @@ class TenantLangfuseService(CommonService):
kwargs["update_date"] = datetime_format(datetime.now())
obj = cls.model.create(**kwargs)
return obj
@classmethod
def delete_model(cls, langfuse_model):
langfuse_model.delete_instance()