-
Notifications
You must be signed in to change notification settings - Fork 895
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a flow to check repo's grammar and spelling
- Loading branch information
Anthony Hu
committed
Sep 10, 2023
1 parent
2077f58
commit c6365ca
Showing
5 changed files
with
109 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
id: template_standard_flow | ||
name: Template Standard Flow | ||
inputs: | ||
path: | ||
type: string | ||
outputs: | ||
output_python: | ||
type: string | ||
reference: ${input_passthrough.output} | ||
output_check: | ||
type: string | ||
reference: ${grammer_check.output} | ||
nodes: | ||
- name: read_file | ||
type: python | ||
source: | ||
type: code | ||
path: read_file.py | ||
inputs: | ||
path: ${inputs.path} | ||
- name: grammer_check | ||
type: llm | ||
source: | ||
type: code | ||
path: grammar_check.jinja2 | ||
inputs: | ||
max_tokens: 1000 | ||
text: ${read_file.output} | ||
deployment_name: gpt-35-turbo | ||
model: gpt-35-turbo | ||
connection: open_ai_connection | ||
api: chat | ||
- name: input_passthrough | ||
type: prompt | ||
source: | ||
type: code | ||
path: input_passthrough.jinja2 | ||
inputs: | ||
input: ${inputs.path} |
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,32 @@ | ||
import os | ||
import json | ||
|
||
def find_py_files(directory): | ||
|
||
sql_files = [] | ||
|
||
for root, _, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith('.py'): | ||
sql_files.append(os.path.abspath(os.path.join(root, file))) | ||
|
||
return sql_files | ||
|
||
def write_to_jsonl(files, output_file="data.jsonl"): | ||
""" | ||
Write list of file paths to a JSON lines file. | ||
Args: | ||
- files (list): List of file paths. | ||
- output_file (str): Name of the output JSON lines file. | ||
""" | ||
with open(output_file, 'w') as out: | ||
for file_path in files: | ||
line = json.dumps({"path": file_path}) | ||
out.write(line + '\n') | ||
|
||
if __name__ == "__main__": | ||
directory = "../../../" | ||
sql_files = find_py_files(directory) | ||
write_to_jsonl(sql_files) | ||
print(f"Output written to data.jsonl") |
18 changes: 18 additions & 0 deletions
18
examples/flows/standard/grammar-check/grammar_check.jinja2
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,18 @@ | ||
system: | ||
You are a python programmer. Please ready the python source doe. Check for any standard/error output to customer, whether the grammar and spelling are correct. If not, please correct them. | ||
Please output your suggestion to correct the grammar and spelling. | ||
Please output the found issues in below json format: | ||
{ | ||
"line": 1, | ||
"column": 1, | ||
"type": "spelling", | ||
"message": "Please correct the spelling of 'python'." | ||
} | ||
|
||
If there is no issue, please output: | ||
{ | ||
"message": "No issues found." | ||
} | ||
|
||
user: | ||
{{text}} |
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 @@ | ||
{{input}} |
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,19 @@ | ||
from promptflow import tool | ||
import time | ||
|
||
# The inputs section will change based on the arguments of the tool function, after you save the code | ||
# Adding type to arguments and return value will help the system show the types properly | ||
# Please update the function name/signature per need | ||
@tool | ||
def my_python_tool(path: str) -> str: | ||
content = "" | ||
try: | ||
time.sleep(6) | ||
with open(path, 'r', encoding='utf-16') as file: | ||
content = file.read() | ||
except Exception as e: | ||
with open(path, 'r') as file: | ||
content = file.read() | ||
return content | ||
|
||
|