|
44 | 44 |
|
45 | 45 |
|
46 | 46 | (defn call-openai-api [prompt]
|
47 |
| - (http/post "https://api.openai.com/v1/completions" |
| 47 | + (http/post "https://api.openai.com/v1/chat/completions" |
48 | 48 | {:headers {"Content-Type" "application/json"
|
49 |
| - "Authorization" "Bearer :/"} |
50 |
| - :body (json/encode {:prompt prompt :model "text-davinci-003" :max_tokens 2000 :n 1 :stop "---"})})) |
51 |
| - |
| 49 | + "Authorization" "Bearer foo"} |
| 50 | + :body prompt})) |
52 | 51 |
|
53 | 52 | (defn create-prompt [input-sample output-sample]
|
54 | 53 | (str "I want you to generate a Jute.clj template that maps the given input YAML data to the specified output YAML data. The task is to create a Jute.clj template using a YAML-based DSL similar to the example provided below. The example demonstrates a FizzBuzz implementation in Jute.clj YAML syntax:\n\n"
|
|
145 | 144 | "Please create a code template that uses the appropriate props to fulfill the user's requirements. Ensure that the generated code is valid React code, adheres to the @innovaccer/design-system library conventions, and is efficient and easy to read.\n\n"
|
146 | 145 | "---\n"))
|
147 | 146 |
|
| 147 | + |
| 148 | + |
| 149 | +(defn generate-gpt-prompt [inputExample outputExample] |
| 150 | + (str ";; GPT Prompt for Generating JUTE Mapping\n" |
| 151 | + ";; ---------------------------------------\n" |
| 152 | + ";; Input: FHIR Resource (YAML)\n" |
| 153 | + ";; Output: Custom YAML Schema\n" |
| 154 | + ";; Requirement: Generate a JUTE template for the transformation\n\n" |
| 155 | + ";; FHIR Resource Example:\n" |
| 156 | + inputExample "\n\n" |
| 157 | + ";; Desired Output Schema:\n" |
| 158 | + outputExample "\n\n" |
| 159 | + ";; Instructions for GPT:\n" |
| 160 | + ";; Use only the supported JUTE functions like joinStr, concat, merge, etc.\n" |
| 161 | + ";; Ensure the JUTE template is in valid syntax and correctly maps the input to the desired output.\n" |
| 162 | + ";; Provide the JUTE template in Clojure syntax.\n\n" |
| 163 | + ";; GPT, please generate the JUTE template:\n")) |
| 164 | + |
| 165 | + |
| 166 | +(defn generate-gpt-json-payload [inputExample outputExample] |
| 167 | + (let [prompt (str ";; GPT Prompt for Generating JUTE Mapping\n" |
| 168 | + ";; ---------------------------------------\n" |
| 169 | + ";; Input: FHIR Resource YAML\n" |
| 170 | + ";; Output: Custom YAML Schema\n" |
| 171 | + ";; Requirement: Generate a JUTE template for the transformation\n\n" |
| 172 | + ";; FHIR Resource Example:\n" |
| 173 | + inputExample "\n\n" |
| 174 | + ";; Desired Output Schema:\n" |
| 175 | + outputExample "\n\n" |
| 176 | + ";; Instructions for GPT:\n" |
| 177 | + ";; Use only the supported JUTE functions like joinStr, concat, merge, etc.\n" |
| 178 | + ";; Ensure the JUTE template is in valid syntax and correctly maps the input to the desired output.\n" |
| 179 | + ";; GPT, please generate the JUTE template:\n")] |
| 180 | + (json/encode |
| 181 | + {:model "gpt-4-turbo" |
| 182 | + :messages [{:role "system" :content "You are a helpful data mapping assistant."} |
| 183 | + {:role "user" :content prompt}]}))) |
| 184 | + |
148 | 185 | (defn extract-jute-template [response]
|
149 | 186 | (let [text (:text (first (:choices response)))]
|
150 | 187 | (s/trim text)))
|
|
154 | 191 | parsed-data (yaml/parse-string yaml-content :keywords true)
|
155 | 192 | template (-> parsed-data :result)
|
156 | 193 | scope (-> parsed-data :scope)
|
157 |
| - prompt (create-prompt-with-reduce (yaml/generate-string scope) (yaml/generate-string template)) |
| 194 | + prompt (generate-gpt-json-payload (yaml/generate-string scope) (yaml/generate-string template)) |
158 | 195 | result (call-openai-api prompt)]
|
159 | 196 | {:result result}))
|
160 | 197 |
|
161 |
| - |
162 |
| - |
163 | 198 | (defn suggest-component [request]
|
164 | 199 | (let [yaml-content (slurp (:body request))
|
165 | 200 | parsed-data (yaml/parse-string yaml-content :keywords true)
|
|
174 | 209 | (fn [opts]
|
175 | 210 | (try
|
176 | 211 | (let [translated (suggest-mapping opts) resp (json/decode (get-in translated [:result :body]) true)]
|
177 |
| - (pprint translated) |
178 |
| - [::response/ok (extract-jute-template resp)]) |
| 212 | + (pprint resp) |
| 213 | + [::response/ok resp]) |
179 | 214 | (catch Exception e
|
180 | 215 | (println e)
|
181 | 216 | [::response/bad-request {:error (.getMessage e)}]))))
|
|
0 commit comments