langchainrb 0.13.5 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +2 -17
- data/lib/langchain/assistants/assistant.rb +207 -92
- data/lib/langchain/assistants/messages/ollama_message.rb +74 -0
- data/lib/langchain/assistants/thread.rb +8 -1
- data/lib/langchain/contextual_logger.rb +2 -2
- data/lib/langchain/llm/ai21.rb +0 -4
- data/lib/langchain/llm/anthropic.rb +15 -6
- data/lib/langchain/llm/azure.rb +3 -3
- data/lib/langchain/llm/base.rb +1 -0
- data/lib/langchain/llm/cohere.rb +0 -2
- data/lib/langchain/llm/google_gemini.rb +1 -1
- data/lib/langchain/llm/google_palm.rb +1 -4
- data/lib/langchain/llm/ollama.rb +24 -18
- data/lib/langchain/llm/openai.rb +1 -1
- data/lib/langchain/llm/response/google_gemini_response.rb +1 -1
- data/lib/langchain/llm/response/ollama_response.rb +5 -1
- data/lib/langchain/llm/unified_parameters.rb +2 -2
- data/lib/langchain/tool/calculator.rb +38 -0
- data/lib/langchain/tool/{database/database.rb → database.rb} +24 -12
- data/lib/langchain/tool/file_system.rb +44 -0
- data/lib/langchain/tool/{google_search/google_search.rb → google_search.rb} +17 -23
- data/lib/langchain/tool/{news_retriever/news_retriever.rb → news_retriever.rb} +41 -14
- data/lib/langchain/tool/ruby_code_interpreter.rb +41 -0
- data/lib/langchain/tool/{tavily/tavily.rb → tavily.rb} +24 -10
- data/lib/langchain/tool/vectorsearch.rb +40 -0
- data/lib/langchain/tool/{weather/weather.rb → weather.rb} +21 -17
- data/lib/langchain/tool/{wikipedia/wikipedia.rb → wikipedia.rb} +17 -13
- data/lib/langchain/tool_definition.rb +212 -0
- data/lib/langchain/utils/hash_transformer.rb +9 -17
- data/lib/langchain/vectorsearch/chroma.rb +2 -2
- data/lib/langchain/vectorsearch/elasticsearch.rb +2 -2
- data/lib/langchain/vectorsearch/epsilla.rb +3 -3
- data/lib/langchain/vectorsearch/milvus.rb +3 -3
- data/lib/langchain/vectorsearch/pgvector.rb +2 -2
- data/lib/langchain/vectorsearch/pinecone.rb +2 -2
- data/lib/langchain/vectorsearch/qdrant.rb +2 -2
- data/lib/langchain/vectorsearch/weaviate.rb +4 -4
- data/lib/langchain/version.rb +1 -1
- metadata +16 -45
- data/lib/langchain/tool/base.rb +0 -107
- data/lib/langchain/tool/calculator/calculator.json +0 -19
- data/lib/langchain/tool/calculator/calculator.rb +0 -34
- data/lib/langchain/tool/database/database.json +0 -46
- data/lib/langchain/tool/file_system/file_system.json +0 -57
- data/lib/langchain/tool/file_system/file_system.rb +0 -32
- data/lib/langchain/tool/google_search/google_search.json +0 -19
- data/lib/langchain/tool/news_retriever/news_retriever.json +0 -122
- data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json +0 -19
- data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb +0 -37
- data/lib/langchain/tool/tavily/tavily.json +0 -54
- data/lib/langchain/tool/vectorsearch/vectorsearch.json +0 -24
- data/lib/langchain/tool/vectorsearch/vectorsearch.rb +0 -36
- data/lib/langchain/tool/weather/weather.json +0 -19
- data/lib/langchain/tool/wikipedia/wikipedia.json +0 -19
- data/lib/langchain/utils/token_length/ai21_validator.rb +0 -41
- data/lib/langchain/utils/token_length/base_validator.rb +0 -42
- data/lib/langchain/utils/token_length/cohere_validator.rb +0 -49
- data/lib/langchain/utils/token_length/google_palm_validator.rb +0 -57
- data/lib/langchain/utils/token_length/openai_validator.rb +0 -138
- data/lib/langchain/utils/token_length/token_limit_exceeded.rb +0 -17
data/lib/langchain/tool/base.rb
DELETED
@@ -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
|
-
]
|
@@ -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
|
-
]
|