Announcement

Collapse
No announcement yet.

MvCALL Array Index error with no Array

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MvCALL Array Index error with no Array

    We are stumped. Works fine with python and curl. But using MvCALL is returning this error: Fatal error in MiscRepo\Test_Groq.mvc @ [00000000:00000302]: E:\MiscRepo\Test_Groq.mv: Line 46: Array index must be positive integer.

    Interestingly we comment out the api_key and we still get the error. If we also comment out the payload - we get authentication error. If we add back the key without payload - expected error. IF we add back payload (with key) - the fatal error.

    Using normal <MvCAPTURE> - same result

    <MIVA STANDARDOUTPUTLEVEL="html,text,compresswhitespace" >

    <MvASSIGN NAME = "g.groqkey" VALUE = "REDACTED-THIS">

    <MvASSIGN NAME="l.payload" VALUE='{"model":"openai/gpt-oss-120b","messages":[{"role":"user","content":"Hello"}],"max_tokens":50,"stream":false}'>

    <MvASSIGN NAME="l.rawresponse" VALUE="">

    <Miva MvCALL_ERROR="nonfatal,nodisplay">
    <MvCALL ACTION="https://api.groq.com/openai/v1/chat/completions"
    METHOD="RAW"
    CONTENT-TYPE="application/json"
    HEADERS="{ 'Authorization: Bearer ' $ g.groqkey }"
    FIELDS="{ l.payload }">
    <MvASSIGN NAME="l.rawresponse" VALUE="{ l.rawresponse $ s.callvalue }">
    <MvCALLSTOP>
    </MvCALL>
    <Miva MvCALL_ERROR="fatal,display">

    Raw Response: <MvEVAL EXPR="{ miva_json_decode(l.rawresponse, l.theresult) }">
    theresult: <MvEVAL EXPR = "{ l.theresult }"><BR>

    Thanks for any assistance.

    -mike



    #2
    The issue is you are using an expression for the FIELDS attribute on the MvCALL. You need to change it to FIELDS="l.payload" (not curly braces). The way you have it now, l.payload is being evaluated within the FIELDS attribute so the engine is parsing your JSON string and when it gets to "[{"role":...}]" it sees an array and finds a string instead of a positive integer.
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      Sheeeze... you mean like we do in all of our other api calls. The hours; the stupidness. Thank you David!! Sorry to waste your time.

      -mike

      Comment

      Working...
      X