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,24 +1,16 @@
1
1
  module Langchain
2
2
  module Utils
3
3
  class HashTransformer
4
- # Converts a string to camelCase
5
- def self.camelize_lower(str)
6
- str.split("_").inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
7
- end
8
-
9
- # Recursively transforms the keys of a hash to camel case
10
- def self.deep_transform_keys(hash, &block)
11
- case hash
12
- when Hash
13
- hash.each_with_object({}) do |(key, value), result|
14
- new_key = block.call(key)
15
- result[new_key] = deep_transform_keys(value, &block)
4
+ def self.symbolize_keys(hash)
5
+ hash.map do |k, v|
6
+ new_key = begin
7
+ k.to_sym
8
+ rescue
9
+ k
16
10
  end
17
- when Array
18
- hash.map { |item| deep_transform_keys(item, &block) }
19
- else
20
- hash
21
- end
11
+ new_value = v.is_a?(Hash) ? symbolize_keys(v) : v
12
+ [new_key, new_value]
13
+ end.to_h
22
14
  end
23
15
  end
24
16
  end
@@ -124,7 +124,7 @@ module Langchain::Vectorsearch
124
124
  # @param k [Integer] The number of results to have in context
125
125
  # @yield [String] Stream responses back one String at a time
126
126
  # @return [String] The answer to the question
127
- def ask(question:, k: 4, &)
127
+ def ask(question:, k: 4, &block)
128
128
  search_results = similarity_search(query: question, k: k)
129
129
 
130
130
  context = search_results.map do |result|
@@ -136,7 +136,7 @@ module Langchain::Vectorsearch
136
136
  prompt = generate_rag_prompt(question: question, context: context)
137
137
 
138
138
  messages = [{role: "user", content: prompt}]
139
- response = llm.chat(messages: messages, &)
139
+ response = llm.chat(messages: messages, &block)
140
140
 
141
141
  response.context = context
142
142
  response
@@ -143,7 +143,7 @@ module Langchain::Vectorsearch
143
143
  # @param k [Integer] The number of results to have in context
144
144
  # @yield [String] Stream responses back one String at a time
145
145
  # @return [String] The answer to the question
146
- def ask(question:, k: 4, &)
146
+ def ask(question:, k: 4, &block)
147
147
  search_results = similarity_search(query: question, k: k)
148
148
 
149
149
  context = search_results.map do |result|
@@ -153,7 +153,7 @@ module Langchain::Vectorsearch
153
153
  prompt = generate_rag_prompt(question: question, context: context)
154
154
 
155
155
  messages = [{role: "user", content: prompt}]
156
- response = llm.chat(messages: messages, &)
156
+ response = llm.chat(messages: messages, &block)
157
157
 
158
158
  response.context = context
159
159
  response
@@ -96,7 +96,7 @@ module Langchain::Vectorsearch
96
96
 
97
97
  status_code, response = @client.database.insert(@table_name, data)
98
98
  raise "Failed to insert texts: #{response}" if status_code != 200
99
- response
99
+ JSON.parse(response)
100
100
  end
101
101
 
102
102
  # Search for similar texts
@@ -129,7 +129,7 @@ module Langchain::Vectorsearch
129
129
  # @param k [Integer] The number of results to have in context
130
130
  # @yield [String] Stream responses back one String at a time
131
131
  # @return [String] The answer to the question
132
- def ask(question:, k: 4, &)
132
+ def ask(question:, k: 4, &block)
133
133
  search_results = similarity_search(query: question, k: k)
134
134
 
135
135
  context = search_results.map do |result|
@@ -140,7 +140,7 @@ module Langchain::Vectorsearch
140
140
  prompt = generate_rag_prompt(question: question, context: context)
141
141
 
142
142
  messages = [{role: "user", content: prompt}]
143
- response = llm.chat(messages: messages, &)
143
+ response = llm.chat(messages: messages, &block)
144
144
 
145
145
  response.context = context
146
146
  response
@@ -156,7 +156,7 @@ module Langchain::Vectorsearch
156
156
  # @param k [Integer] The number of results to have in context
157
157
  # @yield [String] Stream responses back one String at a time
158
158
  # @return [String] The answer to the question
