langchainrb 0.6.11 → 0.6.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +1 -7
  4. data/lib/langchain/agent/base.rb +1 -0
  5. data/lib/langchain/agent/{react_agent/react_agent.rb → react_agent.rb} +12 -11
  6. data/lib/langchain/ai_message.rb +9 -0
  7. data/lib/langchain/conversation.rb +11 -11
  8. data/lib/langchain/conversation_memory.rb +3 -7
  9. data/lib/langchain/human_message.rb +9 -0
  10. data/lib/langchain/llm/cohere.rb +2 -1
  11. data/lib/langchain/llm/google_palm.rb +15 -10
  12. data/lib/langchain/llm/llama_cpp.rb +5 -5
  13. data/lib/langchain/llm/openai.rb +24 -25
  14. data/lib/langchain/llm/replicate.rb +2 -1
  15. data/lib/langchain/message.rb +35 -0
  16. data/lib/langchain/output_parsers/base.rb +5 -4
  17. data/lib/langchain/output_parsers/{fix.rb → output_fixing_parser.rb} +3 -1
  18. data/lib/langchain/prompt/loading.rb +73 -67
  19. data/lib/langchain/prompt.rb +5 -0
  20. data/lib/langchain/system_message.rb +9 -0
  21. data/lib/langchain/tool/base.rb +14 -14
  22. data/lib/langchain/vectorsearch/pgvector.rb +7 -5
  23. data/lib/langchain/version.rb +1 -1
  24. data/lib/langchain.rb +19 -97
  25. metadata +37 -38
  26. data/.env.example +0 -21
  27. data/.rspec +0 -3
  28. data/.rubocop.yml +0 -11
  29. data/.tool-versions +0 -1
  30. data/Gemfile +0 -14
  31. data/Gemfile.lock +0 -360
  32. data/Rakefile +0 -17
  33. data/examples/conversation_with_openai.rb +0 -52
  34. data/examples/create_and_manage_few_shot_prompt_templates.rb +0 -36
  35. data/examples/create_and_manage_prompt_templates.rb +0 -25
  36. data/examples/create_and_manage_prompt_templates_using_structured_output_parser.rb +0 -116
  37. data/examples/llama_cpp.rb +0 -24
  38. data/examples/open_ai_function_calls.rb +0 -41
  39. data/examples/open_ai_qdrant_function_calls.rb +0 -39
  40. data/examples/pdf_store_and_query_with_chroma.rb +0 -40
  41. data/examples/store_and_query_with_pinecone.rb +0 -46
  42. data/examples/store_and_query_with_qdrant.rb +0 -37
  43. data/examples/store_and_query_with_weaviate.rb +0 -32
  44. data/lefthook.yml +0 -5
  45. data/sig/langchain.rbs +0 -4
  46. /data/lib/langchain/agent/{sql_query_agent/sql_query_agent.rb → sql_query_agent.rb} +0 -0
  47. /data/lib/langchain/output_parsers/{structured.rb → structured_output_parser.rb} +0 -0
