langchainrb 0.14.0 → 0.15.0

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 +8 -0
  3. data/lib/langchain/assistants/assistant.rb +175 -131
  4. data/lib/langchain/assistants/messages/ollama_message.rb +9 -21
  5. data/lib/langchain/contextual_logger.rb +2 -2
  6. data/lib/langchain/llm/google_gemini.rb +1 -1
  7. data/lib/langchain/llm/ollama.rb +23 -17
  8. data/lib/langchain/llm/openai.rb +1 -1
  9. data/lib/langchain/llm/response/ollama_response.rb +1 -15
  10. data/lib/langchain/llm/unified_parameters.rb +2 -2
  11. data/lib/langchain/tool/calculator.rb +38 -0
  12. data/lib/langchain/tool/{database/database.rb → database.rb} +24 -12
  13. data/lib/langchain/tool/file_system.rb +44 -0
  14. data/lib/langchain/tool/{google_search/google_search.rb → google_search.rb} +17 -23
  15. data/lib/langchain/tool/{news_retriever/news_retriever.rb → news_retriever.rb} +41 -14
  16. data/lib/langchain/tool/ruby_code_interpreter.rb +41 -0
  17. data/lib/langchain/tool/{tavily/tavily.rb → tavily.rb} +24 -10
  18. data/lib/langchain/tool/vectorsearch.rb +40 -0
  19. data/lib/langchain/tool/{weather/weather.rb → weather.rb} +21 -17
  20. data/lib/langchain/tool/{wikipedia/wikipedia.rb → wikipedia.rb} +17 -13
  21. data/lib/langchain/tool_definition.rb +212 -0
  22. data/lib/langchain/utils/hash_transformer.rb +9 -17
  23. data/lib/langchain/vectorsearch/chroma.rb +2 -2
  24. data/lib/langchain/vectorsearch/elasticsearch.rb +2 -2
  25. data/lib/langchain/vectorsearch/epsilla.rb +3 -3
  26. data/lib/langchain/vectorsearch/milvus.rb +2 -2
  27. data/lib/langchain/vectorsearch/pgvector.rb +2 -2
  28. data/lib/langchain/vectorsearch/pinecone.rb +2 -2
  29. data/lib/langchain/vectorsearch/qdrant.rb +2 -2
  30. data/lib/langchain/vectorsearch/weaviate.rb +4 -4
  31. data/lib/langchain/version.rb +1 -1
  32. metadata +13 -23
  33. data/lib/langchain/tool/base.rb +0 -107
  34. data/lib/langchain/tool/calculator/calculator.json +0 -19
  35. data/lib/langchain/tool/calculator/calculator.rb +0 -34
  36. data/lib/langchain/tool/database/database.json +0 -46
  37. data/lib/langchain/tool/file_system/file_system.json +0 -57
  38. data/lib/langchain/tool/file_system/file_system.rb +0 -32
  39. data/lib/langchain/tool/google_search/google_search.json +0 -19
  40. data/lib/langchain/tool/news_retriever/news_retriever.json +0 -122
  41. data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json +0 -19
  42. data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb +0 -37
  43. data/lib/langchain/tool/tavily/tavily.json +0 -54
  44. data/lib/langchain/tool/vectorsearch/vectorsearch.json +0 -24
  45. data/lib/langchain/tool/vectorsearch/vectorsearch.rb +0 -36
  46. data/lib/langchain/tool/weather/weather.json +0 -19
  47. data/lib/langchain/tool/wikipedia/wikipedia.json +0 -19
