langchainrb 0.7.5 → 0.12.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 +78 -0
- data/README.md +113 -56
- data/lib/langchain/assistants/assistant.rb +213 -0
- data/lib/langchain/assistants/message.rb +58 -0
- data/lib/langchain/assistants/thread.rb +34 -0
- data/lib/langchain/chunker/markdown.rb +37 -0
- data/lib/langchain/chunker/recursive_text.rb +0 -2
- data/lib/langchain/chunker/semantic.rb +1 -3
- data/lib/langchain/chunker/sentence.rb +0 -2
- data/lib/langchain/chunker/text.rb +0 -2
- data/lib/langchain/contextual_logger.rb +1 -1
- data/lib/langchain/data.rb +4 -3
- data/lib/langchain/llm/ai21.rb +1 -1
- data/lib/langchain/llm/anthropic.rb +86 -11
- data/lib/langchain/llm/aws_bedrock.rb +52 -0
- data/lib/langchain/llm/azure.rb +10 -97
- data/lib/langchain/llm/base.rb +3 -2
- data/lib/langchain/llm/cohere.rb +5 -7
- data/lib/langchain/llm/google_palm.rb +4 -2
- data/lib/langchain/llm/google_vertex_ai.rb +151 -0
- data/lib/langchain/llm/hugging_face.rb +1 -1
- data/lib/langchain/llm/llama_cpp.rb +18 -16
- data/lib/langchain/llm/mistral_ai.rb +68 -0
- data/lib/langchain/llm/ollama.rb +209 -27
- data/lib/langchain/llm/openai.rb +138 -170
- data/lib/langchain/llm/prompts/ollama/summarize_template.yaml +9 -0
- data/lib/langchain/llm/replicate.rb +1 -7
- data/lib/langchain/llm/response/anthropic_response.rb +20 -0
- data/lib/langchain/llm/response/base_response.rb +7 -0
- data/lib/langchain/llm/response/google_palm_response.rb +4 -0
- data/lib/langchain/llm/response/google_vertex_ai_response.rb +33 -0
- data/lib/langchain/llm/response/llama_cpp_response.rb +13 -0
- data/lib/langchain/llm/response/mistral_ai_response.rb +39 -0
- data/lib/langchain/llm/response/ollama_response.rb +27 -1
- data/lib/langchain/llm/response/openai_response.rb +8 -0
- data/lib/langchain/loader.rb +3 -2
- data/lib/langchain/output_parsers/base.rb +0 -4
- data/lib/langchain/output_parsers/output_fixing_parser.rb +7 -14
- data/lib/langchain/output_parsers/structured_output_parser.rb +0 -10
- data/lib/langchain/processors/csv.rb +37 -3
- data/lib/langchain/processors/eml.rb +64 -0
- data/lib/langchain/processors/markdown.rb +17 -0
- data/lib/langchain/processors/pptx.rb +29 -0
- data/lib/langchain/prompt/loading.rb +1 -1
- data/lib/langchain/tool/base.rb +21 -53
- data/lib/langchain/tool/calculator/calculator.json +19 -0
- data/lib/langchain/tool/{calculator.rb → calculator/calculator.rb} +8 -16
- data/lib/langchain/tool/database/database.json +46 -0
- data/lib/langchain/tool/database/database.rb +99 -0
- data/lib/langchain/tool/file_system/file_system.json +57 -0
- data/lib/langchain/tool/file_system/file_system.rb +32 -0
- data/lib/langchain/tool/google_search/google_search.json +19 -0
- data/lib/langchain/tool/{google_search.rb → google_search/google_search.rb} +5 -15
- data/lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json +19 -0
- data/lib/langchain/tool/{ruby_code_interpreter.rb → ruby_code_interpreter/ruby_code_interpreter.rb} +8 -4
- data/lib/langchain/tool/vectorsearch/vectorsearch.json +24 -0
- data/lib/langchain/tool/vectorsearch/vectorsearch.rb +36 -0
- data/lib/langchain/tool/weather/weather.json +19 -0
- data/lib/langchain/tool/{weather.rb → weather/weather.rb} +3 -15
- data/lib/langchain/tool/wikipedia/wikipedia.json +19 -0
- data/lib/langchain/tool/{wikipedia.rb → wikipedia/wikipedia.rb} +9 -9
- data/lib/langchain/utils/token_length/ai21_validator.rb +6 -2
- data/lib/langchain/utils/token_length/base_validator.rb +1 -1
- data/lib/langchain/utils/token_length/cohere_validator.rb +6 -2
- data/lib/langchain/utils/token_length/google_palm_validator.rb +5 -1
- data/lib/langchain/utils/token_length/openai_validator.rb +55 -1
- data/lib/langchain/utils/token_length/token_limit_exceeded.rb +1 -1
- data/lib/langchain/vectorsearch/base.rb +11 -4
- data/lib/langchain/vectorsearch/chroma.rb +10 -1
- data/lib/langchain/vectorsearch/elasticsearch.rb +53 -4
- data/lib/langchain/vectorsearch/epsilla.rb +149 -0
- data/lib/langchain/vectorsearch/hnswlib.rb +5 -1
- data/lib/langchain/vectorsearch/milvus.rb +4 -2
- data/lib/langchain/vectorsearch/pgvector.rb +14 -4
- data/lib/langchain/vectorsearch/pinecone.rb +8 -5
- data/lib/langchain/vectorsearch/qdrant.rb +16 -4
- data/lib/langchain/vectorsearch/weaviate.rb +20 -2
- data/lib/langchain/version.rb +1 -1
- data/lib/langchain.rb +20 -5
- metadata +182 -45
- data/lib/langchain/agent/agents.md +0 -54
- data/lib/langchain/agent/base.rb +0 -20
- data/lib/langchain/agent/react_agent/react_agent_prompt.yaml +0 -26
- data/lib/langchain/agent/react_agent.rb +0 -131
- data/lib/langchain/agent/sql_query_agent/sql_query_agent_answer_prompt.yaml +0 -11
- data/lib/langchain/agent/sql_query_agent/sql_query_agent_sql_prompt.yaml +0 -21
- data/lib/langchain/agent/sql_query_agent.rb +0 -82
- data/lib/langchain/conversation/context.rb +0 -8
- data/lib/langchain/conversation/memory.rb +0 -86
- data/lib/langchain/conversation/message.rb +0 -48
- data/lib/langchain/conversation/prompt.rb +0 -8
- data/lib/langchain/conversation/response.rb +0 -8
- data/lib/langchain/conversation.rb +0 -93
- data/lib/langchain/tool/database.rb +0 -90
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: langchainrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.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:
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.0.8
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: baran
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,42 +44,42 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 1.1.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 1.1.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: tiktoken_ruby
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0.
|
61
|
+
version: 0.0.8
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0.
|
68
|
+
version: 0.0.8
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: json-schema
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: 4
|
75
|
+
version: '4'
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: 4
|
82
|
+
version: '4'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: zeitwerk
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,6 +192,34 @@ dependencies:
|
|
178
192
|
- - "~>"
|
179
193
|
- !ruby/object:Gem::Version
|
180
194
|
version: 2.2.7
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: vcr
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: webmock
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
181
223
|
- !ruby/object:Gem::Dependency
|
182
224
|
name: ai21
|
183
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -196,16 +238,16 @@ dependencies:
|
|
196
238
|
name: anthropic
|
197
239
|
requirement: !ruby/object:Gem::Requirement
|
198
240
|
requirements:
|
199
|
-
- - "
|
241
|
+
- - ">="
|
200
242
|
- !ruby/object:Gem::Version
|
201
|
-
version: 0
|
243
|
+
version: '0'
|
202
244
|
type: :development
|
203
245
|
prerelease: false
|
204
246
|
version_requirements: !ruby/object:Gem::Requirement
|
205
247
|
requirements:
|
206
|
-
- - "
|
248
|
+
- - ">="
|
207
249
|
- !ruby/object:Gem::Version
|
208
|
-
version: 0
|
250
|
+
version: '0'
|
209
251
|
- !ruby/object:Gem::Dependency
|
210
252
|
name: aws-sdk-bedrockruntime
|
211
253
|
requirement: !ruby/object:Gem::Requirement
|
@@ -240,14 +282,14 @@ dependencies:
|
|
240
282
|
requirements:
|
241
283
|
- - "~>"
|
242
284
|
- !ruby/object:Gem::Version
|
243
|
-
version: 0.9.
|
285
|
+
version: 0.9.8
|
244
286
|
type: :development
|
245
287
|
prerelease: false
|
246
288
|
version_requirements: !ruby/object:Gem::Requirement
|
247
289
|
requirements:
|
248
290
|
- - "~>"
|
249
291
|
- !ruby/object:Gem::Version
|
250
|
-
version: 0.9.
|
292
|
+
version: 0.9.8
|
251
293
|
- !ruby/object:Gem::Dependency
|
252
294
|
name: docx
|
253
295
|
requirement: !ruby/object:Gem::Requirement
|
@@ -276,6 +318,20 @@ dependencies:
|
|
276
318
|
- - "~>"
|
277
319
|
- !ruby/object:Gem::Version
|
278
320
|
version: 8.2.0
|
321
|
+
- !ruby/object:Gem::Dependency
|
322
|
+
name: epsilla-ruby
|
323
|
+
requirement: !ruby/object:Gem::Requirement
|
324
|
+
requirements:
|
325
|
+
- - "~>"
|
326
|
+
- !ruby/object:Gem::Version
|
327
|
+
version: 0.0.4
|
328
|
+
type: :development
|
329
|
+
prerelease: false
|
330
|
+
version_requirements: !ruby/object:Gem::Requirement
|
331
|
+
requirements:
|
332
|
+
- - "~>"
|
333
|
+
- !ruby/object:Gem::Version
|
334
|
+
version: 0.0.4
|
279
335
|
- !ruby/object:Gem::Dependency
|
280
336
|
name: eqn
|
281
337
|
requirement: !ruby/object:Gem::Requirement
|
@@ -290,6 +346,20 @@ dependencies:
|
|
290
346
|
- - "~>"
|
291
347
|
- !ruby/object:Gem::Version
|
292
348
|
version: 1.6.5
|
349
|
+
- !ruby/object:Gem::Dependency
|
350
|
+
name: google-apis-aiplatform_v1
|
351
|
+
requirement: !ruby/object:Gem::Requirement
|
352
|
+
requirements:
|
353
|
+
- - "~>"
|
354
|
+
- !ruby/object:Gem::Version
|
355
|
+
version: '0.7'
|
356
|
+
type: :development
|
357
|
+
prerelease: false
|
358
|
+
version_requirements: !ruby/object:Gem::Requirement
|
359
|
+
requirements:
|
360
|
+
- - "~>"
|
361
|
+
- !ruby/object:Gem::Version
|
362
|
+
version: '0.7'
|
293
363
|
- !ruby/object:Gem::Dependency
|
294
364
|
name: google_palm_api
|
295
365
|
requirement: !ruby/object:Gem::Requirement
|
@@ -366,14 +436,14 @@ dependencies:
|
|
366
436
|
requirements:
|
367
437
|
- - "~>"
|
368
438
|
- !ruby/object:Gem::Version
|
369
|
-
version: 0.
|
439
|
+
version: 0.9.4
|
370
440
|
type: :development
|
371
441
|
prerelease: false
|
372
442
|
version_requirements: !ruby/object:Gem::Requirement
|
373
443
|
requirements:
|
374
444
|
- - "~>"
|
375
445
|
- !ruby/object:Gem::Version
|
376
|
-
version: 0.
|
446
|
+
version: 0.9.4
|
377
447
|
- !ruby/object:Gem::Dependency
|
378
448
|
name: nokogiri
|
379
449
|
requirement: !ruby/object:Gem::Requirement
|
@@ -388,6 +458,34 @@ dependencies:
|
|
388
458
|
- - "~>"
|
389
459
|
- !ruby/object:Gem::Version
|
390
460
|
version: '1.13'
|
461
|
+
- !ruby/object:Gem::Dependency
|
462
|
+
name: mail
|
463
|
+
requirement: !ruby/object:Gem::Requirement
|
464
|
+
requirements:
|
465
|
+
- - "~>"
|
466
|
+
- !ruby/object:Gem::Version
|
467
|
+
version: '2.8'
|
468
|
+
type: :development
|
469
|
+
prerelease: false
|
470
|
+
version_requirements: !ruby/object:Gem::Requirement
|
471
|
+
requirements:
|
472
|
+
- - "~>"
|
473
|
+
- !ruby/object:Gem::Version
|
474
|
+
version: '2.8'
|
475
|
+
- !ruby/object:Gem::Dependency
|
476
|
+
name: mistral-ai
|
477
|
+
requirement: !ruby/object:Gem::Requirement
|
478
|
+
requirements:
|
479
|
+
- - ">="
|
480
|
+
- !ruby/object:Gem::Version
|
481
|
+
version: '0'
|
482
|
+
type: :development
|
483
|
+
prerelease: false
|
484
|
+
version_requirements: !ruby/object:Gem::Requirement
|
485
|
+
requirements:
|
486
|
+
- - ">="
|
487
|
+
- !ruby/object:Gem::Version
|
488
|
+
version: '0'
|
391
489
|
- !ruby/object:Gem::Dependency
|
392
490
|
name: open-weather-ruby-client
|
393
491
|
requirement: !ruby/object:Gem::Requirement
|
@@ -436,14 +534,14 @@ dependencies:
|
|
436
534
|
requirements:
|
437
535
|
- - "~>"
|
438
536
|
- !ruby/object:Gem::Version
|
439
|
-
version: '
|
537
|
+
version: '2.0'
|
440
538
|
type: :development
|
441
539
|
prerelease: false
|
442
540
|
version_requirements: !ruby/object:Gem::Requirement
|
443
541
|
requirements:
|
444
542
|
- - "~>"
|
445
543
|
- !ruby/object:Gem::Version
|
446
|
-
version: '
|
544
|
+
version: '2.0'
|
447
545
|
- !ruby/object:Gem::Dependency
|
448
546
|
name: pinecone
|
449
547
|
requirement: !ruby/object:Gem::Requirement
|
@@ -506,14 +604,14 @@ dependencies:
|
|
506
604
|
requirements:
|
507
605
|
- - "~>"
|
508
606
|
- !ruby/object:Gem::Version
|
509
|
-
version:
|
607
|
+
version: 6.4.0
|
510
608
|
type: :development
|
511
609
|
prerelease: false
|
512
610
|
version_requirements: !ruby/object:Gem::Requirement
|
513
611
|
requirements:
|
514
612
|
- - "~>"
|
515
613
|
- !ruby/object:Gem::Version
|
516
|
-
version:
|
614
|
+
version: 6.4.0
|
517
615
|
- !ruby/object:Gem::Dependency
|
518
616
|
name: safe_ruby
|
519
617
|
requirement: !ruby/object:Gem::Requirement
|
@@ -548,14 +646,14 @@ dependencies:
|
|
548
646
|
requirements:
|
549
647
|
- - "~>"
|
550
648
|
- !ruby/object:Gem::Version
|
551
|
-
version: 0.8.
|
649
|
+
version: 0.8.10
|
552
650
|
type: :development
|
553
651
|
prerelease: false
|
554
652
|
version_requirements: !ruby/object:Gem::Requirement
|
555
653
|
requirements:
|
556
654
|
- - "~>"
|
557
655
|
- !ruby/object:Gem::Version
|
558
|
-
version: 0.8.
|
656
|
+
version: 0.8.10
|
559
657
|
- !ruby/object:Gem::Dependency
|
560
658
|
name: wikipedia-client
|
561
659
|
requirement: !ruby/object:Gem::Requirement
|
@@ -570,7 +668,35 @@ dependencies:
|
|
570
668
|
- - "~>"
|
571
669
|
- !ruby/object:Gem::Version
|
572
670
|
version: 1.17.0
|
573
|
-
|
671
|
+
- !ruby/object:Gem::Dependency
|
672
|
+
name: faraday
|
673
|
+
requirement: !ruby/object:Gem::Requirement
|
674
|
+
requirements:
|
675
|
+
- - ">="
|
676
|
+
- !ruby/object:Gem::Version
|
677
|
+
version: '0'
|
678
|
+
type: :development
|
679
|
+
prerelease: false
|
680
|
+
version_requirements: !ruby/object:Gem::Requirement
|
681
|
+
requirements:
|
682
|
+
- - ">="
|
683
|
+
- !ruby/object:Gem::Version
|
684
|
+
version: '0'
|
685
|
+
- !ruby/object:Gem::Dependency
|
686
|
+
name: power_point_pptx
|
687
|
+
requirement: !ruby/object:Gem::Requirement
|
688
|
+
requirements:
|
689
|
+
- - "~>"
|
690
|
+
- !ruby/object:Gem::Version
|
691
|
+
version: 0.1.0
|
692
|
+
type: :development
|
693
|
+
prerelease: false
|
694
|
+
version_requirements: !ruby/object:Gem::Requirement
|
695
|
+
requirements:
|
696
|
+
- - "~>"
|
697
|
+
- !ruby/object:Gem::Version
|
698
|
+
version: 0.1.0
|
699
|
+
description: Build LLM-backed Ruby applications with Ruby's Langchain.rb
|
574
700
|
email:
|
575
701
|
- andrei.bondarev13@gmail.com
|
576
702
|
executables: []
|
@@ -581,27 +707,18 @@ files:
|
|
581
707
|
- LICENSE.txt
|
582
708
|
- README.md
|
583
709
|
- lib/langchain.rb
|
584
|
-
- lib/langchain/
|
585
|
-
- lib/langchain/
|
586
|
-
- lib/langchain/
|
587
|
-
- lib/langchain/agent/react_agent/react_agent_prompt.yaml
|
588
|
-
- lib/langchain/agent/sql_query_agent.rb
|
589
|
-
- lib/langchain/agent/sql_query_agent/sql_query_agent_answer_prompt.yaml
|
590
|
-
- lib/langchain/agent/sql_query_agent/sql_query_agent_sql_prompt.yaml
|
710
|
+
- lib/langchain/assistants/assistant.rb
|
711
|
+
- lib/langchain/assistants/message.rb
|
712
|
+
- lib/langchain/assistants/thread.rb
|
591
713
|
- lib/langchain/chunk.rb
|
592
714
|
- lib/langchain/chunker/base.rb
|
715
|
+
- lib/langchain/chunker/markdown.rb
|
593
716
|
- lib/langchain/chunker/prompts/semantic_prompt_template.yml
|
594
717
|
- lib/langchain/chunker/recursive_text.rb
|
595
718
|
- lib/langchain/chunker/semantic.rb
|
596
719
|
- lib/langchain/chunker/sentence.rb
|
597
720
|
- lib/langchain/chunker/text.rb
|
598
721
|
- lib/langchain/contextual_logger.rb
|
599
|
-
- lib/langchain/conversation.rb
|
600
|
-
- lib/langchain/conversation/context.rb
|
601
|
-
- lib/langchain/conversation/memory.rb
|
602
|
-
- lib/langchain/conversation/message.rb
|
603
|
-
- lib/langchain/conversation/prompt.rb
|
604
|
-
- lib/langchain/conversation/response.rb
|
605
722
|
- lib/langchain/data.rb
|
606
723
|
- lib/langchain/dependency_helper.rb
|
607
724
|
- lib/langchain/evals/ragas/answer_relevance.rb
|
@@ -619,10 +736,13 @@ files:
|
|
619
736
|
- lib/langchain/llm/base.rb
|
620
737
|
- lib/langchain/llm/cohere.rb
|
621
738
|
- lib/langchain/llm/google_palm.rb
|
739
|
+
- lib/langchain/llm/google_vertex_ai.rb
|
622
740
|
- lib/langchain/llm/hugging_face.rb
|
623
741
|
- lib/langchain/llm/llama_cpp.rb
|
742
|
+
- lib/langchain/llm/mistral_ai.rb
|
624
743
|
- lib/langchain/llm/ollama.rb
|
625
744
|
- lib/langchain/llm/openai.rb
|
745
|
+
- lib/langchain/llm/prompts/ollama/summarize_template.yaml
|
626
746
|
- lib/langchain/llm/prompts/summarize_template.yaml
|
627
747
|
- lib/langchain/llm/replicate.rb
|
628
748
|
- lib/langchain/llm/response/ai21_response.rb
|
@@ -631,7 +751,10 @@ files:
|
|
631
751
|
- lib/langchain/llm/response/base_response.rb
|
632
752
|
- lib/langchain/llm/response/cohere_response.rb
|
633
753
|
- lib/langchain/llm/response/google_palm_response.rb
|
754
|
+
- lib/langchain/llm/response/google_vertex_ai_response.rb
|
634
755
|
- lib/langchain/llm/response/hugging_face_response.rb
|
756
|
+
- lib/langchain/llm/response/llama_cpp_response.rb
|
757
|
+
- lib/langchain/llm/response/mistral_ai_response.rb
|
635
758
|
- lib/langchain/llm/response/ollama_response.rb
|
636
759
|
- lib/langchain/llm/response/openai_response.rb
|
637
760
|
- lib/langchain/llm/response/replicate_response.rb
|
@@ -643,10 +766,13 @@ files:
|
|
643
766
|
- lib/langchain/processors/base.rb
|
644
767
|
- lib/langchain/processors/csv.rb
|
645
768
|
- lib/langchain/processors/docx.rb
|
769
|
+
- lib/langchain/processors/eml.rb
|
646
770
|
- lib/langchain/processors/html.rb
|
647
771
|
- lib/langchain/processors/json.rb
|
648
772
|
- lib/langchain/processors/jsonl.rb
|
773
|
+
- lib/langchain/processors/markdown.rb
|
649
774
|
- lib/langchain/processors/pdf.rb
|
775
|
+
- lib/langchain/processors/pptx.rb
|
650
776
|
- lib/langchain/processors/text.rb
|
651
777
|
- lib/langchain/processors/xlsx.rb
|
652
778
|
- lib/langchain/prompt.rb
|
@@ -655,12 +781,22 @@ files:
|
|
655
781
|
- lib/langchain/prompt/loading.rb
|
656
782
|
- lib/langchain/prompt/prompt_template.rb
|
657
783
|
- lib/langchain/tool/base.rb
|
658
|
-
- lib/langchain/tool/calculator.
|
659
|
-
- lib/langchain/tool/
|
660
|
-
- lib/langchain/tool/
|
661
|
-
- lib/langchain/tool/
|
662
|
-
- lib/langchain/tool/
|
663
|
-
- lib/langchain/tool/
|
784
|
+
- lib/langchain/tool/calculator/calculator.json
|
785
|
+
- lib/langchain/tool/calculator/calculator.rb
|
786
|
+
- lib/langchain/tool/database/database.json
|
787
|
+
- lib/langchain/tool/database/database.rb
|
788
|
+
- lib/langchain/tool/file_system/file_system.json
|
789
|
+
- lib/langchain/tool/file_system/file_system.rb
|
790
|
+
- lib/langchain/tool/google_search/google_search.json
|
791
|
+
- lib/langchain/tool/google_search/google_search.rb
|
792
|
+
- lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.json
|
793
|
+
- lib/langchain/tool/ruby_code_interpreter/ruby_code_interpreter.rb
|
794
|
+
- lib/langchain/tool/vectorsearch/vectorsearch.json
|
795
|
+
- lib/langchain/tool/vectorsearch/vectorsearch.rb
|
796
|
+
- lib/langchain/tool/weather/weather.json
|
797
|
+
- lib/langchain/tool/weather/weather.rb
|
798
|
+
- lib/langchain/tool/wikipedia/wikipedia.json
|
799
|
+
- lib/langchain/tool/wikipedia/wikipedia.rb
|
664
800
|
- lib/langchain/utils/cosine_similarity.rb
|
665
801
|
- lib/langchain/utils/token_length/ai21_validator.rb
|
666
802
|
- lib/langchain/utils/token_length/base_validator.rb
|
@@ -671,6 +807,7 @@ files:
|
|
671
807
|
- lib/langchain/vectorsearch/base.rb
|
672
808
|
- lib/langchain/vectorsearch/chroma.rb
|
673
809
|
- lib/langchain/vectorsearch/elasticsearch.rb
|
810
|
+
- lib/langchain/vectorsearch/epsilla.rb
|
674
811
|
- lib/langchain/vectorsearch/hnswlib.rb
|
675
812
|
- lib/langchain/vectorsearch/milvus.rb
|
676
813
|
- lib/langchain/vectorsearch/pgvector.rb
|
@@ -697,15 +834,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
697
834
|
requirements:
|
698
835
|
- - ">="
|
699
836
|
- !ruby/object:Gem::Version
|
700
|
-
version: 3.
|
837
|
+
version: 3.1.0
|
701
838
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
702
839
|
requirements:
|
703
840
|
- - ">="
|
704
841
|
- !ruby/object:Gem::Version
|
705
842
|
version: '0'
|
706
843
|
requirements: []
|
707
|
-
rubygems_version: 3.3
|
844
|
+
rubygems_version: 3.5.3
|
708
845
|
signing_key:
|
709
846
|
specification_version: 4
|
710
|
-
summary: Build LLM-backed Ruby applications with Ruby's
|
847
|
+
summary: Build LLM-backed Ruby applications with Ruby's Langchain.rb
|
711
848
|
test_files: []
|
@@ -1,54 +0,0 @@
|
|
1
|
-
|
2
|
-
### Agents 🤖
|
3
|
-
Agents are semi-autonomous bots that can respond to user questions and use available to them Tools to provide informed replies. They break down problems into series of steps and define Actions (and Action Inputs) along the way that are executed and fed back to them as additional information. Once an Agent decides that it has the Final Answer it responds with it.
|
4
|
-
|
5
|
-
#### ReAct Agent
|
6
|
-
|
7
|
-
Add `gem "ruby-openai"`, `gem "eqn"`, and `gem "google_search_results"` to your Gemfile
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
search_tool = Langchain::Tool::GoogleSearch.new(api_key: ENV["SERPAPI_API_KEY"])
|
11
|
-
calculator = Langchain::Tool::Calculator.new
|
12
|
-
|
13
|
-
openai = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"])
|
14
|
-
|
15
|
-
agent = Langchain::Agent::ReActAgent.new(
|
16
|
-
llm: openai,
|
17
|
-
tools: [search_tool, calculator]
|
18
|
-
)
|
19
|
-
```
|
20
|
-
```ruby
|
21
|
-
agent.run(question: "How many full soccer fields would be needed to cover the distance between NYC and DC in a straight line?")
|
22
|
-
#=> "Approximately 2,945 soccer fields would be needed to cover the distance between NYC and DC in a straight line."
|
23
|
-
```
|
24
|
-
|
25
|
-
#### SQL-Query Agent
|
26
|
-
|
27
|
-
Add `gem "sequel"` to your Gemfile
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
database = Langchain::Tool::Database.new(connection_string: "postgres://user:password@localhost:5432/db_name")
|
31
|
-
|
32
|
-
agent = Langchain::Agent::SQLQueryAgent.new(llm: Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"]), db: database)
|
33
|
-
```
|
34
|
-
```ruby
|
35
|
-
agent.run(question: "How many users have a name with length greater than 5 in the users table?")
|
36
|
-
#=> "14 users have a name with length greater than 5 in the users table."
|
37
|
-
```
|
38
|
-
|
39
|
-
#### Demo
|
40
|
-
![May-12-2023 13-09-13](https://github.com/andreibondarev/langchainrb/assets/541665/6bad4cd9-976c-420f-9cf9-b85bf84f7eaf)
|
41
|
-
|
42
|
-
![May-12-2023 13-07-45](https://github.com/andreibondarev/langchainrb/assets/541665/9aacdcc7-4225-4ea0-ab96-7ee48826eb9b)
|
43
|
-
|
44
|
-
#### Available Tools 🛠️
|
45
|
-
|
46
|
-
| Name | Description | ENV Requirements | Gem Requirements |
|
47
|
-
| ------------ | :------------------------------------------------: | :-----------------------------------------------------------: | :---------------------------------------: |
|
48
|
-
| "calculator" | Useful for getting the result of a math expression | | `gem "eqn", "~> 1.6.5"` |
|
49
|
-
| "database" | Useful for querying a SQL database | | `gem "sequel", "~> 5.68.0"` |
|
50
|
-
| "ruby_code_interpreter" | Interprets Ruby expressions | | `gem "safe_ruby", "~> 1.0.4"` |
|
51
|
-
| "google_search" | A wrapper around Google Search | `ENV["SERPAPI_API_KEY"]` (https://serpapi.com/manage-api-key) | `gem "google_search_results", "~> 2.0.0"` |
|
52
|
-
| "weather" | Calls Open Weather API to retrieve the current weather | `ENV["OPEN_WEATHER_API_KEY"]` (https://home.openweathermap.org/api_keys) | `gem "open-weather-ruby-client", "~> 0.3.0"` |
|
53
|
-
| "wikipedia" | Calls Wikipedia API to retrieve the summary | | `gem "wikipedia-client", "~> 1.17.0"` |
|
54
|
-
|
data/lib/langchain/agent/base.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Langchain::Agent
|
4
|
-
# = Agents
|
5
|
-
#
|
6
|
-
# Agents are semi-autonomous bots that can respond to user questions and use available to them Tools to provide informed replies. They break down problems into series of steps and define Actions (and Action Inputs) along the way that are executed and fed back to them as additional information. Once an Agent decides that it has the Final Answer it responds with it.
|
7
|
-
#
|
8
|
-
# Available:
|
9
|
-
# - {Langchain::Agent::ReActAgent}
|
10
|
-
# - {Langchain::Agent::SQLQueryAgent}
|
11
|
-
#
|
12
|
-
# @abstract
|
13
|
-
class Base
|
14
|
-
def self.logger_options
|
15
|
-
{
|
16
|
-
color: :red
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
_type: prompt
|
2
|
-
template: |
|
3
|
-
Today is {date} and you can use tools to get new information. Answer the following questions as best you can using the following tools:
|
4
|
-
|
5
|
-
{tools}
|
6
|
-
|
7
|
-
Use the following format:
|
8
|
-
|
9
|
-
Question: the input question you must answer
|
10
|
-
Thought: you should always think about what to do
|
11
|
-
Action: the action to take, should be one of {tool_names}
|
12
|
-
Action Input: the input to the action
|
13
|
-
Observation: the result of the action
|
14
|
-
... (this Thought/Action/Action Input/Observation can repeat N times)
|
15
|
-
Thought: I now know the final answer
|
16
|
-
Final Answer: the final answer to the original input question
|
17
|
-
|
18
|
-
Begin!
|
19
|
-
|
20
|
-
Question: {question}
|
21
|
-
Thought:
|
22
|
-
input_variables:
|
23
|
-
- date
|
24
|
-
- question
|
25
|
-
- tools
|
26
|
-
- tool_names
|
@@ -1,131 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Langchain::Agent
|
4
|
-
# = ReAct Agent
|
5
|
-
#
|
6
|
-
# llm = Langchain::LLM::OpenAI.new(api_key: ENV["OPENAI_API_KEY"]) # or your choice of Langchain::LLM::Base implementation
|
7
|
-
#
|
8
|
-
# agent = Langchain::Agent::ReActAgent.new(
|
9
|
-
# llm: llm,
|
10
|
-
# tools: [
|
11
|
-
# Langchain::Tool::GoogleSearch.new(api_key: "YOUR_API_KEY"),
|
12
|
-
# Langchain::Tool::Calculator.new,
|
13
|
-
# Langchain::Tool::Wikipedia.new
|
14
|
-
# ]
|
15
|
-
# )
|
16
|
-
#
|
17
|
-
# agent.run(question: "How many full soccer fields would be needed to cover the distance between NYC and DC in a straight line?")
|
18
|
-
# #=> "Approximately 2,945 soccer fields would be needed to cover the distance between NYC and DC in a straight line."
|
19
|
-
class ReActAgent < Base
|
20
|
-
attr_reader :llm, :tools, :max_iterations
|
21
|
-
|
22
|
-
# Initializes the Agent
|
23
|
-
#
|
24
|
-
# @param llm [Object] The LLM client to use
|
25
|
-
# @param tools [Array<Tool>] The tools to use
|
26
|
-
# @param max_iterations [Integer] The maximum number of iterations to run
|
27
|
-
# @return [ReActAgent] The Agent::ReActAgent instance
|
28
|
-
def initialize(llm:, tools: [], max_iterations: 10)
|
29
|
-
Langchain::Tool::Base.validate_tools!(tools: tools)
|
30
|
-
|
31
|
-
@tools = tools
|
32
|
-
|
33
|
-
@llm = llm
|
34
|
-
@max_iterations = max_iterations
|
35
|
-
end
|
36
|
-
|
37
|
-
# Validate tools when they're re-assigned
|
38
|
-
#
|
39
|
-
# @param value [Array<Tool>] The tools to use
|
40
|
-
# @return [Array<Tool>] The tools that will be used
|
41
|
-
def tools=(value)
|
42
|
-
Langchain::Tool::Base.validate_tools!(tools: value)
|
43
|
-
@tools = value
|
44
|
-
end
|
45
|
-
|
46
|
-
# Run the Agent!
|
47
|
-
#
|
48
|
-
# @param question [String] The question to ask
|
49
|
-
# @return [String] The answer to the question
|
50
|
-
def run(question:)
|
51
|
-
question = question.strip
|
52
|
-
prompt = create_prompt(
|
53
|
-
question: question,
|
54
|
-
tools: tools
|
55
|
-
)
|
56
|
-
|
57
|
-
final_response = nil
|
58
|
-
max_iterations.times do
|
59
|
-
Langchain.logger.info("Sending the prompt to the #{llm.class} LLM", for: self.class)
|
60
|
-
|
61
|
-
response = llm.complete(prompt: prompt, stop_sequences: ["Observation:"]).completion
|
62
|
-
|
63
|
-
# Append the response to the prompt
|
64
|
-
prompt += response
|
65
|
-
|
66
|
-
# Find the requested action in the "Action: search" format
|
67
|
-
action = response.match(/Action: (.*)/)&.send(:[], -1)
|
68
|
-
|
69
|
-
if action
|
70
|
-
# Find the input to the action in the "Action Input: [action_input]" format
|
71
|
-
action_input = response.match(/Action Input: "?(.*)"?/)&.send(:[], -1)
|
72
|
-
|
73
|
-
# Find the Tool and call `execute`` with action_input as the input
|
74
|
-
tool = tools.find { |tool| tool.name == action.strip }
|
75
|
-
Langchain.logger.info("Invoking \"#{tool.class}\" Tool with \"#{action_input}\"", for: self.class)
|
76
|
-
|
77
|
-
# Call `execute` with action_input as the input
|
78
|
-
result = tool.execute(input: action_input)
|
79
|
-
|
80
|
-
# Append the Observation to the prompt
|
81
|
-
prompt += if prompt.end_with?("Observation:")
|
82
|
-
" #{result}\nThought:"
|
83
|
-
else
|
84
|
-
"\nObservation: #{result}\nThought:"
|
85
|
-
end
|
86
|
-
elsif response.include?("Final Answer:")
|
87
|
-
# Return the final answer
|
88
|
-
final_response = response.split("Final Answer:")[-1]
|
89
|
-
break
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
final_response || raise(MaxIterationsReachedError.new(max_iterations))
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
# Create the initial prompt to pass to the LLM
|
99
|
-
# @param question [String] Question to ask
|
100
|
-
# @param tools [Array] Tools to use
|
101
|
-
# @return [String] Prompt
|
102
|
-
def create_prompt(question:, tools:)
|
103
|
-
tool_list = tools.map(&:name)
|
104
|
-
|
105
|
-
prompt_template.format(
|
106
|
-
date: Date.today.strftime("%B %d, %Y"),
|
107
|
-
question: question,
|
108
|
-
tool_names: "[#{tool_list.join(", ")}]",
|
109
|
-
tools: tools.map do |tool|
|
110
|
-
tool_name = tool.name
|
111
|
-
tool_description = tool.description
|
112
|
-
"#{tool_name}: #{tool_description}"
|
113
|
-
end.join("\n")
|
114
|
-
)
|
115
|
-
end
|
116
|
-
|
117
|
-
# Load the PromptTemplate from the YAML file
|
118
|
-
# @return [PromptTemplate] PromptTemplate instance
|
119
|
-
def prompt_template
|
120
|
-
@template ||= Langchain::Prompt.load_from_path(
|
121
|
-
file_path: Langchain.root.join("langchain/agent/react_agent/react_agent_prompt.yaml")
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
class MaxIterationsReachedError < Langchain::Errors::BaseError
|
126
|
-
def initialize(max_iterations)
|
127
|
-
super("Agent stopped after #{max_iterations} iterations")
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|