-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
Rspec 'integration' tests for optional use by contributors and ci #145
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5ca2838
Initial integration test
mattlindsey a93d8e1
Standardrb fixes
mattlindsey db1caeb
Merge branch 'main' of github.com:andreibondarev/langchainrb into 144…
mattlindsey 497d457
Xit rspec test for now until done
mattlindsey 3a94a85
Merge branch 'main' of github.com:andreibondarev/langchainrb into 144…
mattlindsey 5c41e12
Add weaviate integration test
mattlindsey 7c42140
Only use rspec for integration testing
mattlindsey 0765bea
Tidy up tests
mattlindsey 286421b
Add integration test example to README
mattlindsey 580513e
Add INTEGRATION_TESTS_ENABLED to env
mattlindsey fae371c
Merge branch 'main' of github.com:andreibondarev/langchainrb into 144…
mattlindsey f0c764f
Merge branch 'main' into 144_testing
mattlindsey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
# execute with command: | ||
# INTEGRATION_TESTS_ENABLED=true bundle exec rspec spec/integration/chain_of_thought_integration_spec.rb | ||
# | ||
# requires the following environment variables: | ||
# SERPAPI_API_KEY | ||
# OPENAI_API_KEY | ||
|
||
RSpec.describe "Chain of Thought integration with other components", type: :integration do | ||
it "Should run with search and calculator" do | ||
question = "How many full soccer fields would be needed to cover the distance between NYC and DC in a straight line?" | ||
|
||
search_tool = Langchain::Tool::SerpApi.new(api_key: ENV["SERPAPI_API_KEY"]) | ||
calculator_tool = Langchain::Tool::Calculator.new | ||
|
||
openai = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"]) | ||
|
||
agent = Langchain::Agent::ChainOfThoughtAgent.new( | ||
llm: openai, | ||
tools: [search_tool, calculator_tool] | ||
) | ||
result = agent.run(question: question) | ||
|
||
expect(result).to include("distance between NYC and DC") | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
# execute with command: | ||
# INTEGRATION_TESTS_ENABLED=true bundle exec rspec spec/integration/weaviate_with_openai_integration_spec.rb | ||
# | ||
# requires the following environment variables: | ||
# OPENAI_API_KEY | ||
# WEAVIATE_URL | ||
# WEAVIATE_API_KEY | ||
|
||
RSpec.describe "Weaviate with OpenAI", type: :integration do | ||
it "Should run as expected" do | ||
weaviate = Langchain::Vectorsearch::Weaviate.new( | ||
url: ENV["WEAVIATE_URL"], | ||
api_key: ENV["WEAVIATE_API_KEY"], | ||
index_name: "Recipes", | ||
llm: Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"]) | ||
) | ||
|
||
weaviate.create_default_schema | ||
|
||
recipes = [ | ||
"Preheat oven to 400 degrees F (200 degrees C). Cut the top off the head of garlic. Arrange the garlic, carrots, celery, onion, pepper, and tomato on a large baking sheet in a single layer. Drizzle the olive oil over the vegetables; season with salt and pepper. Roast the vegetables in the preheated oven, turning every 20 minutes, until tender and browned, about 1 hour. Combine the water, thyme, parsley, and bay leaves in a large stock pot over medium-high heat. Squeeze the head of garlic into the stock pot, and discard the outer husk. Place the carrots, celery, onion, pepper, and tomato in the stock pot. Bring the water to a boil; reduce heat to low and simmer for 1 1/2 hours; strain and cool.", | ||
"Heat oven to 190C/fan 170C/gas 5. Heat 1 tbsp oil and the butter in a frying pan, then add the onion and fry for 5 mins until softened. Cool slightly. Tip the sausagemeat, lemon zest, breadcrumbs, apricots, chestnuts and thyme into a bowl. Add the onion and cranberries, and mix everything together with your hands, adding plenty of pepper and a little salt. Cut each chicken breast into three fillets lengthwise and season all over with salt and pepper. Heat the remaining oil in the frying pan, and fry the chicken fillets quickly until browned, about 6-8 mins. Roll out two-thirds of the pastry to line a 20-23cm springform or deep loose-based tart tin. Press in half the sausage mix and spread to level. Then add the chicken pieces in one layer and cover with the rest of the sausage. Press down lightly. Roll out the remaining pastry. Brush the edges of the pastry with beaten egg and cover with the pastry lid. Pinch the edges to seal, then trim. Brush the top of the pie with egg, then roll out the trimmings to make holly leaf shapes and berries. Decorate the pie and brush again with egg. Set the tin on a baking sheet and bake for 50-60 mins, then cool in the tin for 15 mins. Remove and leave to cool completely. Serve with a winter salad and pickles." | ||
] | ||
|
||
weaviate.add_texts( | ||
texts: recipes | ||
) | ||
|
||
result = weaviate.similarity_search( | ||
query: "chicken", | ||
k: 1 | ||
).to_s | ||
|
||
expect(result).to include("Heat oven to 190C") | ||
end | ||
end |
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 |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
# Disable RSpec exposing methods globally on `Module` and `main` | ||
config.disable_monkey_patching! | ||
|
||
# Only run integration tests when enabled | ||
config.filter_run_excluding type: :integration unless ENV["INTEGRATION_TESTS_ENABLED"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably just filter out all integration tests by default is |
||
|
||
config.expect_with :rspec do |c| | ||
c.syntax = :expect | ||
end | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way that people do this is indexing into a vectorsearch DB all of the variations of possible acceptable answers and then run a vector search agains them to see if they "match".