Skip to content

Commit

Permalink
Add JavaScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmurdza committed Dec 17, 2023
1 parent b8339f6 commit 36a3eb2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: pip install -r requirements.txt

- name: Run script to generate README-python.md
- name: Run script to transpile README.md
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: python generate.py
Expand All @@ -35,6 +35,6 @@ jobs:
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git add README-python.md
git commit -m "✨ Generate README-python from README."
git add README-*.md
git commit -m "✨ Generate README.md in various languages."
git push
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This repository contains a list of working code examples for calling various LLM

[README-python.md](README-python.md) contains the same examples in Python, and is generated automatically using GPT-3.5 whenever README.md is updated.

[README-js.md](README-js.md) contains the same examples in JavaScript, and is generated automatically using GPT-3.5 whenever README.md is updated.

See also: [List of cloud hosts for inference and fine-tuning](https://github.com/jamesmurdza/awesome-inference-hosts)

## Table of Contents
Expand Down
30 changes: 24 additions & 6 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@
always use double quotes
"""

prompts = {"python": bash_to_python_prompt}
bash_to_javascript_prompt = """\
convert this block of code as concisely as possible to
```javascript
const fetch = require("node-fetch");
const response = await fetch("https://...",{{
...
body: ...
}}).then((response) => response.json());
```
use process.env to get API keys
don't use intermediate variables
always use double quotes
"""

prompts = {
"python": bash_to_python_prompt,
"javascript": bash_to_javascript_prompt,
}

def transpile_readme(readme_content, to_language):
# Function to replace bash code blocks with python code blocks
Expand All @@ -30,9 +47,7 @@ def transpile_block(match):
generator = ModifyCodeChain.from_instruction(
prompts[to_language], ChatOpenAI(model="gpt-3.5-turbo", temperature=0.2)
)
result = f"```{to_language}\n{generator.run(bash_code)}\n```"
print(result)
return result
return f"```{to_language}\n{generator.run(bash_code)}\n```"

# Use re.sub() to find and replace bash code blocks with python code blocks
return re.sub(
Expand All @@ -43,7 +58,10 @@ def transpile_block(match):
with open("README.md", "r") as readme_file:
readme_content = readme_file.read()

# Write the updated content back to README.md
# Write the transpiled README-python.md and README-javascript.md
with open("README-python.md", "w") as readme_file:
readme_file.write(transpile_readme(readme_content, "python"))
print("Wrote README-python.md")
print("Wrote README-python.md")
with open("README-js.md", "w") as readme_file:
readme_file.write(transpile_readme(readme_content, "javascript"))
print("Wrote README-js.md")

0 comments on commit 36a3eb2

Please sign in to comment.