Duibonduil commited on
Commit
1d53d27
·
verified ·
1 Parent(s): a1e47c1

Upload ca81bd47c050_add_config_table.py

Browse files
examples/ca81bd47c050_add_config_table.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Add config table
2
+
3
+ Revision ID: ca81bd47c050
4
+ Revises: 7e5b5dc7342b
5
+ Create Date: 2024-08-25 15:26:35.241684
6
+
7
+ """
8
+
9
+ from typing import Sequence, Union
10
+
11
+ import sqlalchemy as sa
12
+ from alembic import op
13
+ from sqlalchemy import text
14
+
15
+ # revision identifiers, used by Alembic.
16
+ revision: str = "ca81bd47c050"
17
+ down_revision: Union[str, None] = "7e5b5dc7342b"
18
+ branch_labels: Union[str, Sequence[str], None] = None
19
+ depends_on: Union[str, Sequence[str], None] = None
20
+
21
+
22
+ def upgrade():
23
+ op.create_table(
24
+ "config",
25
+ sa.Column("id", sa.Integer, primary_key=True),
26
+ sa.Column("data", sa.JSON(), nullable=False),
27
+ sa.Column("version", sa.Integer, nullable=False),
28
+ sa.Column(
29
+ "created_at", sa.DateTime(), nullable=False, server_default=sa.func.now()
30
+ ),
31
+ sa.Column(
32
+ "updated_at",
33
+ sa.DateTime(),
34
+ nullable=True,
35
+ server_default=sa.func.now(),
36
+ onupdate=sa.func.now(),
37
+ ),
38
+ )
39
+ init_gaia_config()
40
+
41
+ def downgrade():
42
+ op.drop_table("config")
43
+
44
+
45
+ def init_gaia_config():
46
+ import json
47
+ prompt_suggestions = None
48
+ with open(
49
+ "/app/aworld/examples/gaia/GAIA/2023/validation/metadata.jsonl",
50
+ "r",
51
+ encoding="utf-8",
52
+ ) as f:
53
+ data_set = [json.loads(line) for line in f]
54
+
55
+ prompt_suggestions = [
56
+ {
57
+ "title": [
58
+ i["task_id"],
59
+ i["Question"][:100],
60
+ ],
61
+ "content": json.dumps({"task_id": i["task_id"]}),
62
+ }
63
+ for i in data_set
64
+ ]
65
+
66
+ conn = op.get_bind()
67
+ conn.execute(
68
+ text("INSERT INTO config (id, data, version) VALUES (1, :data, 0)"),
69
+ {"data": json.dumps({"ui": {"prompt_suggestions": prompt_suggestions}})},
70
+ )
71
+ print(f">>> patch gaia_agent: add prompt_suggestions success!")
72
+