Skip to content

Commit

Permalink
fix: update modifications_check.py for use LCEL
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu007 committed May 28, 2024
1 parent a43728a commit 3c5bc86
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/codeinterpreterapi/chains/modifications_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from typing import List, Optional

from langchain_core.language_models import BaseLanguageModel
from langchain_core.output_parsers import JsonOutputParser

from codeinterpreterapi.llm.llm import prepare_test_llm
from codeinterpreterapi.prompts import determine_modifications_prompt


Expand All @@ -14,12 +16,10 @@ def get_file_modifications(
if retry < 1:
return None

prompt = determine_modifications_prompt.format(code=code)

result = llm.invoke(prompt)

try:
result = json.loads(result.content)
result_seq = determine_modifications_prompt | llm | JsonOutputParser()
result = result_seq.invoke({"code": code})
print("result=", result)
except json.JSONDecodeError:
result = ""
if not result or not isinstance(result, dict) or "modifications" not in result:
Expand All @@ -35,12 +35,10 @@ async def aget_file_modifications(
if retry < 1:
return None

prompt = determine_modifications_prompt.format(code=code)

result = await llm.ainvoke(prompt)

try:
result = json.loads(result.content)
result_seq = determine_modifications_prompt | llm | JsonOutputParser()
result = result_seq.invoke({"code": code})
print("result=", result)
except json.JSONDecodeError:
result = ""
if not result or not isinstance(result, dict) or "modifications" not in result:
Expand All @@ -49,9 +47,7 @@ async def aget_file_modifications(


async def test() -> None:
from langchain_openai import ChatOpenAI

llm = ChatOpenAI()
llm = prepare_test_llm()

code = """
import matplotlib.pyplot as plt
Expand All @@ -67,7 +63,8 @@ async def test() -> None:
plt.show()
"""

print(get_file_modifications(code, llm))
result = get_file_modifications(code, llm)
assert result == [] # This is no change for the file system.


if __name__ == "__main__":
Expand Down

0 comments on commit 3c5bc86

Please sign in to comment.