-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5070 create new gollm endpoint that takes in a list of latex equation…
…s a returns cleaned up ones (#5145)
- Loading branch information
Showing
8 changed files
with
240 additions
and
20 deletions.
There are no files selected for viewing
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,24 @@ | ||
EQUATIONS_CLEANUP_PROMPT = """ | ||
You are a helpful agent designed to reformat latex equations based on a supplied style guide. | ||
The style guide will contain a list of rules that you should follow when reformatting the equations. You should reformat the equations to match the style guide as closely as possible. | ||
Do not respond in full sentences; only create a JSON object that satisfies the JSON schema specified in the response format. | ||
Use the following style guide to ensure that your LaTeX equations are correctly formatted: | ||
--- STYLE GUIDE START --- | ||
{style_guide} | ||
--- STYLE GUIDE END --- | ||
The equations that you need to reformat are as follows: | ||
--- EQUATIONS START --- | ||
{equations} | ||
--- EQUATIONS END --- | ||
Answer: | ||
""" |
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 |
---|---|---|
@@ -1,19 +1,14 @@ | ||
LATEXT_STYLE_GUIDE = """ | ||
1) Derivatives must be written in Leibniz notation (for example, \\frac{d X}{d t}). Equations that are written in other notations, like Newton or Lagrange, should be converted. | ||
1) Derivatives must be written in Leibniz notation (for example, '\\frac{d X}{d t}'). Equations that are written in other notations, like Newton or Lagrange, should be converted. | ||
2) First-order derivative must be on the left of the equal sign | ||
3) Use whitespace to indicate multiplication | ||
a) "*" is optional but probably should be avoided | ||
4) "(t)" is optional and probably should be avoided | ||
5) Avoid superscripts and LaTeX superscripts "^", particularly to denote sub-variables | ||
6) Subscripts using LaTeX "_" are permitted | ||
a) Ensure that all characters used in the subscript are surrounded by a pair of curly brackets "{...}" | ||
7) Avoid mathematical constants like pi or Euler's number | ||
a) Replace them as floats with 3 decimal places of precision | ||
8) Avoid parentheses | ||
9) Avoid capital sigma and pi notations for summation and product | ||
10) Avoid non-ASCII characters when possible | ||
11) Avoid using homoglyphs | ||
12) Avoid words or multi-character names for variables and names | ||
a) Use camel case to express multi-word or multi-character names | ||
13) Do not use \\cdot for multiplication. Use whitespace instead. | ||
3) the use of '(t)' should be avoided | ||
4) Avoid superscripts and LaTeX superscripts '^', particularly to denote sub-variables | ||
5) Subscripts using LaTeX '_' are permitted. However, Ensure that all characters used in the subscript are surrounded by a pair of curly brackets '{...}' | ||
6) Avoid parentheses | ||
7) Avoid capital sigma and pi notations for summation and product | ||
8) Avoid non-ASCII characters when possible | ||
9) Avoid using homoglyphs | ||
10) Avoid words or multi-character names for variables and names. Use camel case to express multi-word or multi-character names | ||
11) Do not use '\\cdot' or '*' to indicate multiplication. Use whitespace instead. | ||
12) Avoid using notation for mathematical constants like 'e' and 'pi'. Use their actual values up to 3 decimal places instead. | ||
""" |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
from entities import EquationsCleanup | ||
from gollm_openai.tool_utils import equations_cleanup | ||
|
||
from taskrunner import TaskRunnerInterface | ||
|
||
|
||
def cleanup(): | ||
pass | ||
|
||
|
||
def main(): | ||
exitCode = 0 | ||
try: | ||
taskrunner = TaskRunnerInterface(description="Reformat equations based on style guide") | ||
taskrunner.on_cancellation(cleanup) | ||
|
||
input_dict = taskrunner.read_input_dict_with_timeout() | ||
|
||
taskrunner.log("Creating EquationsCleanup from input") | ||
input_model = EquationsCleanup(**input_dict) | ||
|
||
taskrunner.log("Sending request to OpenAI API") | ||
response = equations_cleanup(equations=input_model.equations) | ||
taskrunner.log("Received response from OpenAI API") | ||
|
||
taskrunner.write_output_dict_with_timeout({"response": response}) | ||
|
||
except Exception as e: | ||
sys.stderr.write(f"Error: {str(e)}\n") | ||
sys.stderr.flush() | ||
exitCode = 1 | ||
|
||
taskrunner.log("Shutting down") | ||
taskrunner.shutdown() | ||
sys.exit(exitCode) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
40 changes: 40 additions & 0 deletions
40
.../software/uncharted/terarium/hmiserver/service/tasks/EquationsCleanupResponseHandler.java
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,40 @@ | ||
package software.uncharted.terarium.hmiserver.service.tasks; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class EquationsCleanupResponseHandler extends TaskResponseHandler { | ||
|
||
public static final String NAME = "gollm:equations_cleanup"; | ||
|
||
@Override | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
@Data | ||
public static class Input { | ||
|
||
List<String> equations; | ||
} | ||
|
||
@Data | ||
public static class Properties { | ||
|
||
UUID projectId; | ||
} | ||
|
||
@Data | ||
public static class Response { | ||
|
||
JsonNode response; | ||
} | ||
} |