159
- def ask(question:, k: 4, &)
159
+ def ask(question:, k: 4, &block)
160
160
  search_results = similarity_search(query: question, k: k)
161
161
 
162
162
  content_field = search_results.dig("results", "fields_data").select { |field| field.dig("field_name") == "content" }
@@ -167,7 +167,7 @@ module Langchain::Vectorsearch
167
167
  prompt = generate_rag_prompt(question: question, context: context)
168
168
 
169
169
  messages = [{role: "user", content: prompt}]
170
- response = llm.chat(messages: messages, &)
170
+ response = llm.chat(messages: messages, &block)
171
171
 
172
172
  response.context = context
173
173
  response
@@ -146,7 +146,7 @@ module Langchain::Vectorsearch
146
146
  # @param k [Integer] The number of results to have in context
147
147
  # @yield [String] Stream responses back one String at a time
148
148
  # @return [String] The answer to the question
149
- def ask(question:, k: 4, &)
149
+ def ask(question:, k: 4, &block)
150
150
  search_results = similarity_search(query: question, k: k)
151
151
 
152
152
  context = search_results.map do |result|
@@ -157,7 +157,7 @@ module Langchain::Vectorsearch
157
157
  prompt = generate_rag_prompt(question: question, context: context)
158
158
 
159
159
  messages = [{role: "user", content: prompt}]
160
- response = llm.chat(messages: messages, &)
160
+ response = llm.chat(messages: messages, &block)
161
161
 
162
162
  response.context = context
163
163
  response
@@ -171,7 +171,7 @@ module Langchain::Vectorsearch
171
171
  # @param filter [String] The filter to use
172
172
  # @yield [String] Stream responses back one String at a time
173
173
  # @return [String] The answer to the question
174
- def ask(question:, namespace: "", filter: nil, k: 4, &)
174
+ def ask(question:, namespace: "", filter: nil, k: 4, &block)
175
175
  search_results = similarity_search(query: question, namespace: namespace, filter: filter, k: k)
176
176
 
177
177
  context = search_results.map do |result|
@@ -182,7 +182,7 @@ module Langchain::Vectorsearch
182
182
  prompt = generate_rag_prompt(question: question, context: context)
183
183
 
184
184
  messages = [{role: "user", content: prompt}]
185
- response = llm.chat(messages: messages, &)
185
+ response = llm.chat(messages: messages, &block)
186
186
 
187
187
  response.context = context
188
188
  response
@@ -137,7 +137,7 @@ module Langchain::Vectorsearch
137
137
  # @param k [Integer] The number of results to have in context
138
138
  # @yield [String] Stream responses back one String at a time
139
139
  # @return [String] The answer to the question
140
- def ask(question:, k: 4, &)
140
+ def ask(question:, k: 4, &block)
141
141
  search_results = similarity_search(query: question, k: k)
142
142
 
143
143
  context = search_results.map do |result|
@@ -148,7 +148,7 @@ module Langchain::Vectorsearch
148
148
  prompt = generate_rag_prompt(question: question, context: context)
149
149
 
150
150
  messages = [{role: "user", content: prompt}]
151
- response = llm.chat(messages: messages, &)
151
+ response = llm.chat(messages: messages, &block)
152
152
 
153
153
  response.context = context
154
154
  response
@@ -6,7 +6,7 @@ module Langchain::Vectorsearch
6
6
  # Wrapper around Weaviate
7
7
  #
8
8
  # Gem requirements:
9
- # gem "weaviate-ruby", "~> 0.8.9"
9
+ # gem "weaviate-ruby", "~> 0.9.0"
10
10
  #
11
11
  # Usage:
12
12
  # weaviate = Langchain::Vectorsearch::Weaviate.new(url: ENV["WEAVIATE_URL"], api_key: ENV["WEAVIATE_API_KEY"], index_name: "Docs", llm: llm)
@@ -17,7 +17,7 @@ module Langchain::Vectorsearch
17
17
  # @param api_key [String] The API key to use
18
18
  # @param index_name [String] The capitalized name of the index to use
19
19
  # @param llm [Object] The LLM client to use
