Skip to content

Commit

Permalink
Merge pull request #38 from plasma-umass/cost
Browse files Browse the repository at this point in the history
Add cost estimation on text completion
  • Loading branch information
emeryberger authored Oct 4, 2023
2 parents b6d3a56 + 7841caa commit 748368c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
{ name="Nicolas van Kempen", email="nvankemp@gmail.com" },
{ name="Bryce Adelstein Lelbach", email="brycelelbach@gmail.com" }
]
dependencies = ["openai==0.28.1", "llm_utils==0.1.4"]
dependencies = ["openai==0.28.1", "llm_utils==0.2"]
description = "Explains and proposes fixes for compile-time errors for many programming languages."
readme = "README.md"
requires-python = ">=3.7"
Expand All @@ -23,7 +23,6 @@ classifiers = [
[project.scripts]
cwhy = "cwhy.__main__:main"


[project.urls]
"Homepage" = "https://github.com/plasma-umass/cwhy"
"Bug Tracker" = "https://github.com/plasma-umass/cwhy/issues"
10 changes: 10 additions & 0 deletions src/cwhy/cwhy.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,18 @@ def evaluate(args, stdin):
def evaluate_text_prompt(args, prompt, wrap=True, **kwargs):
completion = complete(args, prompt, **kwargs)
text = completion.choices[0].message.content

if wrap:
text = llm_utils.word_wrap_except_code_blocks(text)

cost = llm_utils.calculate_cost(
completion.usage.prompt_tokens,
completion.usage.completion_tokens,
args["llm"]
)
text += "\n\n"
text += f"This request cost ~ {cost:.2f}$."

return text


Expand Down

0 comments on commit 748368c

Please sign in to comment.