Skip to content

Commit

Permalink
add a flow to check repo's grammar and spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Hu committed Sep 10, 2023
1 parent 2077f58 commit c6365ca
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/flows/standard/grammar-check/flow.dag.yaml
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}
32 changes: 32 additions & 0 deletions examples/flows/standard/grammar-check/generate_data.py
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 examples/flows/standard/grammar-check/grammar_check.jinja2
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}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{input}}
19 changes: 19 additions & 0 deletions examples/flows/standard/grammar-check/read_file.py
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


0 comments on commit c6365ca

Please sign in to comment.