@@ -1,122 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "news_retriever__get_everything",
6
- "description": "News Retriever: Search through millions of articles from over 150,000 large and small news sources and blogs.",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "q": {
11
- "type": "string",
12
- "description": "Keywords or phrases to search for in the article title and body. Surround phrases with quotes (\") for exact match. Alternatively you can use the AND / OR / NOT keywords, and optionally group these with parenthesis. Must be URL-encoded."
13
- },
14
- "search_in": {
15
- "type": "string",
16
- "description": "The fields to restrict your q search to.",
17
- "enum": ["title", "description", "content"]
18
- },
19
- "sources": {
20
- "type": "string",
21
- "description": "A comma-seperated string of identifiers (maximum 20) for the news sources or blogs you want headlines from. Use the /sources endpoint to locate these programmatically or look at the sources index."
22
- },
23
- "domains": {
24
- "type": "string",
25
- "description": "A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to."
26
- },
27
- "exclude_domains": {
28
- "type": "string",
29
- "description": "A comma-seperated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to remove from the results."
30
- },
31
- "from": {
32
- "type": "string",
33
- "description": "A date and optional time for the oldest article allowed. This should be in ISO 8601 format."
34
- },
35
- "to": {
36
- "type": "string",
37
- "description": "A date and optional time for the newest article allowed. This should be in ISO 8601 format."
38
- },
39
- "language": {
40
- "type": "string",
41
- "description": "The 2-letter ISO-639-1 code of the language you want to get headlines for.",
42
- "enum": ["ar", "de", "en", "es", "fr", "he", "it", "nl", "no", "pt", "ru", "sv", "ud", "zh"]
43
- },
44
- "sort_by": {
45
- "type": "string",
46
- "description": "The order to sort the articles in.",
47
- "enum": ["relevancy", "popularity", "publishedAt"]
48
- },
49
- "page_size": {
50
- "type": "integer",
51
- "description": "The number of results to return per page (request). 5 is the default, 100 is the maximum."
52
- },
53
- "page": {
54
- "type": "integer",
55
- "description": "Use this to page through the results if the total results found is greater than the page size."
56
- }
57
- }
58
- }
59
- }
60
- },
61
- {
62
- "type": "function",
63
- "function": {
64
- "name": "news_retriever__get_top_headlines",
65
- "description": "News Retriever: Provides live top and breaking headlines for a country, specific category in a country, single source, or multiple sources. You can also search with keywords. Articles are sorted by the earliest date published first.",
66
- "parameters": {
67
- "type": "object",
68
- "properties": {
69
- "country": {
70
- "type": "string",
71
- "description": "The 2-letter ISO 3166-1 code of the country you want to get headlines for.",
72
- "enum": ["ae", "ar", "at", "au", "be", "bg", "br", "ca", "ch", "cn", "co", "cu", "cz", "de", "eg", "fr", "gb", "gr", "hk", "hu", "id", "ie", "il", "in", "it", "jp", "kr", "lt", "lv", "ma", "mx", "my", "ng", "nl", "no", "nz", "ph", "pl", "pt", "ro", "rs", "ru", "sa", "se", "sg", "si", "sk", "th", "tr", "tw", "ua", "us", "ve", "za"]
73
- },
74
- "category": {
75
- "type": "string",
76
- "description": "The category you want to get headlines for.",
77
- "enum": ["business", "entertainment", "general", "health", "science", "sports", "technology"]
78
- },
79
- "q": {
80
- "type": "string",
81
- "description": "Keywords or a phrase to search for."
82
- },
83
- "page_size": {
84
- "type": "integer",
85
- "description": "The number of results to return per page (request). 5 is the default, 100 is the maximum."
86
- },
87
- "page": {
88
- "type": "integer",
89
- "description": "Use this to page through the results if the total results found is greater than the page size."
90
- }
91
- }
92
- }
93
- }
94
- },
95
- {
96
- "type": "function",
97
- "function": {
98
- "name": "news_retriever__get_sources",
99
- "description": "News Retriever: This endpoint returns the subset of news publishers that top headlines (/v2/top-headlines) are available from. It's mainly a convenience endpoint that you can use to keep track of the publishers available on the API, and you can pipe it straight through to your users.",
100
- "parameters": {
101
- "type": "object",
102
- "properties": {
103
- "country": {
104
- "type": "string",
105
- "description": "The 2-letter ISO 3166-1 code of the country you want to get headlines for. Default: all countries.",
106
- "enum": ["ae", "ar", "at", "au", "be", "bg", "br", "ca", "ch", "cn", "co", "cu", "cz", "de", "eg", "fr", "gb", "gr", "hk", "hu", "id", "ie", "il", "in", "it", "jp", "kr", "lt", "lv", "ma", "mx", "my", "ng", "nl", "no", "nz", "ph", "pl", "pt", "ro", "rs", "ru", "sa", "se", "sg", "si", "sk", "th", "tr", "tw", "ua", "us", "ve", "za"]
107
- },
108
- "category": {
109
- "type": "string",
110
- "description": "The category you want to get headlines for. Default: all categories.",
111
- "enum": ["business", "entertainment", "general", "health", "science", "sports", "technology"]
112
- },
113
- "language": {
114
- "type": "string",
115
- "description": "The 2-letter ISO-639-1 code of the language you want to get headlines for.",
116
- "enum": ["ar", "de", "en", "es", "fr", "he", "it", "nl", "no", "pt", "ru", "sv", "ud", "zh"]
117
- }
118
- }
119
- }
120
- }
121
- }
122
- ]
@@ -1,19 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "ruby_code_interpreter__execute",
6
- "description": "Executes Ruby code in a sandboxes environment.",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "input": {
11
- "type": "string",
12
- "description": "ruby code expression"
13
- }
14
- },
15
- "required": ["input"]
16
- }
17
- }
18
- }
19
- ]
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain::Tool
4
- class RubyCodeInterpreter < Base
5
- #
6
- # A tool that execute Ruby code in a sandboxed environment.
7
- #
8
- # Gem requirements:
9
- # gem "safe_ruby", "~> 1.0.4"
10
- #
11
- # Usage:
12
- # interpreter = Langchain::Tool::RubyCodeInterpreter.new
13
- #
14
- NAME = "ruby_code_interpreter"
15
- ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
16
-
17
- def initialize(timeout: 30)
18
- depends_on "safe_ruby"
19
-
20
- @timeout = timeout
21
- end
22
-
23
- # Executes Ruby code in a sandboxes environment.
24
- #
25
- # @param input [String] ruby code expression
26
- # @return [String] Answer
27
- def execute(input:)
28
- Langchain.logger.info("Executing \"#{input}\"", for: self.class)
29
-
30
- safe_eval(input)
31
- end
32
-
33
- def safe_eval(code)
34
- SafeRuby.eval(code, timeout: @timeout)
35
- end
36
- end
37
- end
@@ -1,54 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "tavily__search",
6
- "description": "Tavily Tool: Robust search API",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "query": {
11
- "type": "string",
12
- "description": "The search query string"
13
- },
14
- "search_depth": {
15
- "type": "string",
16
- "description": "The depth of the search: basic for quick results and advanced for indepth high quality results but longer response time",
17
- "enum": ["basic", "advanced"]
18
- },
19
- "include_images": {
20
- "type": "boolean",
21
- "description": "Include a list of query related images in the response"
22
- },
23
- "include_answer": {
24
- "type": "boolean",
25
- "description": "Include answers in the search results"
26
- },
27
- "include_raw_content": {
28
- "type": "boolean",
29
- "description": "Include raw content in the search results"
30
- },
31
- "max_results": {
32
- "type": "integer",
33
- "description": "The number of maximum search results to return"
34
- },
35
- "include_domains": {
36
- "type": "array",
37
- "items": {
38
- "type": "string"
39
- },
40
- "description": "A list of domains to specifically include in the search results"
41
- },
42
- "exclude_domains": {
43
- "type": "array",
44
- "items": {
45
- "type": "string"
46
- },
47
- "description": "A list of domains to specifically exclude from the search results"
48
- }
49
- },
50
- "required": ["query"]
51
- }
52
- }
53
- }
54
- ]
@@ -1,24 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "vectorsearch__similarity_search",
6
- "description": "Vectorsearch: Retrieves relevant document for the query",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "query": {
11
- "type": "string",
12
- "description": "Query to find similar documents for"
13
- },
14
- "k": {
15
- "type": "integer",
16
- "description": "Number of similar documents to retrieve",
17
- "default": 4
18
- }
19
- },
20
- "required": ["query"]
21
- }
22
- }
23
- }
24
- ]
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain::Tool
4
- class Vectorsearch < Base
5
- #
6
- # A tool wraps vectorsearch classes
7
- #
8
- # Usage:
9
- # # Initialize the LLM that will be used to generate embeddings
10
- # ollama = Langchain::LLM::Ollama.new(url: ENV["OLLAMA_URL"]
11
- # chroma = Langchain::Vectorsearch::Chroma.new(url: ENV["CHROMA_URL"], index_name: "my_index", llm: ollama)
12
- #
13
- # # This tool can now be used by the Assistant
14
- # vectorsearch_tool = Langchain::Tool::Vectorsearch.new(vectorsearch: chroma)
15
- #
16
- NAME = "vectorsearch"
17
- ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
18
-
19
- attr_reader :vectorsearch
20
-
21
- # Initializes the Vectorsearch tool
22
- #
23
- # @param vectorsearch [Langchain::Vectorsearch::Base] Vectorsearch instance to use
24
- def initialize(vectorsearch:)
25
- @vectorsearch = vectorsearch
26
- end
27
-
28
- # Executes the vector search and returns the results
29
- #
30
- # @param query [String] The query to search for
31
- # @param k [Integer] The number of results to return
32
- def similarity_search(query:, k: 4)
33
- vectorsearch.similarity_search(query:, k: 4)
34
- end
35
- end
36
- end
@@ -1,19 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "weather__execute",
6
- "description": "Returns current weather for a city",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "input": {
11
- "type": "string",
12
- "description": "comma separated city and unit (optional: imperial, metric, or standard)"
13
- }
14
- },
15
- "required": ["input"]
16
- }
17
- }
18
- }
19
- ]
@@ -1,19 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "wikipedia__execute",
6
- "description": "Executes Wikipedia API search and returns the answer",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "input": {
11
- "type": "string",
12
- "description": "search query"
13
- }
14
- },
15
- "required": ["input"]
16
- }
17
- }
18
- }
19
- ]