Skip to content

Commit 5783def

Browse files
committed
Using with_response_format at crmne/ruby_llm#131 in DeepSeek v3
1 parent dfac07b commit 5783def

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ gem "wechat", git: "https://git.thape.com.cn/Eric-Guo/wechat.git", branch: :main
4646
gem "rake"
4747

4848
# bundle config local.ruby_llm /Users/$(whoami)/git/oss/ruby_llm/
49-
gem "ruby_llm", git: "https://git.thape.com.cn/rails/ruby_llm.git", branch: :main
49+
gem "ruby_llm", git: "https://git.thape.com.cn/rails/ruby_llm.git", branch: :WithResponseFormat
5050
gem "uri"
5151
gem "faraday-net_http"
5252
gem "net-http", "~> 0.4.1"

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ GIT
1414

1515
GIT
1616
remote: https://git.thape.com.cn/rails/ruby_llm.git
17-
revision: 455c3e4c81e88ec871369e25eacc66a7db945210
18-
branch: main
17+
revision: 4f4b2c4ff5c278e1d2af048f5088536d0b22bb70
18+
branch: WithResponseFormat
1919
specs:
20-
ruby_llm (1.2.0)
20+
ruby_llm (1.3.0)
2121
base64
2222
event_stream_parser (~> 1)
2323
faraday (~> 2)

app/models/guest_message.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ class GuestMessage < ApplicationRecord
44
after_create :auto_fill_spam_score
55

66
def auto_fill_spam_score
7-
ai_result = JSON.parse(ai_spam_score)
8-
9-
if ai_result.present?
10-
spam_score = ai_result["spam_score"]
11-
update_column(:spam_score, spam_score)
12-
end
7+
update_column(:spam_score, ai_spam_score)
138
end
149

1510
def ai_spam_score
@@ -25,25 +20,19 @@ def ai_spam_score
2520
包淦: 请问贵阳公司在招结构专业负责人吗
2621
2722
EXAMPLE JSON OUTPUT 1:
28-
{
29-
"spam_score": 0
30-
}
23+
{"result": 0}
3124
3225
EXAMPLE INPUT 2:
3326
DavidPop: Igjdfjvkdgvj jfsfcjsjfkj ifjfsifhidjfw iijfosjfd https://mail.ru/?gjvhdfjdfuvdbggf
3427
3528
EXAMPLE JSON OUTPUT 2:
36-
{
37-
"spam_score": 10
38-
}
29+
{"result": 10}
3930
4031
EXAMPLE INPUT 3:
4132
RobertDrale:Hæ, ég vildi vita verð þitt.
4233
4334
EXAMPLE JSON OUTPUT 3:
44-
{
45-
"spam_score": 8
46-
}
35+
{"result": 8}
4736
4837
EXAMPLE INPUT 4:
4938
Eric Jones: Cool website!
@@ -54,13 +43,12 @@ def ai_spam_score
5443
5544
5645
EXAMPLE JSON OUTPUT 4:
57-
{
58-
"spam_score": 9
59-
}
46+
{"result": 9}
6047
EOS_PROMPT
6148

6249
chat = RubyLLM.chat
6350
chat.with_instructions system_prompt
51+
chat.with_response_format(type: :object, properties: {result: {type: :integer}})
6452
response = chat.ask "#{name} from company #{company} (#{contact_details}) leaving message:\n\n#{message}"
6553
response.content
6654
end

0 commit comments

Comments
 (0)