Visitar URL original
feat: 2 few-shot examples · bigcode-project/selfcodealign@13e5535 · GitHub
Skip to content

Commit 13e5535

Browse files
feat: 2 few-shot examples
1 parent d74d519 commit 13e5535

1 file changed

Lines changed: 183 additions & 0 deletions

File tree

‎prompts/self-ossinstruct-fewshot.txt‎

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,189 @@ except ValueError:
820820
assert parse_duration('1000000s') == 1000000, "Very large number of seconds"
821821
```
822822

823+
### Example 15
824+
[Code]
825+
class Restaurant():
826+
827+
def __init__(self, name, cuisine_type):
828+
self.name = name.title()
829+
self.cuisine_type = cuisine_type
830+
self.number_served = 0
831+
832+
def describe_restaurant(self):
833+
msg = f"{self.name} tiene los mejores {self.cuisine_type}."
834+
print(f"\n{msg}")
835+
836+
def open_restaurant(self):
837+
msg = f"{self.name} Está Abierta. ¡Adelante! \n"
838+
print(f"\n{msg}")
839+
840+
def set_number_served(self, number_served):
841+
self.number_served = number_served #Aquí establecemos la cantidad de clientes atendidos
842+
843+
def increment_number_served(self, additional_served):
844+
self.number_served += additional_served #Aquí incrementamos la cantidad de clientes atendidos
845+
846+
[Property]
847+
category: code generation (class implementation)
848+
language: Python
849+
concepts: class initialization, instance methods, encapsulation, data validation
850+
851+
[Instruction]
852+
Create a Python class `Restaurant` with the following properties:
853+
- `name`: a string representing the name of the restaurant
854+
- `cuisine_type`: a string representing the type of cuisine served at the restaurant
855+
- `number_served`: an integer representing the number of customers served at the restaurant (default to 0)
856+
857+
The class should have the following methods:
858+
- `describe_restaurant`: prints a message describing the restaurant's name and cuisine type
859+
- `open_restaurant`: prints a message indicating that the restaurant is open
860+
- `set_number_served`: sets the number of customers served to a given value
861+
- `increment_number_served`: increments the number of customers served by a given value
862+
863+
Ensure that the `name` and `cuisine_type` properties are properly encapsulated and that the `number_served` property is validated to only accept positive integers.
864+
865+
[Response]
866+
[Reasoning]
867+
To create a Python class `Restaurant` with the specified properties and methods, we can follow these steps:
868+
869+
1. Define the class `Restaurant` with the `__init__` method to initialize the properties `name`, `cuisine_type`, and `number_served` with the given values. The `name` and `cuisine_type` properties can be encapsulated by using the `@property` decorator and defining getters and setters for these properties.
870+
2. Define the `describe_restaurant` and `open_restaurant` methods to print the appropriate messages.
871+
3. Define the `set_number_served` and `increment_number_served` methods to set and increment the `number_served` property, respectively. Ensure that the `number_served` property is validated to only accept positive integers.
872+
873+
[Implementation]
874+
Here's how you can implement this class:
875+
876+
```python
877+
class Restaurant:
878+
def __init__(self, name, cuisine_type):
879+
self._name = name.title()
880+
self._cuisine_type = cuisine_type
881+
self._number_served = 0
882+
883+
@property
884+
def name(self):
885+
return self._name
886+
887+
@property
888+
def cuisine_type(self):
889+
return self._cuisine_type
890+
891+
@property
892+
def number_served(self):
893+
return self._number_served
894+
895+
@number_served.setter
896+
def number_served(self, value):
897+
if not isinstance(value, int) or value < 0:
898+
raise ValueError("number_served must be a positive integer")
899+
self._number_served = value
900+
901+
def describe_restaurant(self):
902+
msg = f"{self.name} tiene los mejores {self.cuisine_type}."
903+
print(f"\n{msg}")
904+
905+
def open_restaurant(self):
906+
msg = f"{self.name} Está Abierta. ¡Adelante! \n"
907+
print(f"\n{msg}")
908+
909+
def set_number_served(self, number_served):
910+
self.number_served = number_served
911+
912+
def increment_number_served(self, additional_served):
913+
self.number_served += additional_served
914+
```
915+
916+
[Explanation]
917+
This class `Restaurant` encapsulates the `name` and `cuisine_type` properties using the `@property` decorator and defines getters and setters for these properties. The `number_served` property is also encapsulated and validated to only accept positive integers. The methods `describe_restaurant` and `open_restaurant` print the appropriate messages, while `set_number_served` and `increment_number_served` set and increment the `number_served` property, respectively.
918+
919+
[Tests]
920+
To verify the correctness of this class, we can run the following tests:
921+
922+
```python
923+
restaurant = Restaurant("La Taquería", "comida mexicana")
924+
assert restaurant.name == "La Taquería"
925+
assert restaurant.cuisine_type == "comida mexicana"
926+
assert restaurant.number_served == 0
927+
928+
restaurant.set_number_served(10)
929+
assert restaurant.number_served == 10
930+
931+
restaurant.increment_number_served(5)
932+
assert restaurant.number_served == 15
933+
934+
try:
935+
restaurant.number_served = -1
936+
except ValueError:
937+
pass
938+
else:
939+
raise AssertionError("number_served should not accept negative values")
940+
```
941+
942+
### Example 16
943+
[Code]
944+
def fib(limit):
945+
nums = []
946+
current, nxt = 0, 1
947+
while len(nums) < limit:
948+
current, nxt = nxt, current + nxt
949+
nums.append(current)
950+
951+
return nums
952+
953+
[Property]
954+
category: code generation (function implementation)
955+
language: Python
956+
concepts: Fibonacci sequence, list manipulation, efficient memory usage
957+
958+
[Instruction]
959+
Write a Python function that returns a list of the first `limit` numbers in the Fibonacci sequence. The function should use efficient memory usage by only storing the last two numbers in the sequence and updating them in each iteration. The function should also validate the input `limit` to ensure it is a positive integer.
960+
961+
[Response]
962+
[Reasoning]
963+
To generate the first `limit` numbers in the Fibonacci sequence, we can use a loop that iteratively calculates the next number in the sequence by adding the last two numbers. To efficiently use memory, we only need to store the last two numbers in the sequence and update them in each iteration. This approach avoids storing the entire sequence in memory, which can be costly for large values of `limit`.
964+
965+
To validate the input `limit`, we can check if it is a positive integer using `isinstance` and `>= 0`.
966+
967+
[Implementation]
968+
Here's how you can implement this function:
969+
970+
```python
971+
def fibonacci_sequence(limit: int) -> list:
972+
# Validate the input limit
973+
if not isinstance(limit, int) or limit < 0:
974+
raise ValueError("limit must be a positive integer")
975+
976+
# Base case for limit = 0 and 1
977+
if limit == 0:
978+
return []
979+
elif limit == 1:
980+
return [0]
981+
982+
# Initialize the list with the first two numbers in the sequence
983+
nums = [0, 1]
984+
985+
# Keep generating numbers until the list reaches the limit
986+
while len(nums) < limit:
987+
# Calculate the next number in the sequence and append it to the list
988+
nums.append(nums[-1] + nums[-2])
989+
990+
return nums
991+
```
992+
993+
[Explanation]
994+
This function generates the first `limit` numbers in the Fibonacci sequence by iteratively calculating the next number and appending it to the list. The function also validates the input `limit` to ensure it is a positive integer.
995+
996+
[Tests]
997+
You can test this function with a few test cases to ensure correctness:
998+
999+
```python
1000+
assert fibonacci_sequence(0) == []
1001+
assert fibonacci_sequence(1) == [0]
1002+
assert fibonacci_sequence(2) == [0, 1]
1003+
assert fibonacci_sequence(10) == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
1004+
```
1005+
8231006
### Example 17
8241007
[Code]
8251008
def get_param_groups(network):

0 commit comments

Comments
 (0)