Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 Bad Request Faraday error on a small variation of the sample code in README #24

Open
itsmeritesh opened this issue Jul 25, 2024 · 4 comments

Comments

@itsmeritesh
Copy link

itsmeritesh commented Jul 25, 2024

Describe the bug
400 Bad Request - Faraday Error

To Reproduce
Steps to reproduce the behavior:

Running my function in a rails app.

Function takes a string argument OCR-text, which is scans of bio text books and written material.

Expected behavior
Should return a structured JSON of the organisms mentioned in the extracted_text.

CODE BLOCK

def extract_bio(ocr_text) 
@prompt = "Analyze the user provided text, and identify any references to wildlife. For all matching organisms include the name, biological name, description among other attributes, return results in the declared JSON format. [only elaborate where you can cite a verified source, return Nil otherwise"
@output_json_format = '[{"Name": "Name of the referenced animal or species",  
 "description": "brief description of the organism", "article-date": "date of publishing in datetime format","location": "full address, or lat long"}]'
claude = Anthropic::Client.new  
  
response = claude.messages(  
  parameters: {  
    model: "claude-3-haiku-20240307",  
    system: @prompt,  
    messages: [  
      {"role": "user", "content": ocr_text},  
      { "role": "assistant", "content": @output_json_format }  
    ],  
    max_tokens: 1000  
  }  
)
puts response
end

Desktop (please complete the following information):

  • OS: [e.g. MacOS]
  • Browser [e.g. chrome]

Additional context
I'm declaring Anthropic::Client in an initializer.rb file.

@itsmeritesh
Copy link
Author

itsmeritesh commented Jul 25, 2024

I'd posted this on the discord yesterday. This is a duplicate. Attaching the questions here too.

  1. Is there a way to turn on verbose error logs ?
  2. Is this still the recommended way to get JSON responses? In trying this out on a console, I'm getting hallucinations. Trying to correct it by dropping temp drops recall on my dataset.
  3. If I'm trying to orchestrate a few such calls using Ruby, is there a framework that helps, similar to long chain, that's recommended for use in Ruby?

@Maclenn77
Copy link
Contributor

  1. If I'm trying to orchestrate a few such calls using Ruby, is there a framework that helps, similar to long chain, that's recommended for use in Ruby?

@itsmeritesh did you mean "langchain" ? Check langchainrb or boxcars

@gerrywastaken
Copy link

gerrywastaken commented Sep 5, 2024

def extract_bio
  response = claude.messages(
    parameters: {
      model: "claude-3-haiku-20240307",
      system: @prompt,
      messages: [
        { "role": "user", "content": ocr_text },
        { "role": "assistant", "content": @output_json_format }
      ],
      max_tokens: 1000
    }
  )
  puts response
rescue
  $!.response_body
end

@itsmeritesh
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants