Skip to content

Commit

Permalink
dev: update to gpt-4-turbo (#78)
Browse files Browse the repository at this point in the history
* update to gpt-4-turbo

* update readme
  • Loading branch information
betogaona7 authored Jan 15, 2024
1 parent e02c39d commit ad15c15
Show file tree
Hide file tree
Showing 7 changed files with 740 additions and 774 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ will give you the total cost of $2.95762 USD. This command triggers GPT calls an

## Dependency on GPT-4

We found that `GPT-3.5` can't extract code components and generate docstring in a reliable manner, while `GPT-4` can do so. Hence, devtale currently only works with `GPT-4`. Beware that the cost associated with running devtale on a large code repository may be prohibitive. To reduce this cost, devtale uses `text-davinci-003` for generating top-level file summaries and README files.
We found that `GPT-3.5` can't extract code components and generate docstring in a reliable manner, while `GPT-4` can do so. Hence, devtale currently only works with `GPT-4`. Beware that the cost associated with running devtale on a large code repository may be prohibitive. To reduce this cost, devtale uses `gpt-3.5-turbo-0613` for generating top-level file summaries and README files and `gpt-4-1106-preview` for the rest.

## Pipeline

Expand Down
6 changes: 4 additions & 2 deletions devtale/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ def process_file(
code_elements = []
for idx, doc in enumerate(big_docs):
elements_set, call_cost = extract_code_elements(
big_doc=doc, model_name="gpt-4", cost_estimation=cost_estimation
big_doc=doc,
model_name="gpt-4-1106-preview",
cost_estimation=cost_estimation,
)
cost += call_cost
if elements_set:
Expand Down Expand Up @@ -440,7 +442,7 @@ def process_file(
tale, call_cost = get_unit_tale(
short_doc=doc,
code_elements=code_elements_copy,
model_name="gpt-4",
model_name="gpt-4-1106-preview",
cost_estimation=cost_estimation,
)
cost += call_cost
Expand Down
6 changes: 5 additions & 1 deletion devtale/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
DOCSTRING_LABEL = "@DEVTALE-GENERATED:"

# Extracted from https://openai.com/pricing on January 15th, 2024.
GPT_PRICE = {"gpt-4": 0.03, "gpt-3.5-turbo-16k": 0.0010, "gpt-3.5-turbo": 0.0015}
GPT_PRICE = {
"gpt-4-1106-preview": 0.01,
"gpt-3.5-turbo-16k": 0.0010,
"gpt-3.5-turbo": 0.0010,
}
12 changes: 8 additions & 4 deletions devtale/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from json import JSONDecodeError
from pathlib import Path

import json_repair
import tiktoken
from langchain import LLMChain, PromptTemplate
from langchain.callbacks import get_openai_callback
Expand Down Expand Up @@ -55,7 +56,7 @@ def split_code(code, language, chunk_size=1000, chunk_overlap=0):


def extract_code_elements(
big_doc, verbose=False, model_name="gpt-4", cost_estimation=False
big_doc, verbose=False, model_name="gpt-4-1106-preview", cost_estimation=False
):
prompt = PromptTemplate(
template=CODE_EXTRACTOR_TEMPLATE,
Expand All @@ -79,7 +80,11 @@ def extract_code_elements(


def get_unit_tale(
short_doc, code_elements, model_name="gpt-4", verbose=False, cost_estimation=False
short_doc,
code_elements,
model_name="gpt-4-1106-preview",
verbose=False,
cost_estimation=False,
):
parser = PydanticOutputParser(pydantic_object=FileDocumentation)
prompt = PromptTemplate(
Expand Down Expand Up @@ -267,8 +272,7 @@ def _convert_to_json(text_answer):
if start_index != -1 and end_index != -1 and start_index < end_index:
json_text = text[start_index : end_index + 1]

json_text = _add_escape_characters(json_text)
result_json = json.loads(json_text)
result_json = json_repair.loads(json_text)
return result_json

except Exception as e:
Expand Down
1,394 changes: 720 additions & 674 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "devtale"
version = "0.1.3"
version = "0.1.4"
description = "Generate automatic repository documentation with LLMs"
authors = ["Mystral AI"]
readme = "README.md"
Expand All @@ -19,6 +19,7 @@ openai = "^0.27.8"
click = "^8.1.6"
python-dotenv = "^1.0.0"
tiktoken = "^0.5.1"
json-repair = "^0.4.5"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.3.3"
Expand Down
91 changes: 0 additions & 91 deletions requirements.txt

This file was deleted.

0 comments on commit ad15c15

Please sign in to comment.