smart_prompt 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 844c87d47dccd945bedcab69c58377ae144238ac9087b49219041382db539146
4
- data.tar.gz: 3e70f88fbe8d26a0a15408e73ae9060b9f711a18e6b44eb561910b90156ca14b
3
+ metadata.gz: 18a10421c03b8707b2ff6d7cf40a5e58eee621b62a177c7ab3d10c2b5e75b767
4
+ data.tar.gz: 4f43968f0b7cf8e9dab3ce5959f2a837729b335b0a1fcc533852339f130b7e43
5
5
  SHA512:
6
- metadata.gz: 398854ce070f96f794ae944cc656a10d2f4752268cb35b4f9a857fcd8a722489b3ee112de97e5cdfe1cc1efb75cf92e4cd4a9b36cb338cbd8de6e22f1d6cc7dc
7
- data.tar.gz: babac8b7d0479eb376df22b00cd693e6e657293e6b28b654aaa6b2ef4f9fcfdccb9709d6f1dd0b066cb6f22c07eed0173426816121061a80c91fc9afdd62ba06
6
+ metadata.gz: e0fd7f1e1995821f53135e01f92c3d3cdf1296405fec138c588ff23450c9be452d81b8a3dd42fb1e9fdf73748a1cc0119fe09285bac281eb035c2bec4742987c
7
+ data.tar.gz: 45e702684683ff912f149a2ae2f7eb94f0f4efa183f991923db8858223a1c721e975821972f7183fcb958e902168a65b22d5ea14f84be6cea87a434ced74e447
data/README.cn.md CHANGED
@@ -24,90 +24,4 @@ $ gem install smart_prompt
24
24
 
25
25
  ## 用法
26
26
 
