Skip to content

Commit

Permalink
Adding poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgordonbell committed Jan 9, 2024
1 parent b9577b8 commit 42deb3f
Show file tree
Hide file tree
Showing 8 changed files with 4,067 additions and 0 deletions.
1,504 changes: 1,504 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.poetry]
name = "earthly-website"
version = "0.1.0"
description = ""
authors = ["Adam Gordon Bell <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
psupport = {path = "util/psupport", develop = true}

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1,484 changes: 1,484 additions & 0 deletions util/psupport/poetry.lock

Large diffs are not rendered by default.

449 changes: 449 additions & 0 deletions util/psupport/psupport/scripts/bottomcta.py

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions util/psupport/psupport/scripts/excerpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import argparse
import subprocess
import os
import guidance
from pathlib import Path
import contextlib

gpt35turbo = guidance.llms.OpenAI("gpt-3.5-turbo-16k")

def get_excerpt(content):
score = guidance("""
{{#system~}}
You generate two sentence summaries from markdown content.
{{~/system}}
{{#user~}}
{{content}}
Can you summarize this in two sentences?
{{~/user}}
{{#assistant~}}
{{gen 'summary' max_tokens=100 temperature=0}}
{{~/assistant}}
""", llm=gpt35turbo)
out = run_llm_program(score, content=content)
return out['summary'].strip()

def run_llm_program(program, *args, **kwargs):
return program(*args, **kwargs)

def add_excerpt_to_md_file(filename):

with open(filename, 'r') as f:
lines = f.readlines()

excerpt_exists = False

for i, line in enumerate(lines[1:], start=1):
if line.strip().startswith('excerpt:'):
excerpt_exists = True
elif not excerpt_exists and line.strip() == "---":
break

if not excerpt_exists:
# Generate the excerpt
file_content = Path(filename).read_text()
excerpt = get_excerpt(file_content)

# Insert the excerpt
lines.insert(i, f"excerpt: |\n {excerpt}\n")

with open(filename, 'w') as f:
f.writelines(lines)

def main():
parser = argparse.ArgumentParser(description='Add an excerpt to a markdown file.')
parser.add_argument('--dir', help='The directory containing the markdown files.')
parser.add_argument('--file', help='The path to a single markdown file.')

args = parser.parse_args()

if args.dir:
# Process each markdown file in the directory
for root, dirs, files in os.walk(args.dir):
for file in files:
if file.endswith('.md'):
path = os.path.join(root, file)
print(f"Starting: {path}")
add_excerpt_to_md_file(os.path.join(root, file))
print(f"Finishing: {path}")
elif args.file:
add_excerpt_to_md_file(args.file)
else:
print("Please provide either --dir or --file.")
exit(1)

if __name__ == '__main__':
main()
Loading

0 comments on commit 42deb3f

Please sign in to comment.