Skip to content

Commit

Permalink
Protect from more ollama responses (#142)
Browse files Browse the repository at this point in the history
* update version to 1.20.2

* protect from ollama responses with nested hashes

---------

Co-authored-by: nick <nicholas.newberry@oxaro.com>
  • Loading branch information
oxaronick and nick authored Nov 19, 2024
1 parent 22d3e21 commit cbc7088
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ RSpec/InstanceVariable:
Rails/I18nLocaleTexts:
# reenable when we localize
Enabled: false
Layout/MultilineOperationIndentation:
EnforcedStyle: indented
5 changes: 4 additions & 1 deletion app/services/ollama_proxy/formatted_chat_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ def generate(&)
def extract_content(chunk)
response_hash = parse_chunk(chunk)

response_hash.dig("message", "content") ||
content = response_hash.dig("message", "content") ||
response_hash.dig("choices", 0, "delta", "content") ||
response_hash.dig("choices", 0, "message", "content") ||
response_hash["error"] ||
chunk
content = content.to_s unless content.is_a?(String)

content
end

def parse_chunk(chunk)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
`git describe --tags`.strip
else
# make this calculated in production, or at least have tests or something else to detect drift from git tag
"v1.20.0"
"v1.20.2"
end

0 comments on commit cbc7088

Please sign in to comment.