@@ -1,39 +0,0 @@
1
- require "langchain"
2
- require "dotenv/load"
3
-
4
- functions = [
5
- {
6
- name: "create_rails_controller",
7
- description: "gives a command to create a rails controller",
8
- parameters: {
9
- type: :object,
10
- properties: {
11
- controller_name: {
12
- type: :string,
13
- description: "the controller name, e.g. users_controller"
14
- }
15
- },
16
- required: ["controller_name"]
17
- }
18
- }
19
- ]
20
-
21
- openai = Langchain::LLM::OpenAI.new(
22
- api_key: ENV["OPENAI_API_KEY"],
23
- default_options: {
24
- chat_completion_model_name: "gpt-3.5-turbo-16k"
25
- }
26
- )
27
-
28
- client = Langchain::Vectorsearch::Qdrant.new(
29
- url: ENV["QDRANT_URL"],
30
- api_key: ENV["QDRANT_API_KEY"],
31
- index_name: ENV["QDRANT_INDEX"],
32
- llm: openai
33
- )
34
-
35
- client.llm.functions = functions
36
- client.llm.complete_response = true
37
- chat = client.ask(question: "create a users_controller")
38
-
39
- puts chat
@@ -1,40 +0,0 @@
1
- require "langchain"
2
-
3
- # gem install chroma-db
4
- # or add `gem "chroma-db", "~> 0.3.0"` to your Gemfile
5
-
6
- # Instantiate the Chroma client
7
- chroma = Langchain::Vectorsearch::Chroma.new(
8
- url: ENV["CHROMA_URL"],
9
- index_name: "documents",
10
- llm: Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
11
- )
12
-
13
- # Create the default schema.
14
- chroma.create_default_schema
15
-
16
- # gem install these or add them to your Gemfile
17
- # Add `gem "pdf-reader", "~> 1.4"` to your Gemfile
18
- # Add `gem "docx", branch: "master", git: "https://github.com/ruby-docx/docx.git"` to your Gemfile
19
-
20
- # Set up an array of PDF and TXT documents
21
- docs = [
22
- Langchain.root.join("/docs/document.pdf"),
23
- Langchain.root.join("/docs/document.txt"),
24
- Langchain.root.join("/docs/document.docx")
25
- ]
26
-
27
- # Add data to the index. Weaviate will use OpenAI to generate embeddings behind the scene.
28
- chroma.add_data(
29
- paths: docs
30
- )
31
-
32
- # Query your data
33
- chroma.similarity_search(
34
- query: "..."
35
- )
36
-
37
- # Interact with your index through Q&A
38
- chroma.ask(
39
- question: "..."
40
- )
@@ -1,46 +0,0 @@
1
- require "langchain"
2
-
3
- # gem install pinecone
4
- # or add `gem "pinecone"` to your Gemfile
5
-
6
- # Instantiate the Pinecone client
7
- pinecone = Langchain::Vectorsearch::Pinecone.new(
8
- environment: ENV["PINECONE_ENVIRONMENT"],
9
- api_key: ENV["PINECONE_API_KEY"],
10
- index_name: "recipes",
11
- llm: Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
12
- )
13
-
14
- # Create the default schema.
15
- # If you are using the free Pinecone tier, ensure there is not an existing schema/index
16
- pinecone.create_default_schema
17
-
18
- # Set up an array of text strings
19
- recipes = [
20
- "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.",
21
- "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."
22
- ]
23
-
24
- # Add data to the index. Pinecone will use OpenAI to generate embeddings behind the scene.
25
- pinecone.add_texts(
26
- texts: recipes
27
- )
28
-
29
- # Query your data
30
- pinecone.similarity_search(
31
- query: "chicken",
32
- k: 1
33
- )
34
-
35
- # Interact with your index through Q&A
36
- pinecone.ask(
37
- question: "What is a good recipe for chicken?"
38
- )
39
-
40
- # Generate an embedding and search by it
41
- openai = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
42
- embedding = openai.embed(text: "veggie")
43
-
44
- pinecone.similarity_search_by_vector(
45
- embedding: embedding
46
- )
@@ -1,37 +0,0 @@
1
- require "langchain"
2
-
3
- # gem install qdrant-ruby
4
- # or add `gem "qdrant-ruby"` to your Gemfile
5
-
6
- # Instantiate the Qdrant client
7
- qdrant = Langchain::Vectorsearch::Qdrant.new(
8
- url: ENV["QDRANT_URL"],
9
- api_key: ENV["QDRANT_API_KEY"],
10
- index_name: "recipes",
11
- llm: Langchain::LLM::Cohere.new(api_key: ENV["COHERE_API_KEY"])
12
- )
13
-
14
- # Create the default schema.
15
- qdrant.create_default_schema
16
-
17
- # Set up an array of text strings
18
- recipes = [
19
- "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.",
20
- "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."
21
- ]
22
-
23
- # Add data to the index. Weaviate will use OpenAI to generate embeddings behind the scene.
24
- qdrant.add_texts(
25
- texts: recipes
26
- )
27
-
28
- # Query your data
29
- qdrant.similarity_search(
30
- query: "chicken",
31
- k: 1
32
- )
33
-
34
- # Interact with your index through Q&A
35
- qdrant.ask(
36
- question: "What is the best recipe for chicken?"
37
- )
@@ -1,32 +0,0 @@
1
- require "langchain"
2
-
3
- # gem install weaviate-ruby
4
- # or add `gem "weaviate-ruby"` to your Gemfile
5
-
6
- # Instantiate the Weaviate client
7
- weaviate = Langchain::Vectorsearch::Weaviate.new(
8
- url: ENV["WEAVIATE_URL"],
9
- api_key: ENV["WEAVIATE_API_KEY"],
10
- index_name: "Recipes",
11
- llm: Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
12
- )
13
-
14
- # Create the default schema. A text field `content` will be used.
15
- weaviate.create_default_schema
16
-
17
- # Set up an array of text strings
18
- recipes = [
19
- "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.",
20
- "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."
21
- ]
22
-
23
- # Add data to the index. Weaviate will use OpenAI to generate embeddings behind the scene.
24
- weaviate.add_texts(
25
- texts: recipes
26
- )
27
-
28
- # Query your data
29
- weaviate.similarity_search(
30
- query: "chicken",
31
- k: 1
32
- )
data/lefthook.yml DELETED
@@ -1,5 +0,0 @@
1
- pre-commit:
2
- commands:
3
- lint:
4
- run: standardrb --fix
5
- stage_fixed: true
data/sig/langchain.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Langchain
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end