Skip to content

Commit

Permalink
fix: summarize example test with Gemma 2 2B.
Browse files Browse the repository at this point in the history
  • Loading branch information
codito committed Aug 19, 2024
1 parent d1752c0 commit a0414f2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions arey/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from arey.error import AreyError
from arey.platform.console import SignalContextManager, get_console
from arey.play import PlayFile
from arey.task import close


def _generate_response(
Expand Down Expand Up @@ -173,6 +174,7 @@ def task(instruction: str, overrides_file: str, verbose: bool) -> int:
lambda: (task.result and task.result.metrics),
)

close(task)
_print_logs(console, verbose, task.result and task.result.logs)
return 0

Expand Down
7 changes: 6 additions & 1 deletion arey/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ def run(task: Task, user_input: str) -> Iterator[str]:
finish_reason=finish_reason,
logs=stderr.getvalue(),
)
model.free()


def close(task: Task):
"""Close a task and free the model."""
if model:
model.free()
6 changes: 4 additions & 2 deletions docs/samples/summarize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type: override
tokens:
custom:
prompt_prefix: |
You are a SEO expert. Follow the instructions and provide an answer.
I am a SEO expert with a deep understanding of keywords and meta texts to
optimize a webpage for search engines. I will follow the instruction below
and help the user.
#Summarize and extract keywords from user message in this JSON format: {"summary": "", "keywords": []}.
Summarize and extract keywords from user message in this JSON format: {"summary": "", "keywords": []}.
6 changes: 4 additions & 2 deletions docs/samples/summarize_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Summarize sample script."""

#!/usr/bin/env python
import argparse
import glob
Expand Down Expand Up @@ -41,8 +42,9 @@ def summarize_markdown_file(task: Task, path: str, write: bool) -> None:
text = StringIO()
for response in run(task, instruction):
text.write(response)
formatted_text = text.getvalue().replace("```json", "").replace("```", "")
try:
summary = json.loads(text.getvalue())
summary = json.loads(formatted_text)
post["auto_summary"] = summary["summary"]
post["auto_keywords"] = summary["keywords"]
if write:
Expand All @@ -53,7 +55,7 @@ def summarize_markdown_file(task: Task, path: str, write: bool) -> None:
console.print("---")
console.print(f"[dim]{task.result and task.result.metrics}[/dim]")
except Exception:
console.print(text.getvalue())
console.print(formatted_text)
console.print_exception()


Expand Down

0 comments on commit a0414f2

Please sign in to comment.