Skip to content

Commit

Permalink
Update OpenAIWritter
Browse files Browse the repository at this point in the history
- Update prompt
- User newer LLM model
  • Loading branch information
MatheusRich committed Aug 30, 2024
1 parent 8d38833 commit b996a17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/gold_miner/blog_post/open_ai_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def give_title_to(gold_nugget)

def summarize(gold_nugget)
summary = ask_openai <<~PROMPT
Summarize the following markdown message without removing the author's blog link. Return the summary as markdown.
Summarize the following markdown message without removing the author's blog link.
Keep code examples and links, if any. Return the summary as markdown.
Message:
#{gold_nugget.as_conversation}
Expand All @@ -48,7 +49,7 @@ def summarize(gold_nugget)
def ask_openai(prompt)
response = @openai_client.chat(
parameters: {
model: "gpt-3.5-turbo",
model: "gpt-4o-mini",
messages: [{role: "user", content: prompt.strip}],
temperature: 0
}
Expand Down
8 changes: 4 additions & 4 deletions spec/gold_miner/blog_post/open_ai_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
request = stub_open_ai_request(
token: token,
prompt:
"Summarize the following markdown message without removing the author's blog link. Return the summary as markdown.\n\nMessage:\n#{gold_nugget.as_conversation}",
"Summarize the following markdown message without removing the author's blog link.\nKeep code examples and links, if any. Return the summary as markdown.\n\nMessage:\n#{gold_nugget.as_conversation}",
response_status: 200,
response_body: {
"choices" => [{"message" => {"role" => "assistant", "content" => open_ai_summary}}]
Expand All @@ -231,7 +231,7 @@
request = stub_open_ai_error(
token: token,
prompt:
"Summarize the following markdown message without removing the author's blog link. Return the summary as markdown.\n\nMessage:\n#{gold_nugget.as_conversation}",
"Summarize the following markdown message without removing the author's blog link.\nKeep code examples and links, if any. Return the summary as markdown.\n\nMessage:\n#{gold_nugget.as_conversation}",
response_error: open_ai_error
)
writer = described_class.new(open_ai_api_token: token, fallback_writer: stub_fallback_writer)
Expand All @@ -248,7 +248,7 @@
request = stub_open_ai_error(
token: token,
prompt:
"Summarize the following markdown message without removing the author's blog link. Return the summary as markdown.\n\nMessage:\n#{gold_nugget.as_conversation}",
"Summarize the following markdown message without removing the author's blog link.\nKeep code examples and links, if any. Return the summary as markdown.\n\nMessage:\n#{gold_nugget.as_conversation}",
response_error: "Some error"
)
fallback_summary = "[TODO]"
Expand Down Expand Up @@ -285,7 +285,7 @@ def stub_open_ai_error(token:, prompt:, response_error:)
def stub_open_ai_request(token:, prompt:, response_body:, response_status:)
stub_request(:post, "https://api.openai.com/v1/chat/completions")
.with(
body: %({"model":"gpt-3.5-turbo","messages":[{"role":"user","content":#{prompt.strip.dump}}],"temperature":0}),
body: %({"model":"gpt-4o-mini","messages":[{"role":"user","content":#{prompt.strip.dump}}],"temperature":0}),
headers: {
"Accept" => "*/*",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
Expand Down

0 comments on commit b996a17

Please sign in to comment.