Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
izzat5233 committed Jun 27, 2023
1 parent 4c527b5 commit ac6ee55
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.izzatalsharif.openai</groupId>
<artifactId>chat-agent</artifactId>
<version>0.1.1</version>
<version>0.1.2</version>
<name>chat-agent</name>
<description>chat-agent</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,20 @@ public Mono<Response> request(I input) throws InputFormattingException, OutputPa
* @return the request template with the prompt injected
*/
private String injectRequest(String prompt) {
prompt = quoteFix(prompt);
return template.replace("{prompt}", prompt);
}

/**
* Adds prefix '\' to all double quotes to ensure proper parsing.
* This is because the prompt will be injected as a string and parsed again in OpenAI server.
* So it must be explicit '\"' in the JSON body.
*
* @param prompt the input string to be fixed
* @return the fixed input string
*/
private String quoteFix(String prompt) {
return prompt.replaceAll("\"", "\\\\\"");
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package com.izzatalsharif.openai.chatagent;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.izzatalsharif.openai.chatagent.core.HandlerFactory;
import com.izzatalsharif.openai.chatagent.exception.OutputParsingException;
import com.izzatalsharif.openai.chatagent.handler.JsonInputFormatter;
import com.izzatalsharif.openai.chatagent.handler.JsonOutputParser;
import com.izzatalsharif.openai.chatagent.handler.XmlInputFormatter;
import com.izzatalsharif.openai.chatagent.handler.XmlOutputParser;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down

0 comments on commit ac6ee55

Please sign in to comment.