27
- 以下是一些基本用法示例:
28
-
29
- ### 配置文件
30
-
31
- ```
32
- adapters:
33
- openai: OpenAIAdapter
34
- ollama: OllamaAdapter
35
- llms:
36
- siliconflow:
37
- adapter: openai
38
- url: https://api.siliconflow.cn/v1/
39
- api_key: ENV["APIKey"]
40
- default_model: Qwen/Qwen2.5-7B-Instruct
41
- llamacpp:
42
- adapter: openai
43
- url: http://localhost:8080/
44
- ollama:
45
- adapter: ollama
46
- url: http://localhost:11434/
47
- default_model: qwen2.5
48
- default_llm: siliconflow
49
- worker_path: "./workers"
50
- template_path: "./templates"
51
- ```
52
-
53
- ### 基本使用
54
-
55
- ```
56
- require 'smart_prompt'
57
- engine = SmartPrompt::Engine.new('./config/llm_config.yml')
58
- result = engine.call_worker(:daily_report, {location: "Shanghai"})
59
- puts result
60
- ```
61
-
62
- ### workers/daily_report.rb
63
-
64
- ```
65
- SmartPrompt.define_worker :daily_report do
66
- use "ollama"
67
- model "gemma2"
68
- system "You are a helpful report writer."
69
- weather = call_worker(:weather_summary, { location: params[:location], date: "today" })
70
- prompt :daily_report, { weather: weather, location: params[:location] }
71
- send_msg
72
- end
73
- ```
74
-
75
- ### workers/weather_summary.rb
76
-
77
- ```
78
- SmartPrompt.define_worker :weather_summary do
79
- use "ollama"
80
- model "gemma2"
81
- sys_msg "You are a helpful weather assistant."
82
- prompt :weather, { location: params[:location], date: params[:date] }
83
- weather_info = send_msg
84
- prompt :summarize, { text: weather_info }
85
- send_msg
86
- end
87
- ```
88
-
89
- ### templates/daily_report.erb
90
-
91
- ```
92
- Please create a brief daily report for <%= location %> based on the following weather information:
93
-
94
- <%= weather %>
95
-
96
- The report should include:
97
- 1. A summary of the weather
98
- 2. Any notable events or conditions
99
- 3. Recommendations for residents
100
- ```
101
- ### templates/weather.erb
102
-
103
- ```
104
- What's the weather like in <%= location %> <%= date %>? Please provide a brief description including temperature and general conditions.
105
- ```
106
-
107
- ### templates/summarize.erb
108
-
109
- ```
110
- Please summarize the following text in one sentence:
111
-
112
- <%= text %>
113
- ```
27
+ 更多示例请看项目 [SmartPromptDemo](https://github.com/zhuangbiaowei/SmartPromptDemo)
data/README.md CHANGED
@@ -26,90 +26,4 @@ $ gem install smart_prompt
26
26
 
27
27
  ## Usage
28
28
 
29
- The following are some examples of basic usage:
30
-
31
- ### llm_config.yml
32
-
33
- ```
34
- adapters:
35
- openai: OpenAIAdapter
36
- ollama: OllamaAdapter
37
- llms:
38
- siliconflow:
39
- adapter: openai
40
- url: https://api.siliconflow.cn/v1/
41
- api_key: ENV["APIKey"]
42
- default_model: Qwen/Qwen2.5-7B-Instruct
43
- llamacpp:
44
- adapter: openai
45
- url: http://localhost:8080/
46
- ollama:
47
- adapter: ollama
48
- url: http://localhost:11434/
49
- default_model: qwen2.5
50
- default_llm: siliconflow
51
- worker_path: "./workers"
52
- template_path: "./templates"
53
- ```
54
-
55
- ### Basic usage
56
-
57
- ```
58
- require 'smart_prompt'
59
- engine = SmartPrompt::Engine.new('./config/llm_config.yml')
60
- result = engine.call_worker(:daily_report, {location: "Shanghai"})
61
- puts result
62
- ```
63
-
64
- ### workers/daily_report.rb
65
-
66
- ```
67
- SmartPrompt.define_worker :daily_report do
68
- use "ollama"
69
- model "gemma2"
70
- system "You are a helpful report writer."
71
- weather = call_worker(:weather_summary, { location: params[:location], date: "today" })
72
- prompt :daily_report, { weather: weather, location: params[:location] }
73
- send_msg
74
- end
75
- ```
76
-
77
- ### workers/weather_summary.rb
78
-
79
- ```
80
- SmartPrompt.define_worker :weather_summary do
81
- use "ollama"
82
- model "gemma2"
83
- sys_msg "You are a helpful weather assistant."
84
- prompt :weather, { location: params[:location], date: params[:date] }
85
- weather_info = send_msg
86
- prompt :summarize, { text: weather_info }
87
- send_msg
88
- end
89
- ```
90
-
91
- ### templates/daily_report.erb
92
-
93
- ```
94
- Please create a brief daily report for <%= location %> based on the following weather information:
95
-
96
- <%= weather %>
97
-
98
- The report should include:
99
- 1. A summary of the weather
100
- 2. Any notable events or conditions
101
- 3. Recommendations for residents
102
- ```
103
- ### templates/weather.erb
104
-
105
- ```
106
- What's the weather like in <%= location %> <%= date %>? Please provide a brief description including temperature and general conditions.
107
- ```
108
-
109
- ### templates/summarize.erb
110
-
111
- ```
112
- Please summarize the following text in one sentence:
113
-
114
- <%= text %>
115
- ```
29
+ See project [SmartPromptDemo](https://github.com/zhuangbiaowei/SmartPromptDemo) for more examples.
@@ -2,18 +2,21 @@ module SmartPrompt
2
2
  class Engine
3
3
  attr_reader :config_file, :config, :adapters, :current_adapter, :llms, :templates
4
4
  def initialize(config_file)
5
- SmartPrompt.logger.info "Start create the SmartPrompt engine."
6
5
  @config_file = config_file
7
6
  @adapters={}
8
7
  @llms={}
9
8
  @templates={}
10
9
  load_config(config_file)
10
+ SmartPrompt.logger.info "Started create the SmartPrompt engine."
11
11
  end
12
12
 
13
13
  def load_config(config_file)
14
- SmartPrompt.logger.info "Loading configuration from file: #{config_file}"
15
14
  @config_file = config_file
16
15
  @config = YAML.load_file(config_file)
16
+ if @config['logger_file']
17
+ SmartPrompt.logger = Logger.new(@config['logger_file'])
18
+ end
19
+ SmartPrompt.logger.info "Loading configuration from file: #{config_file}"
17
20
  @config['adapters'].each do |adapter_name, adapter_class|
18
21
  adapter_class = SmartPrompt.const_get(adapter_class)
19
22
  @adapters[adapter_name] = adapter_class
@@ -1,3 +1,3 @@
1
1
  module SmartPrompt
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/smart_prompt.rb CHANGED
@@ -17,6 +17,10 @@ module SmartPrompt
17
17
  worker = Worker.new(name, config_file)
18
18
  worker.execute(params)
19
19
  end
20
+
21
+ def self.logger=(logger)
22
+ @logger = logger
23
+ end
20
24
 
21
25
  def self.logger
22
26
  @logger ||= Logger.new($stdout).tap do |log|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_prompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhuang biaowei
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-07 00:00:00.000000000 Z
11
+ date: 2024-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml