guzba / sunny

JSON in Nim with Go-like field tags.
MIT License
14 stars 0 forks source link

Error: OllmGenerateResponse variant discriminator field cannot be omitted #10

Closed Luyten-Orion closed 3 months ago

Luyten-Orion commented 3 months ago

Hey there, I'm currently writing an Ollama API wrapper and I decided to use sunny since it provided the features I needed, but when I added the createdAt field, Sunny complained about the omission of the discriminator field. Removing this field fixes the error but prevents me from being able to store the parsed timestamp, other than this, sunny is great and exactly what I needed!

import sunny, times

type
  OllmGenerateResponse* = object
    model* {.json: ",required".}: string
    createdAtStr {.json: "created_at,required".}: string
    createdAt {.json: "-".}: DateTime
    response* {.json: ",required".}: string
    case done*: bool
      of true:
        totalDuration* {.json: "total_duration,required".}: int64
        loadDuration* {.json: "load_duration,required".}: int64
        promptEvalCount* {.json: "prompt_eval_count,required".}: int64
        promptEvalDuration* {.json: "prompt_eval_duration,required".}: int64
        evalCount* {.json: "eval_count,required".}: int64
        evalDuration* {.json: "eval_duration,required".}: int64
        context* {.json: ",required".}: seq[int]
      else:
        discard

echo OllmGenerateResponse.fromJson("""{"model":"stuehieyr/nandine:latest","created_at":"2024-06-25T22:38:48.566852763Z","response":"Hello! How can I assist you today?\n","done":true,"total_duration":0,"load_duration":0,"prompt_eval_count":0,"prompt_eval_duration":0,"eval_count":0,"eval_duration":0,"context":[]}""")
Luyten-Orion commented 3 months ago

I forgot to include the exact error, the error is

/home/chronos/.nimble/pkgs2/sunny-0.1.8-4692a8890fa287ff182f347530f455bfbf8b7669/sunny.nim(1127, 9) template/generic instantiation of `fromJson` from here
/home/chronos/.nimble/pkgs2/sunny-0.1.8-4692a8890fa287ff182f347530f455bfbf8b7669/sunny.nim(1037, 22) Error: OllmGenerateResponse variant discriminator field cannot be omitted
guzba commented 3 months ago

Thanks for the heads up, small issue with a quick easy fix.

Fixed and tagged in 0.1.9 https://github.com/guzba/sunny/releases/tag/0.1.9

Luyten-Orion commented 3 months ago

Thanks for the quick reply and fix, heavily appreciated!

On Wed, 26 Jun 2024, 1:08 am guzba, @.***> wrote:

Thanks for the heads up, small issue with a quick easy fix.

Fixed and tagged in 0.1.9 https://github.com/guzba/sunny/releases/tag/0.1.9

— Reply to this email directly, view it on GitHub https://github.com/guzba/sunny/issues/10#issuecomment-2190236269, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGSGUVYDP6E54XSQGS3BPA3ZJIBATAVCNFSM6AAAAABJ4XCO7KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJQGIZTMMRWHE . You are receiving this because you authored the thread.Message ID: @.***>