20
- def initialize(url:, api_key:, index_name:, llm:)
20
+ def initialize(url:, index_name:, llm:, api_key: nil)
21
21
  depends_on "weaviate-ruby", req: "weaviate"
22
22
 
23
23
  @client = ::Weaviate::Client.new(
@@ -143,7 +143,7 @@ module Langchain::Vectorsearch
143
143
  # @param k [Integer] The number of results to have in context
144
144
  # @yield [String] Stream responses back one String at a time
145
145
  # @return [Hash] The answer
146
- def ask(question:, k: 4, &)
146
+ def ask(question:, k: 4, &block)
147
147
  search_results = similarity_search(query: question, k: k)
148
148
 
149
149
  context = search_results.map do |result|
@@ -154,7 +154,7 @@ module Langchain::Vectorsearch
154
154
  prompt = generate_rag_prompt(question: question, context: context)
155
155
 
156
156
  messages = [{role: "user", content: prompt}]
157
- response = llm.chat(messages: messages, &)
157
+ response = llm.chat(messages: messages, &block)
158
158
 
159
159
  response.context = context
160
160
  response
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Langchain
4
- VERSION = "0.14.0"
4
+ VERSION = "0.15.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: langchainrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-12 00:00:00.000000000 Z
11
+ date: 2024-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: baran
@@ -774,27 +774,17 @@ files:
774
774
  - lib/langchain/prompt/few_shot_prompt_template.rb
775
775
  - lib/langchain/prompt/loading.rb
776
776
  - lib/langchain/prompt/prompt_template.rb
777
- - lib/langchain/tool/base.rb
778
- - lib/langchain/tool/calculator/calculator.json
779
- - lib/langchain/tool/calculator/calculator.rb
780
- - lib/langchain/tool/database/database.json
781
- - lib/langchain/tool/database/database.rb
782
- - lib/langchain/tool/file_system/file_system.json
783
- - lib/langchain/tool/file_system/file_system.rb
784
- - lib/langchain/tool/google_search/google_search.json
785
- - lib/langchain/tool/google_search/google_search.rb
786
- - lib/langchain/tool/news_retriever/news_retriever.json
787
- - lib/langchain/tool/news_retriever/news_retriever.rb
788
- - lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json
789
- - lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb
790
- - lib/langchain/tool/tavily/tavily.json
791
- - lib/langchain/tool/tavily/tavily.rb
792
- - lib/langchain/tool/vectorsearch/vectorsearch.json
793
- - lib/langchain/tool/vectorsearch/vectorsearch.rb
794
- - lib/langchain/tool/weather/weather.json
795
- - lib/langchain/tool/weather/weather.rb
796
- - lib/langchain/tool/wikipedia/wikipedia.json
797
- - lib/langchain/tool/wikipedia/wikipedia.rb
777
+ - lib/langchain/tool/calculator.rb
778
+ - lib/langchain/tool/database.rb
779
+ - lib/langchain/tool/file_system.rb
780
+ - lib/langchain/tool/google_search.rb
781
+ - lib/langchain/tool/news_retriever.rb
782
+ - lib/langchain/tool/ruby_code_interpreter.rb
783
+ - lib/langchain/tool/tavily.rb
784
+ - lib/langchain/tool/vectorsearch.rb
785
+ - lib/langchain/tool/weather.rb
786
+ - lib/langchain/tool/wikipedia.rb
787
+ - lib/langchain/tool_definition.rb
798
788
  - lib/langchain/utils/cosine_similarity.rb
799
789
  - lib/langchain/utils/hash_transformer.rb
800
790
  - lib/langchain/vectorsearch/base.rb
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain::Tool
4
- # = Tools
5
- #
6
- # Tools are used by Agents to perform specific tasks. A 'Tool' is a collection of functions ("methods").
7
- #
8
- # == Available Tools
9
- #
10
- # - {Langchain::Tool::Calculator}: calculate the result of a math expression
11
- # - {Langchain::Tool::Database}: executes SQL queries
12
- # - {Langchain::Tool::FileSystem}: interacts with the file system
13
- # - {Langchain::Tool::GoogleSearch}: search on Google (via SerpAPI)
14
- # - {Langchain::Tool::RubyCodeInterpreter}: runs ruby code
15
- # - {Langchain::Tool::Weather}: gets current weather data
16
- # - {Langchain::Tool::Wikipedia}: search on Wikipedia
17
- #
18
- # == Usage
19
- #
20
- # 1. Pick the tools you'd like to pass to an Agent and install the gems listed under **Gem Requirements**
21
- #
22
- # # For example to use the Calculator, GoogleSearch, and Wikipedia:
23
- # gem install eqn
24
- # gem install google_search_results
25
- # gem install wikipedia-client
26
- #
27
- # 2. Set the environment variables listed under **ENV Requirements**
28
- #
29
- # export SERPAPI_API_KEY=paste-your-serpapi-api-key-here
30
- #
31
- # 3. Pass the tools when Agent is instantiated.
32
- #
33
- # agent = Langchain::Assistant.new(
34
- # llm: Langchain::LLM::OpenAI.new(api_key: "YOUR_API_KEY"), # or other LLM that supports function calling (coming soon)
35
- # thread: Langchain::Thread.new,
36
- # tools: [
37
- # Langchain::Tool::GoogleSearch.new(api_key: "YOUR_API_KEY"),
38
- # Langchain::Tool::Calculator.new,
39
- # Langchain::Tool::Wikipedia.new
40
- # ]
41
- # )
42
- #
43
- # == Adding Tools
44
- #
45
- # 1. Create a new folder in lib/langchain/tool/your_tool_name/
46
- # 2. Inside of this folder create a file with a class YourToolName that inherits from {Langchain::Tool::Base}
47
- # 3. Add `NAME=` and `ANNOTATIONS_PATH=` constants in your Tool class
48
- # 4. Implement various public methods in your tool class
49
- # 5. Create a sidecar .json file in the same directory as your tool file annotating the methods in the Open API format
50
- # 6. Add your tool to the {file:README.md}
51
- class Base
52
- include Langchain::DependencyHelper
53
-
54
- # Returns the NAME constant of the tool
55
- #
56
- # @return [String] tool name
57
- def name
58
- self.class.const_get(:NAME)
59
- end
60
-
61
- def self.logger_options
62
- {
63
- color: :light_blue
64
- }
65
- end
66
-
67
- # Returns the tool as a list of OpenAI formatted functions
68
- #
69
- # @return [Array<Hash>] List of hashes representing the tool as OpenAI formatted functions
70
- def to_openai_tools
71
- method_annotations
72
- end
73
-
74
- # Returns the tool as a list of Anthropic formatted functions
75
- #
76
- # @return [Array<Hash>] List of hashes representing the tool as Anthropic formatted functions
77
- def to_anthropic_tools
78
- method_annotations.map do |annotation|
79
- # Slice out only the content of the "function" key
80
- annotation["function"]
81
- # Rename "parameters" to "input_schema" key
82
- .transform_keys("parameters" => "input_schema")
83
- end
84
- end
85
-
86
- # Returns the tool as a list of Google Gemini formatted functions
87
- #
88
- # @return [Array<Hash>] List of hashes representing the tool as Google Gemini formatted functions
89
- def to_google_gemini_tools
90
- method_annotations.map do |annotation|
91
- # Slice out only the content of the "function" key
92
- annotation["function"]
93
- end
94
- end
95
-
96
- # Return tool's method annotations as JSON
97
- #
98
- # @return [Hash] Tool's method annotations
99
- def method_annotations
100
- JSON.parse(
101
- File.read(
102
- self.class.const_get(:ANNOTATIONS_PATH)
103
- )
104
- )
105
- end
106
- end
107
- end
@@ -1,19 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "calculator__execute",
6
- "description": "Evaluates a pure math expression or if equation contains non-math characters (e.g.: \"12F in Celsius\") then it uses the google search calculator to evaluate the expression",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "input": {
11
- "type": "string",
12
- "description": "math expression"
13
- }
14
- },
15
- "required": ["input"]
16
- }
17
- }
18
- }
19
- ]
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain::Tool
4
- class Calculator < Base
5
- #
6
- # A calculator tool that falls back to the Google calculator widget
7
- #
8
- # Gem requirements:
9
- # gem "eqn", "~> 1.6.5"
10
- # gem "google_search_results", "~> 2.0.0"
11
- #
12
- # Usage:
13
- # calculator = Langchain::Tool::Calculator.new
14
- #
15
- NAME = "calculator"
16
- ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
17
-
18
- def initialize
19
- depends_on "eqn"
20
- end
21
-
22
- # Evaluates a pure math expression or if equation contains non-math characters (e.g.: "12F in Celsius") then it uses the google search calculator to evaluate the expression
23
- #
24
- # @param input [String] math expression
25
- # @return [String] Answer
26
- def execute(input:)
27
- Langchain.logger.info("Executing \"#{input}\"", for: self.class)
28
-
29
- Eqn::Calculator.calc(input)
30
- rescue Eqn::ParseError, Eqn::NoVariableValueError
31
- "\"#{input}\" is an invalid mathematical expression"
32
- end
33
- end
34
- end
@@ -1,46 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "database__describe_tables",
6
- "description": "Database Tool: Returns the schema for a list of tables",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "tables": {
11
- "type": "string",
12
- "description": "The tables to describe."
13
- }
14
- },
15
- "required": ["tables"]
16
- }
17
- }
18
- }, {
19
- "type": "function",
20
- "function": {
21
- "name": "database__list_tables",
22
- "description": "Database Tool: Returns a list of tables in the database",
23
- "parameters": {
24
- "type": "object",
25
- "properties": {},
26
- "required": []
27
- }
28
- }
29
- }, {
30
- "type": "function",
31
- "function": {
32
- "name": "database__execute",
33
- "description": "Database Tool: Executes a SQL query and returns the results",
34
- "parameters": {
35
- "type": "object",
36
- "properties": {
37
- "input": {
38
- "type": "string",
39
- "description": "SQL query to be executed"
40
- }
41
- },
42
- "required": ["input"]
43
- }
44
- }
45
- }
46
- ]
@@ -1,57 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "file_system__list_directory",
6
- "description": "File System Tool: Lists out the content of a specified directory",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "directory_path": {
11
- "type": "string",
12
- "description": "Directory path to list"
13
- }
14
- },
15
- "required": ["directory_path"]
16
- }
17
- }
18
- },
19
- {
20
- "type": "function",
21
- "function": {
22
- "name": "file_system__read_file",
23
- "description": "File System Tool: Reads the contents of a file",
24
- "parameters": {
25
- "type": "object",
26
- "properties": {
27
- "file_path": {
28
- "type": "string",
29
- "description": "Path to the file to read from"
30
- }
31
- },
32
- "required": ["file_path"]
33
- }
34
- }
35
- },
36
- {
37
- "type": "function",
38
- "function": {
39
- "name": "file_system__write_to_file",
40
- "description": "File System Tool: Write content to a file",
41
- "parameters": {
42
- "type": "object",
43
- "properties": {
44
- "file_path": {
45
- "type": "string",
46
- "description": "Path to the file to write"
47
- },
48
- "content": {
49
- "type": "string",
50
- "description": "Content to write to the file"
51
- }
52
- },
53
- "required": ["file_path", "content"]
54
- }
55
- }
56
- }
57
- ]
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain::Tool
4
- class FileSystem < Base
5
- #
6
- # A tool that wraps the Ruby file system classes.
7
- #
8
- # Usage:
9
- # file_system = Langchain::Tool::FileSystem.new
10
- #
11
- NAME = "file_system"
12
- ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
13
-
14
- def list_directory(directory_path:)
15
- Dir.entries(directory_path)
16
- rescue Errno::ENOENT
17
- "No such directory: #{directory_path}"
18
- end
19
-
20
- def read_file(file_path:)
21
- File.read(file_path)
22
- rescue Errno::ENOENT
23
- "No such file: #{file_path}"
24
- end
25
-
26
- def write_to_file(file_path:, content:)
27
- File.write(file_path, content)
28
- rescue Errno::EACCES
29
- "Permission denied: #{file_path}"
30
- end
31
- end
32
- end
@@ -1,19 +0,0 @@
1
- [
2
- {
3
- "type": "function",
4
- "function": {
5
- "name": "google_search-execute",
6
- "description": "Executes Google Search and returns the result",
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
- ]