Skip to content

Commit

Permalink
Changes to adapt to JSOn Type in Context (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
shincap8 authored Nov 19, 2024
1 parent 452dcc4 commit fb19829
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
8 changes: 4 additions & 4 deletions backend/app/domain/services/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_context(self, task_id: int, method: str, tags=None, need_context=False):

print(f"context id {context.id}")
return {
"current_context": json.loads(context.context_json),
"current_context": context.context_json,
"context_id": context.id,
"real_round_id": context.r_realid,
"tags": tags,
Expand Down Expand Up @@ -316,16 +316,16 @@ def save_contexts_to_s3(
def get_random_context_from_key_value(
self, key_name: str, key_value: dict, r_realid: int
) -> dict:
search_txt = f'%{key_name}":"{key_value}%'
context = self.context_repository.get_context_by_key_value_in_contextjson(
search_txt, r_realid
key_name, key_value, r_realid
)
print("context", context)
if not context:
return None
context = {
"id": context.id,
"round_id": r_realid,
**json.loads(context.context_json),
**context.context_json,
}

return context
Expand Down
3 changes: 2 additions & 1 deletion backend/app/infrastructure/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# coding: utf-8
from sqlalchemy import (
JSON,
TIMESTAMP,
BigInteger,
Column,
Expand Down Expand Up @@ -383,7 +384,7 @@ class Context(Base):

id = Column(Integer, primary_key=True)
r_realid = Column(ForeignKey("rounds.id"), nullable=False, index=True)
context_json = Column(Text)
context_json = Column(JSON)
tag = Column(Text)
metadata_json = Column(Text)
total_used = Column(Integer)
Expand Down
6 changes: 4 additions & 2 deletions backend/app/infrastructure/repositories/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ def get_context_by_real_round_id(self, real_round_id: int):
.all()
)

def get_context_by_key_value_in_contextjson(self, search_txt: str, r_realid: int):
def get_context_by_key_value_in_contextjson(
self, key_name: str, key_value: str, r_realid: int
):
instance = (
self.session.query(self.model)
.filter(
self.model.r_realid == r_realid,
self.model.context_json.like(search_txt),
self.model.context_json[key_name] == key_value,
)
.order_by(func.rand())
.first()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ const SelectMultipleTextMultipleTags: FC<
})
.catch((error) => {
console.warn("error", error);
setLoading2(false);
Swal.fire({
title: instruction?.context_alert_title,
text: instruction?.context_alert_text,
icon: "warning",
confirmButtonText: "Ok",
}).then(() => {
handleSubmit(field_names_for_the_model?.default_tag);
});
});
};

Expand Down

0 comments on commit fb19829

Please sign in to comment.