langchainrb 0.5.4 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +1 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +10 -1
- data/README.md +8 -5
- data/examples/store_and_query_with_pinecone.rb +5 -4
- data/lib/langchain/agent/base.rb +5 -0
- data/lib/langchain/agent/chain_of_thought_agent/chain_of_thought_agent.rb +22 -10
- data/lib/langchain/agent/chain_of_thought_agent/chain_of_thought_agent_prompt.yaml +26 -0
- data/lib/langchain/agent/sql_query_agent/sql_query_agent.rb +7 -7
- data/lib/langchain/agent/sql_query_agent/sql_query_agent_answer_prompt.yaml +11 -0
- data/lib/langchain/agent/sql_query_agent/sql_query_agent_sql_prompt.yaml +21 -0
- data/lib/langchain/chunker/base.rb +15 -0
- data/lib/langchain/chunker/text.rb +38 -0
- data/lib/langchain/contextual_logger.rb +60 -0
- data/lib/langchain/conversation.rb +97 -0
- data/lib/langchain/data.rb +4 -0
- data/lib/langchain/llm/google_palm.rb +3 -2
- data/lib/langchain/llm/openai.rb +16 -6
- data/lib/langchain/llm/prompts/summarize_template.yaml +9 -0
- data/lib/langchain/llm/replicate.rb +1 -1
- data/lib/langchain/prompt/base.rb +2 -2
- data/lib/langchain/tool/base.rb +9 -3
- data/lib/langchain/tool/calculator.rb +2 -2
- data/lib/langchain/tool/database.rb +3 -3
- data/lib/langchain/tool/{serp_api.rb → google_search.rb} +9 -9
- data/lib/langchain/tool/ruby_code_interpreter.rb +1 -1
- data/lib/langchain/tool/weather.rb +67 -0
- data/lib/langchain/tool/wikipedia.rb +1 -1
- data/lib/langchain/utils/token_length/base_validator.rb +38 -0
- data/lib/langchain/utils/token_length/google_palm_validator.rb +9 -29
- data/lib/langchain/utils/token_length/openai_validator.rb +10 -27
- data/lib/langchain/utils/token_length/token_limit_exceeded.rb +17 -0
- data/lib/langchain/vectorsearch/base.rb +6 -0
- data/lib/langchain/vectorsearch/hnswlib.rb +2 -2
- data/lib/langchain/version.rb +1 -1
- data/lib/langchain.rb +29 -12
- metadata +46 -11
- data/lib/langchain/agent/chain_of_thought_agent/chain_of_thought_agent_prompt.json +0 -10
- data/lib/langchain/agent/sql_query_agent/sql_query_agent_answer_prompt.json +0 -10
- data/lib/langchain/agent/sql_query_agent/sql_query_agent_sql_prompt.json +0 -10
- data/lib/langchain/chat.rb +0 -50
- data/lib/langchain/llm/prompts/summarize_template.json +0 -5
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: langchainrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Bondarev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: baran
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.1.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.1.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: colorize
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tiktoken_ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.5
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.5
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: dotenv-rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -248,6 +262,20 @@ dependencies:
|
|
248
262
|
- - "~>"
|
249
263
|
- !ruby/object:Gem::Version
|
250
264
|
version: '1.13'
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: open-weather-ruby-client
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - "~>"
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: 0.3.0
|
272
|
+
type: :development
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - "~>"
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: 0.3.0
|
251
279
|
- !ruby/object:Gem::Dependency
|
252
280
|
name: pg
|
253
281
|
requirement: !ruby/object:Gem::Requirement
|
@@ -442,11 +470,14 @@ files:
|
|
442
470
|
- lib/langchain.rb
|
443
471
|
- lib/langchain/agent/base.rb
|
444
472
|
- lib/langchain/agent/chain_of_thought_agent/chain_of_thought_agent.rb
|
445
|
-
- lib/langchain/agent/chain_of_thought_agent/chain_of_thought_agent_prompt.
|
473
|
+
- lib/langchain/agent/chain_of_thought_agent/chain_of_thought_agent_prompt.yaml
|
446
474
|
- lib/langchain/agent/sql_query_agent/sql_query_agent.rb
|
447
|
-
- lib/langchain/agent/sql_query_agent/sql_query_agent_answer_prompt.
|
448
|
-
- lib/langchain/agent/sql_query_agent/sql_query_agent_sql_prompt.
|
449
|
-
- lib/langchain/
|
475
|
+
- lib/langchain/agent/sql_query_agent/sql_query_agent_answer_prompt.yaml
|
476
|
+
- lib/langchain/agent/sql_query_agent/sql_query_agent_sql_prompt.yaml
|
477
|
+
- lib/langchain/chunker/base.rb
|
478
|
+
- lib/langchain/chunker/text.rb
|
479
|
+
- lib/langchain/contextual_logger.rb
|
480
|
+
- lib/langchain/conversation.rb
|
450
481
|
- lib/langchain/data.rb
|
451
482
|
- lib/langchain/dependency_helper.rb
|
452
483
|
- lib/langchain/llm/ai21.rb
|
@@ -455,7 +486,7 @@ files:
|
|
455
486
|
- lib/langchain/llm/google_palm.rb
|
456
487
|
- lib/langchain/llm/hugging_face.rb
|
457
488
|
- lib/langchain/llm/openai.rb
|
458
|
-
- lib/langchain/llm/prompts/summarize_template.
|
489
|
+
- lib/langchain/llm/prompts/summarize_template.yaml
|
459
490
|
- lib/langchain/llm/replicate.rb
|
460
491
|
- lib/langchain/loader.rb
|
461
492
|
- lib/langchain/processors/base.rb
|
@@ -474,11 +505,14 @@ files:
|
|
474
505
|
- lib/langchain/tool/base.rb
|
475
506
|
- lib/langchain/tool/calculator.rb
|
476
507
|
- lib/langchain/tool/database.rb
|
508
|
+
- lib/langchain/tool/google_search.rb
|
477
509
|
- lib/langchain/tool/ruby_code_interpreter.rb
|
478
|
-
- lib/langchain/tool/
|
510
|
+
- lib/langchain/tool/weather.rb
|
479
511
|
- lib/langchain/tool/wikipedia.rb
|
512
|
+
- lib/langchain/utils/token_length/base_validator.rb
|
480
513
|
- lib/langchain/utils/token_length/google_palm_validator.rb
|
481
514
|
- lib/langchain/utils/token_length/openai_validator.rb
|
515
|
+
- lib/langchain/utils/token_length/token_limit_exceeded.rb
|
482
516
|
- lib/langchain/vectorsearch/base.rb
|
483
517
|
- lib/langchain/vectorsearch/chroma.rb
|
484
518
|
- lib/langchain/vectorsearch/hnswlib.rb
|
@@ -497,6 +531,7 @@ metadata:
|
|
497
531
|
homepage_uri: https://rubygems.org/gems/langchainrb
|
498
532
|
source_code_uri: https://github.com/andreibondarev/langchainrb
|
499
533
|
changelog_uri: https://github.com/andreibondarev/langchainrb/CHANGELOG.md
|
534
|
+
documentation_uri: https://rubydoc.info/gems/langchainrb
|
500
535
|
post_install_message:
|
501
536
|
rdoc_options: []
|
502
537
|
require_paths:
|
@@ -1,10 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"_type": "prompt",
|
3
|
-
"template": "Today is {date} and you can use tools to get new information. Answer the following questions as best you can using the following tools:\n\n{tools}\n\nUse the following format:\n\nQuestion: the input question you must answer\nThought: you should always think about what to do\nAction: the action to take, should be one of {tool_names}\nAction Input: the input to the action\nObservation: the result of the action\n... (this Thought/Action/Action Input/Observation can repeat N times)\nThought: I now know the final answer\nFinal Answer: the final answer to the original input question\n\nBegin!\n\nQuestion: {question}\nThought:",
|
4
|
-
"input_variables": [
|
5
|
-
"date",
|
6
|
-
"question",
|
7
|
-
"tools",
|
8
|
-
"tool_names"
|
9
|
-
]
|
10
|
-
}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"_type": "prompt",
|
3
|
-
"template":
|
4
|
-
"Given an input question and results of a SQL query, look at the results and return the answer. Use the following format:\nQuestion: {question}\nThe SQL query: {sql_query}\nResult of the SQLQuery: {results}\nFinal answer: Final answer here",
|
5
|
-
"input_variables": [
|
6
|
-
"question",
|
7
|
-
"sql_query",
|
8
|
-
"results"
|
9
|
-
]
|
10
|
-
}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"_type": "prompt",
|
3
|
-
"template":
|
4
|
-
"Given an input question, create a syntactically correct {dialect} query to run, then return the query in valid SQL.\nNever query for all the columns from a specific table, only ask for a the few relevant columns given the question.\nPay attention to use only the column names that you can see in the schema description. Be careful to not query for columns that do not exist. Pay attention to which column is in which table. Also, qualify column names with the table name when needed.\nOnly use the tables listed below.\n{schema}\nUse the following format:\nQuestion: {question}\nSQLQuery:",
|
5
|
-
"input_variables": [
|
6
|
-
"dialect",
|
7
|
-
"schema",
|
8
|
-
"question"
|
9
|
-
]
|
10
|
-
}
|
data/lib/langchain/chat.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Langchain
|
4
|
-
class Chat
|
5
|
-
attr_reader :context
|
6
|
-
|
7
|
-
def initialize(llm:, **options)
|
8
|
-
@llm = llm
|
9
|
-
@context = nil
|
10
|
-
@examples = []
|
11
|
-
@messages = []
|
12
|
-
end
|
13
|
-
|
14
|
-
# Set the context of the conversation. Usually used to set the model's persona.
|
15
|
-
# @param message [String] The context of the conversation
|
16
|
-
def set_context(message)
|
17
|
-
@context = message
|
18
|
-
end
|
19
|
-
|
20
|
-
# Add examples to the conversation. Used to give the model a sense of the conversation.
|
21
|
-
# @param examples [Array<Hash>] The examples to add to the conversation
|
22
|
-
def add_examples(examples)
|
23
|
-
@examples.concat examples
|
24
|
-
end
|
25
|
-
|
26
|
-
# Message the model with a prompt and return the response.
|
27
|
-
# @param message [String] The prompt to message the model with
|
28
|
-
# @return [String] The response from the model
|
29
|
-
def message(message)
|
30
|
-
append_user_message(message)
|
31
|
-
response = llm_response(message)
|
32
|
-
append_ai_message(response)
|
33
|
-
response
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def llm_response(prompt)
|
39
|
-
@llm.chat(messages: @messages, context: @context, examples: @examples)
|
40
|
-
end
|
41
|
-
|
42
|
-
def append_ai_message(message)
|
43
|
-
@messages << {role: "ai", content: message}
|
44
|
-
end
|
45
|
-
|
46
|
-
def append_user_message(message)
|
47
|
-
@messages << {role: "user", content: message}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|