Skip to content

Commit 9502b60

Browse files
committed
fix: prompt syntax
1 parent de98db2 commit 9502b60

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ services:
1717
POSTGRES_USER: postgres
1818
POSTGRES_PASSWORD: postgres
1919
ports:
20-
- "5432:5432"
20+
- "5432"

src/etlp_mapper/handler/mappings.clj

+44-9
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444

4545

4646
(defn call-openai-api [prompt]
47-
(http/post "https://api.openai.com/v1/completions"
47+
(http/post "https://api.openai.com/v1/chat/completions"
4848
{: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}))
5251

5352
(defn create-prompt [input-sample output-sample]
5453
(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,6 +144,44 @@
145144
"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"
146145
"---\n"))
147146

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+
148185
(defn extract-jute-template [response]
149186
(let [text (:text (first (:choices response)))]
150187
(s/trim text)))
@@ -154,12 +191,10 @@
154191
parsed-data (yaml/parse-string yaml-content :keywords true)
155192
template (-> parsed-data :result)
156193
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))
158195
result (call-openai-api prompt)]
159196
{:result result}))
160197

161-
162-
163198
(defn suggest-component [request]
164199
(let [yaml-content (slurp (:body request))
165200
parsed-data (yaml/parse-string yaml-content :keywords true)
@@ -174,8 +209,8 @@
174209
(fn [opts]
175210
(try
176211
(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])
179214
(catch Exception e
180215
(println e)
181216
[::response/bad-request {:error (.getMessage e)}]))))

0 commit comments

Comments
 (0)