|
21 | 21 | :command ["{{database}}" "{{query}}"]}}]})
|
22 | 22 |
|
23 | 23 | (def first-tool-call
|
24 |
| - {:messages [{:content "" |
25 |
| - :tool_calls [{:function {:name "sql_db_list_tables_tool" |
| 24 | + {:messages [{:role "assistant" |
| 25 | + :content "" |
| 26 | + :tool_calls [{:type "function" |
| 27 | + :function {:name "sql_db_list_tables_tool" |
26 | 28 | :arguments "{\"database\": \"./Chinook.db\"}"}
|
27 | 29 | :id "tool_abc123"}]}]
|
28 | 30 | :tools [{:type "function"
|
|
37 | 39 | :command ["{{database}}" ".tables"]}}}]})
|
38 | 40 |
|
39 | 41 | (def model-get-schema
|
40 |
| - {:messages [] |
41 |
| - :tools [{:name "sql_db_get_schema_tool" |
42 |
| - :description "List all tables in the database" |
43 |
| - :parameters |
44 |
| - {:type "object" |
45 |
| - :properties |
46 |
| - {:database {:type "string" :description "the database to query"} |
47 |
| - :table {:type "string" :description "the table to get the schema for"}}} |
48 |
| - :container |
49 |
| - {:image "vonwig/sqlite:latest" |
50 |
| - :command ["{{database}}" ".schema {{table}}"]}}]}) |
| 42 | + {:tools [{:type "function" |
| 43 | + :function {:name "sql_db_get_schema_tool" |
| 44 | + :description "List all tables in the database" |
| 45 | + :parameters |
| 46 | + {:type "object" |
| 47 | + :properties |
| 48 | + {:database {:type "string" :description "the database to query"} |
| 49 | + :table {:type "string" :description "the table to get the schema for"}}} |
| 50 | + :container |
| 51 | + {:image "vonwig/sqlite:latest" |
| 52 | + :command ["{{database}}" ".schema {{table}}"]}}}]}) |
51 | 53 |
|
52 | 54 | (defn list-tables-inject-tool [_]
|
53 | 55 | (async/go
|
|
79 | 81 | (string/starts-with? last-message "Error:") "query-gen"
|
80 | 82 | :else "correct-query")))
|
81 | 83 |
|
| 84 | +(defn seed-get-schema-conversation [state] |
| 85 | + ; inherit full conversation |
| 86 | + ; no prompts |
| 87 | + ; add the schema tool |
| 88 | + (-> state |
| 89 | + (update-in [:opts :level] (fnil inc 0)) |
| 90 | + (update-in [:opts :parameters] (constantly {:database "./Chinook.db"})) |
| 91 | + (update-in [:functions] (fnil concat []) (:tools model-get-schema)))) |
| 92 | + |
82 | 93 | (defn graph [_]
|
83 | 94 | (-> {}
|
84 | 95 | (graph/add-node "start" graph/start)
|
|
88 | 99 | (graph/add-node "list-tables-tool" (graph/tool-node nil))
|
89 | 100 | (graph/add-edge "list-tables-inject-tool" "list-tables-tool")
|
90 | 101 |
|
91 |
| - (graph/add-node "end" graph/end) |
92 |
| - (graph/add-edge "list-tables-tool" "end") |
| 102 | + (graph/add-node "model-get-schema" (graph/sub-graph-node {:init-state seed-get-schema-conversation})) ; assistant |
| 103 | + (graph/add-edge "list-tables-tool" "model-get-schema") |
93 | 104 |
|
94 |
| - ;(graph/add-node "model-get-schema" (graph/sub-graph-node model-get-schema)) ; assistant |
| 105 | + (graph/add-node "end" graph/end) |
| 106 | + (graph/add-edge "model-get-schema" "end") |
95 | 107 | ;(graph/add-node "query-gen" query-gen) ; assistant - might just end if it generates the right response
|
96 | 108 | ;; - might just loop back to query-gen if there's an error
|
97 | 109 | ;; - otherwise switch to correct-query
|
|
0 commit comments