Skip to content

Commit

Permalink
Merge branch 'checkpoint_parser' into lezhan
Browse files Browse the repository at this point in the history
  • Loading branch information
TanLeZhan committed Jul 26, 2024
2 parents 73d0425 + ad25b71 commit a2db759
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions-hub/gcloud@master
env:
PROJECT_ID: tscthing
PROJECT_ID: rails-server-sprint1
APPLICATION_CREDENTIALS: ${{secrets.GCP_SA_KEY}}
with:
args: builds submit --config python-server/cloudbuild.yaml python-server
4 changes: 4 additions & 0 deletions python-server/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv
__pycache__
app/.env
app/seed_user_db.py
40 changes: 40 additions & 0 deletions python-server/checkpoint_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
def print_checkpoint(obj):
for msg in obj["channel_values"]["messages"]:
max_chars = 60
msg_kwargs = msg["kwargs"]
tool_ls = msg_kwargs.get("tool_calls")
typ = msg_kwargs["type"]

if typ == "human":
print("")

line = typ + "\t"
match typ:
case "ai": colour = 32
case "tool": colour = 90
case "human": colour = 96
case _: raise "skfjdghsdfkjlghsdf"

if tool_ls:
tools = ', '.join([t["name"] for t in msg_kwargs.get("tool_calls")])
line += f"Calling tool(s): {tools}"
else:
text = str(msg_kwargs["content"]).replace('\n', ' ')
if len(text) > max_chars:
text = f"{text[:max_chars]}... [{len(text) - max_chars}]"
line += text

print(f"\033[{colour}m{line}\033[0m")

if __name__ == "__main__":
from app.models import Checkpoint_ORM
from app.database import user_engine
from sqlalchemy.orm import Session
from sqlalchemy import select
import json

with Session(user_engine) as s:
stmt = select(Checkpoint_ORM.cp_data).where(Checkpoint_ORM.chat_id == 10)
obj = json.loads(s.scalar(stmt))

print_checkpoint(obj)
3 changes: 2 additions & 1 deletion python-server/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ steps:
name: 'gcr.io/kaniko-project/executor'
args: [
'--destination=gcr.io/${PROJECT_ID}/${_SERVICE_NAME}',
'--cache=true'
'--cache=true',
'--cache-ttl=48h'
]
- id: "run deploy"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
Expand Down
2 changes: 1 addition & 1 deletion python-server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ google-resumable-media==2.7.1
googleapis-common-protos==1.63.2
greenlet==3.0.3
grpc-google-iam-v1==0.13.1
grpcio==1.65.1
grpcio==1.64.0
grpcio-status==1.62.2
h11==0.14.0
httpcore==1.0.5
Expand Down

0 comments on commit a2db759

Please sign in to comment.