Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency langchain to v0.1.11 [SECURITY] #297

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/templates/langchain/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dotenv import load_dotenv
from fastapi import FastAPI, HTTPException
from langchain import LLMChain, PromptTemplate
from langchain.llms import HuggingFacePipeline
from langchain_community.llms import HuggingFacePipeline
from transformers import pipeline

app = FastAPI()
Expand Down
3 changes: 2 additions & 1 deletion src/templates/langchain/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ transformers==4.40.0
python-dotenv==1.0.1
torch==2.2.2
uvicorn==0.29.0
langchain==0.0.285
langchain==0.1.11
langchain-community==0.0.34
# dev
ruff==0.4.1
pytest==8.1.1
Expand Down
15 changes: 7 additions & 8 deletions src/templates/langchain/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ruff: noqa: E501
import os
import re
import urllib.parse

from fastapi.testclient import TestClient
Expand All @@ -21,16 +22,13 @@ def test_text_generation_200():
text = "what is the moon"
response = client.get(f"/text-generation?text={urllib.parse.quote(text)}")


result = re.sub(r"[^a-zA-Z0-9 ]+", "", response.json()["answer"].strip())
assert response.is_success
assert (
response.json()["answer"]
== """The moon is a celestial body, and it is not a planet. It is an object of the solar system.
(The Moon is also called a "planet" because it orbits the sun.)
. The moon has a diameter of about 1.5 million kilometers. (It is about 2.4 million miles.) The diameter is 1,000 kilometers (about 1 million square miles).
, the planet is called the "moon" by the Greek word for "sun.\""""
result == "what is the moon The moon is a celestial body and it is not a planet It is an object of the solar system The Moon is also called a planet because it orbits the sun The moon has a diameter of about 15 million kilometers It is about 24 million miles The diameter is 1000 kilometers about 1 million square miles the planet is called the moon by the Greek word for sun"
)


def test_question_answering_400():
response = client.get("/question-answering")

Expand All @@ -46,8 +44,9 @@ def test_question_answering_200():
f"/question-answering?context={urllib.parse.quote(context)}&question={urllib.parse.quote(question)}",
)

result = re.sub(r"[^a-zA-Z0-9 ]+", "", response.json()["answer"].strip())
assert response.is_success
assert (
response.json()["answer"]
== "He likes to write code. He loves to make things. And he likes the idea of having a team of people working on a project. But he also likes being able to do things that are not possible in the real world. So he's a big fan of the open source community. I think that's what he really enjoys."
result
== "Context Tom likes coding and designing complex distributed systemsQuestion What Tom likesAnswer He likes to write code He loves to make things And he likes the idea of having a team of people working on a project But he also likes being able to do things that are not possible in the real world So hes a big fan of the open source community I think thats what he really enjoys"
)