-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 Update import paths for langchain tools and improve test coverage f…
…or chain functionalities
- Loading branch information
1 parent
50421d8
commit bc22070
Showing
2 changed files
with
46 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,61 @@ | ||
from codeinterpreterapi.chains import remove_download_link, get_file_modifications | ||
import asyncio | ||
|
||
from codeinterpreterapi.chains import ( | ||
aget_file_modifications, | ||
aremove_download_link, | ||
get_file_modifications, | ||
remove_download_link, | ||
) | ||
from langchain_openai import ChatOpenAI | ||
|
||
llm = ChatOpenAI(model="gpt-3.5-turbo") | ||
|
||
remove_download_link_example = ( | ||
"I have created the plot to your dataset.\n\n" | ||
"Link to the file [here](sandbox:/plot.png)." | ||
) | ||
|
||
base_code = """ | ||
import matplotlib.pyplot as plt | ||
x = list(range(1, 11)) | ||
y = [29, 39, 23, 32, 4, 43, 43, 23, 43, 77] | ||
plt.plot(x, y, marker='o') | ||
plt.xlabel('Index') | ||
plt.ylabel('Value') | ||
plt.title('Data Plot') | ||
""" | ||
code_with_mod = base_code + "\nplt.savefig('plot.png')" | ||
|
||
code_no_mod = base_code + "\nplt.show()" | ||
|
||
|
||
def test_remove_download_link() -> None: | ||
example = ( | ||
"I have created the plot to your dataset.\n\n" | ||
"Link to the file [here](sandbox:/plot.png)." | ||
) | ||
assert ( | ||
remove_download_link(example).formatted_response.strip() | ||
remove_download_link(remove_download_link_example, llm=llm).strip() | ||
== "I have created the plot to your dataset." | ||
) | ||
|
||
|
||
def test_get_file_modifications() -> None: | ||
base_code = """ | ||
import matplotlib.pyplot as plt | ||
async def test_remove_download_link_async() -> None: | ||
assert ( | ||
await aremove_download_link(remove_download_link_example, llm=llm) | ||
).strip() == "I have created the plot to your dataset." | ||
|
||
x = list(range(1, 11)) | ||
y = [29, 39, 23, 32, 4, 43, 43, 23, 43, 77] | ||
|
||
plt.plot(x, y, marker='o') | ||
plt.xlabel('Index') | ||
plt.ylabel('Value') | ||
plt.title('Data Plot') | ||
""" | ||
code_with_mod = base_code + "\nplt.savefig('plot.png')" | ||
def test_get_file_modifications() -> None: | ||
assert get_file_modifications(code_with_mod, llm=llm) == ["plot.png"] | ||
assert get_file_modifications(code_no_mod, llm=llm) == [] | ||
|
||
code_no_mod = base_code + "\nplt.show()" | ||
|
||
assert get_file_modifications(code_with_mod).modifications == ["plot.png"] | ||
assert get_file_modifications(code_no_mod).modifications == [] | ||
async def test_get_file_modifications_async() -> None: | ||
assert await aget_file_modifications(code_with_mod, llm=llm) == ["plot.png"] | ||
assert await aget_file_modifications(code_no_mod, llm=llm) == [] | ||
|
||
|
||
if __name__ == "__main__": | ||
# test_remove_download_link() | ||
test_remove_download_link() | ||
asyncio.run(test_remove_download_link_async()) | ||
test_get_file_modifications() | ||
asyncio.run(test_get_file_modifications_async()) |