Update CodeGeneratorAtomicFlow.py
Browse files- CodeGeneratorAtomicFlow.py +13 -10
CodeGeneratorAtomicFlow.py
CHANGED
|
@@ -9,6 +9,14 @@ from dataclasses import dataclass
|
|
| 9 |
class CodeGeneratorAtomicFlow(OpenAIChatAtomicFlow):
|
| 10 |
def __init__(self, **kwargs):
|
| 11 |
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
@classmethod
|
| 14 |
def instantiate_from_config(cls, config):
|
|
@@ -22,18 +30,13 @@ class CodeGeneratorAtomicFlow(OpenAIChatAtomicFlow):
|
|
| 22 |
|
| 23 |
# ~~~ Instantiate flow ~~~
|
| 24 |
return cls(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 27 |
-
|
| 28 |
-
Make sure your response is in the following format:
|
| 29 |
-
Response Format:
|
| 30 |
-
{
|
| 31 |
-
"language_of_code": "language of the code",
|
| 32 |
-
"code": "String of the code corresponding to the goal",
|
| 33 |
-
}
|
| 34 |
-
"""
|
| 35 |
-
if 'goal' in input_data:
|
| 36 |
-
input_data['goal'] += hint_for_model
|
| 37 |
api_output = super().run(input_data)["api_output"].strip()
|
| 38 |
try:
|
| 39 |
response = json.loads(api_output)
|
|
|
|
| 9 |
class CodeGeneratorAtomicFlow(OpenAIChatAtomicFlow):
|
| 10 |
def __init__(self, **kwargs):
|
| 11 |
super().__init__(**kwargs)
|
| 12 |
+
self.hint_for_model = """
|
| 13 |
+
Make sure your response is in the following format:
|
| 14 |
+
Response Format:
|
| 15 |
+
{
|
| 16 |
+
"language_of_code": "language of the code",
|
| 17 |
+
"code": "String of the code corresponding to the goal",
|
| 18 |
+
}
|
| 19 |
+
"""
|
| 20 |
|
| 21 |
@classmethod
|
| 22 |
def instantiate_from_config(cls, config):
|
|
|
|
| 30 |
|
| 31 |
# ~~~ Instantiate flow ~~~
|
| 32 |
return cls(**kwargs)
|
| 33 |
+
|
| 34 |
+
def _update_input(self, input_data: Dict[str, Any]):
|
| 35 |
+
if 'goal' in input_data:
|
| 36 |
+
input_data['goal'] += self.hint_for_model
|
| 37 |
|
| 38 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 39 |
+
self._update_input(input_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
api_output = super().run(input_data)["api_output"].strip()
|
| 41 |
try:
|
| 42 |
response = json.loads(api_output)
|