whackthejacker commited on
Commit
86f546d
·
verified ·
1 Parent(s): 91987b2

Update tokenizer.py

Browse files
Files changed (1) hide show
  1. tokenizer.py +40 -55
tokenizer.py CHANGED
@@ -1,56 +1,41 @@
 
1
  from transformers import pipeline
2
- from huggingface_hub import hf_hub_url, cached_download, HfApi
3
-
4
- HF_TOKEN = os.environ.get("HF_TOKEN", None)
5
-
6
- def generate_code_from_model(input_text):
7
- """Generates code using the bigscience/T0_3B model."""
8
- model_name = 'bigscience/T0_3B' # Choose your model
9
- generator = pipeline('text-generation', model=model_name)
10
- model_type = {
11
- "model_type": "compositional",
12
- "task": "Develop an app that allows users to search for and modify files on a remote server using the SSH protocol",
13
- "history": "",
14
- "history_additions": [
15
- "Set the task description to 'Develop an app that allows users to search for and modify files on a remote server using the SSH protocol'",
16
- "Updated the task description to 'Connect to the remote server using the SSH protocol'",
17
- "Completed the task: Connect to the remote server using the SSH protocol",
18
- "Updated the task description to 'Search for a file on the remote server'",
19
- "Completed the task: Search for a file on the remote server",
20
- "Updated the task description to 'Modify the file found on the remote server'",
21
- "Completed the task: Modify the file found on the remote server",
22
- "Updated the task description to 'Verify the file modifications using the updated file'",
23
- "Completed the task: Verify the file modifications using the updated file",
24
- "Updated the task description to 'Create a summary of the timeline of progress and any important challenges faced during the development of the app'",
25
- "Completed the task: Create a summary of the timeline of progress and any important challenges faced during the development of the app",
26
- "Updated the task description to 'Deploy the app to the production server'",
27
- "Completed the task: Deploy the app to the production server",
28
- "Updated the task description to 'Monitor the performance of the deployed app and make adjustments as necessary'",
29
- "Completed the task: Monitor the performance of the deployed app and make adjustments as necessary",
30
- "Updated the task description to 'Maintain and update the app in response to user feedback and any discovered bugs'"
31
- ],
32
- "history_removals": [],
33
- "model_log": [
34
- "Model prompt: You are attempting to complete the task task: Develop an app that allows users to search for and modify files on a remote server using the SSH protocol Progress: Connect to the remote server using the SSH protocol",
35
- "Model response: Connect to the remote server using the SSH protocol",
36
- "Model prompt: Updated the task description to 'Search for a file on the remote server'",
37
- "Model response: Search for a file on the remote server",
38
- "Model prompt: Completed the task: Search for a file on the remote server Progress: Connect to the remote server using the SSH protocol\nSearch for a file on the remote server",
39
- "Model response: You have successfully completed the task: Search for a file on the remote server",
40
- "Model prompt: Updated the task description to 'Modify the file found on the remote server'",
41
- "Model response: Modify the file found on the remote server",
42
- "Model prompt: Completed the task: Modify the file found on the remote server Progress: Connect to the remote server using the SSH protocol\nSearch for a file on the remote server\nModify the file found on the remote server",
43
- "Model response: You have successfully completed the task: Modify the file found on the remote server",
44
- "Model prompt: Updated the task description to 'Verify the file modifications using the updated file'",
45
- "Model response: Verify the file modifications using the updated file",
46
- "Model prompt: Completed the task: Verify the file modifications using the updated file Progress: Connect to the remote server using the SSH protocol\nSearch for a file on the remote server\nModify the file found on the remote server\nVerify the file modifications using the updated file",
47
- "Model response: You have successfully completed the task: Verify the file modifications using the updated file",
48
- "Model prompt: Updated the task description to 'Create a summary of the timeline of progress and any important challenges faced during the development of the app'",
49
- "Model response: Create a summary of the timeline of progress and any important challenges faced during the development of the app",
50
- "Model prompt: Completed the task: Create a summary of the timeline of progress and any important challenges faced.",
51
- "Model response: All tasks complete. What shall I do next?"
52
- ]
53
- }
54
-
55
- code = generator(input_text, max_length=50, num_return_sequences=1, do_sample=True)[0]['generated_text']
56
- return code
 
1
+ import os
2
  from transformers import pipeline
3
+
4
+ HF_TOKEN = os.environ.get("HF_TOKEN")
5
+
6
+ class CodeGenerator:
7
+ def __init__(self, model_name='bigscience/T0_3B'):
8
+ self.generator = pipeline('text-generation', model=model_name)
9
+
10
+ def generate_code(self, task_description):
11
+ """
12
+ Generates code based on the provided task description using the specified language model.
13
+
14
+ Parameters:
15
+ task_description (str): The task description or prompt for generating the code.
16
+
17
+ Returns:
18
+ str: The generated code.
19
+ """
20
+ return self._generate_code_from_model(task_description)
21
+
22
+ def _generate_code_from_model(self, input_text):
23
+ """
24
+ Internal method to generate code from the model.
25
+
26
+ Parameters:
27
+ input_text (str): The input text for code generation.
28
+
29
+ Returns:
30
+ str: The code generated by the language model.
31
+ """
32
+ return self.generator(input_text, max_length=50, num_return_sequences=1, do_sample=True)[0]['generated_text']
33
+
34
+ def main():
35
+ task_description = "Develop an app that allows users to search for and modify files on a remote server using the SSH protocol"
36
+ code_generator = CodeGenerator()
37
+ generated_code = code_generator.generate_code(task_description)
38
+ print(generated_code)
39
+
40
+ if __name__ == "__main__":
41
+ main()