-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from profiq/azure-support
Azure support
- Loading branch information
Showing
11 changed files
with
276 additions
and
116 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.profiq.codexor; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Takes in a response from OpenAI API and formats it into a proper Python docstring. | ||
*/ | ||
public class DocstringFormatter { | ||
|
||
private final String openaiResponse; | ||
private String[] docstringLines = null; | ||
|
||
public DocstringFormatter(String openaiResponse) { | ||
this.openaiResponse = openaiResponse; | ||
} | ||
|
||
public String docstringWithIndentation(String indentation) { | ||
String[] docstringLines = getDocstringLines(); | ||
|
||
StringBuilder docstring = new StringBuilder(); | ||
for (String line : docstringLines) { | ||
docstring.append(indentation).append(line).append("\n"); | ||
} | ||
|
||
return docstring.toString(); | ||
} | ||
|
||
private String[] getDocstringLines() { | ||
if (docstringLines == null) { | ||
Pattern docstringRegex = Pattern.compile("(([ \t]*)\"\"\".*\"\"\")", Pattern.DOTALL); | ||
Matcher docstringMatcher = docstringRegex.matcher(openaiResponse); | ||
|
||
if (!docstringMatcher.find()) { | ||
throw new IllegalArgumentException("No docstring found in the OpenAI response."); | ||
} | ||
|
||
String docstring = docstringMatcher.group(1); | ||
String indentation = docstringMatcher.group(2); | ||
String[] docstringLinesRaw = docstring.split("\n"); | ||
|
||
docstringLines = new String[docstringLinesRaw.length]; | ||
int substringIdx = 0; | ||
|
||
for (int i = 0; i < docstringLinesRaw.length; i++) { | ||
substringIdx = Math.min(docstringLinesRaw[i].length(), indentation.length()); | ||
docstringLines[i] = docstringLinesRaw[i].substring(substringIdx); | ||
} | ||
} | ||
|
||
return docstringLines; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,4 @@ public class Response { | |
Choice[] getChoices() { | ||
return choices; | ||
} | ||
|
||
} |
Oops, something went wrong.