@@ -17,7 +17,15 @@ class LLM:
17
17
18
18
@property
19
19
def type (self ) -> str :
20
- """Return type of llm."""
20
+ """
21
+ Return type of LLM.
22
+
23
+ Raises:
24
+ APIKeyNotFoundError: Type has not been implemented
25
+
26
+ Returns:
27
+ str: Type of LLM a string
28
+ """
21
29
raise APIKeyNotFoundError ("Type has not been implemented" )
22
30
23
31
def _remove_imports (self , code : str ) -> str :
@@ -32,12 +40,16 @@ def _remove_imports(self, code: str) -> str:
32
40
return astor .to_source (new_tree )
33
41
34
42
def _polish_code (self , code : str ) -> str :
35
- """Polish the code:
36
- - remove the leading "python" or "py"
37
- - remove the imports
38
- - remove trailing spaces and new lines
39
43
"""
44
+ Polish the code by removing the leading "python" or "py", \
45
+ removing the imports and removing trailing spaces and new lines.
40
46
47
+ Args:
48
+ code (str): Code
49
+
50
+ Returns:
51
+ str: Polished code
52
+ """
41
53
if re .match (r"^(python|py)" , code ):
42
54
code = re .sub (r"^(python|py)" , "" , code )
43
55
if re .match (r"^`.*`$" , code ):
@@ -54,8 +66,19 @@ def _is_python_code(self, string):
54
66
return False
55
67
56
68
def _extract_code (self , response : str , separator : str = "```" ) -> str :
57
- """Extract the code from the response"""
69
+ """
70
+ Extract the code from the response.
71
+
72
+ Args:
73
+ response (str): Response
74
+ separator (str, optional): Separator. Defaults to "```".
58
75
76
+ Raises:
77
+ NoCodeFoundError: No code found in the response
78
+
79
+ Returns:
80
+ str: Extracted code from the response
81
+ """
59
82
code = response
60
83
if len (response .split (separator )) > 1 :
61
84
code = response .split (separator )[1 ]
@@ -67,12 +90,24 @@ def _extract_code(self, response: str, separator: str = "```") -> str:
67
90
68
91
return code
69
92
70
- def call (self , instruction : str , value : str ) -> str :
71
- """Execute the llm with the given prompt"""
93
+ def call (self , instruction : str , value : str ) -> None :
94
+ """
95
+ Execute the LLM with given prompt.
96
+
97
+ Args:
98
+ instruction (str): Prompt
99
+ value (str): Value
72
100
101
+ Raises:
102
+ MethodNotImplementedError: Call method has not been implemented
103
+ """
73
104
raise MethodNotImplementedError ("Call method has not been implemented" )
74
105
75
106
def generate_code (self , instruction : str , prompt : str ) -> str :
76
- """Generate the code based on the instruction and the prompt"""
107
+ """
108
+ Generate the code based on the instruction and the given prompt.
77
109
110
+ Returns:
111
+ str: Code
112
+ """
78
113
return self ._extract_code (self .call (instruction , prompt ))
0 commit comments