langchainrb 0.14.0 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -2
  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 +11 -5
  6. data/lib/langchain/evals/ragas/faithfulness.rb +5 -1
  7. data/lib/langchain/llm/google_gemini.rb +1 -1
  8. data/lib/langchain/llm/ollama.rb +23 -17
  9. data/lib/langchain/llm/openai.rb +1 -1
  10. data/lib/langchain/llm/response/ollama_response.rb +1 -15
  11. data/lib/langchain/llm/unified_parameters.rb +2 -2
  12. data/lib/langchain/tool/calculator.rb +38 -0
  13. data/lib/langchain/tool/{database/database.rb → database.rb} +24 -12
  14. data/lib/langchain/tool/file_system.rb +44 -0
  15. data/lib/langchain/tool/{google_search/google_search.rb → google_search.rb} +17 -23
  16. data/lib/langchain/tool/{news_retriever/news_retriever.rb → news_retriever.rb} +41 -14
  17. data/lib/langchain/tool/ruby_code_interpreter.rb +41 -0
  18. data/lib/langchain/tool/{tavily/tavily.rb → tavily.rb} +24 -10
  19. data/lib/langchain/tool/vectorsearch.rb +40 -0
  20. data/lib/langchain/tool/weather.rb +109 -0
  21. data/lib/langchain/tool/{wikipedia/wikipedia.rb → wikipedia.rb} +17 -13
  22. data/lib/langchain/tool_definition.rb +212 -0
  23. data/lib/langchain/utils/colorizer.rb +19 -0
  24. data/lib/langchain/utils/hash_transformer.rb +9 -17
  25. data/lib/langchain/utils/to_boolean.rb +27 -0
  26. data/lib/langchain/vectorsearch/chroma.rb +2 -2
  27. data/lib/langchain/vectorsearch/elasticsearch.rb +2 -2
  28. data/lib/langchain/vectorsearch/epsilla.rb +3 -3
  29. data/lib/langchain/vectorsearch/milvus.rb +2 -2
  30. data/lib/langchain/vectorsearch/pgvector.rb +2 -2
  31. data/lib/langchain/vectorsearch/pinecone.rb +2 -2
  32. data/lib/langchain/vectorsearch/qdrant.rb +2 -2
  33. data/lib/langchain/vectorsearch/weaviate.rb +4 -4
  34. data/lib/langchain/version.rb +1 -1
  35. data/lib/langchain.rb +1 -2
  36. metadata +18 -54
  37. data/lib/langchain/tool/base.rb +0 -107
  38. data/lib/langchain/tool/calculator/calculator.json +0 -19
  39. data/lib/langchain/tool/calculator/calculator.rb +0 -34
  40. data/lib/langchain/tool/database/database.json +0 -46
  41. data/lib/langchain/tool/file_system/file_system.json +0 -57
  42. data/lib/langchain/tool/file_system/file_system.rb +0 -32
  43. data/lib/langchain/tool/google_search/google_search.json +0 -19
  44. data/lib/langchain/tool/news_retriever/news_retriever.json +0 -122
  45. data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json +0 -19
  46. data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb +0 -37
  47. data/lib/langchain/tool/tavily/tavily.json +0 -54
  48. data/lib/langchain/tool/vectorsearch/vectorsearch.json +0 -24
  49. data/lib/langchain/tool/vectorsearch/vectorsearch.rb +0 -36
  50. data/lib/langchain/tool/weather/weather.json +0 -19
  51. data/lib/langchain/tool/weather/weather.rb +0 -55
  52. data/lib/langchain/tool/wikipedia/wikipedia.json +0 -19
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Langchain::Tool
4
- class Weather < Base
5
- #
6
- # A weather tool that gets current weather data
7
- #
8
- # Current weather data is free for 1000 calls per day (https://home.openweathermap.org/api_keys)
9
- # Forecast and historical data require registration with credit card, so not supported yet.
10
- #
11
- # Gem requirements:
12
- # gem "open-weather-ruby-client", "~> 0.3.0"
13
- # api_key: https://home.openweathermap.org/api_keys
14
- #
15
- # Usage:
16
- # weather = Langchain::Tool::Weather.new(api_key: ENV["OPEN_WEATHER_API_KEY"])
17
- # weather.execute(input: "Boston, MA; imperial")
18
- #
19
- NAME = "weather"
20
- ANNOTATIONS_PATH = Langchain.root.join("./langchain/tool/#{NAME}/#{NAME}.json").to_path
21
-
22
- attr_reader :client, :units
23
-
24
- # Initializes the Weather tool
25
- #
26
- # @param api_key [String] Open Weather API key
27
- # @return [Langchain::Tool::Weather] Weather tool
28
- def initialize(api_key:, units: "metric")
29
- depends_on "open-weather-ruby-client"
30
- require "open-weather-ruby-client"
31
-
32
- OpenWeather::Client.configure do |config|
33
- config.api_key = api_key
34
- config.user_agent = "Langchainrb Ruby Client"
35
- end
36
-
37
- @client = OpenWeather::Client.new
38
- end
39
-
40
- # Returns current weather for a city
41
- #
42
- # @param input [String] comma separated city and unit (optional: imperial, metric, or standard)
43
- # @return [String] Answer
44
- def execute(input:)
45
- Langchain.logger.info("Executing for \"#{input}\"", for: self.class)
46
-
47
- input_array = input.split(";")
48
- city, units = *input_array.map(&:strip)
49
-
50
- data = client.current_weather(city: city, units: units)
51
- weather = data.main.map { |key, value| "#{key} #{value}" }.join(", ")
52
- "The current weather in #{data.name} is #{weather}"
53
- end
54
- end
55
- end
@@ -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
- ]