types.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. package api
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log/slog"
  6. "math"
  7. "os"
  8. "reflect"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // StatusError is an error with and HTTP status code.
  14. type StatusError struct {
  15. StatusCode int
  16. Status string
  17. ErrorMessage string `json:"error"`
  18. }
  19. func (e StatusError) Error() string {
  20. switch {
  21. case e.Status != "" && e.ErrorMessage != "":
  22. return fmt.Sprintf("%s: %s", e.Status, e.ErrorMessage)
  23. case e.Status != "":
  24. return e.Status
  25. case e.ErrorMessage != "":
  26. return e.ErrorMessage
  27. default:
  28. // this should not happen
  29. return "something went wrong, please see the ollama server logs for details"
  30. }
  31. }
  32. // ImageData represents the raw binary data of an image file.
  33. type ImageData []byte
  34. // GenerateRequest describes a request sent by [Client.Generate]. While you
  35. // have to specify the Model and Prompt fields, all the other fields have
  36. // reasonable defaults for basic uses.
  37. type GenerateRequest struct {
  38. // Model is the model name; it should be a name familiar to Ollama from
  39. // the library at https://ollama.com/library
  40. Model string `json:"model"`
  41. // Prompt is the textual prompt to send to the model.
  42. Prompt string `json:"prompt"`
  43. // System overrides the model's default system message/prompt.
  44. System string `json:"system"`
  45. // Template overrides the model's default prompt template.
  46. Template string `json:"template"`
  47. // Context is the context parameter returned from a previous call to
  48. // Generate call. It can be used to keep a short conversational memory.
  49. Context []int `json:"context,omitempty"`
  50. // Stream specifies whether the response is streaming; it is true by default.
  51. Stream *bool `json:"stream,omitempty"`
  52. // Raw set to true means that no formatting will be applied to the prompt.
  53. Raw bool `json:"raw,omitempty"`
  54. // Format specifies the format to return a response in.
  55. Format string `json:"format"`
  56. // KeepAlive controls how long the model will stay loaded in memory following
  57. // this request.
  58. KeepAlive *Duration `json:"keep_alive,omitempty"`
  59. // Images is an optional list of base64-encoded images accompanying this
  60. // request, for multimodal models.
  61. Images []ImageData `json:"images,omitempty"`
  62. // Options lists model-specific options. For example, temperature can be
  63. // set through this field, if the model supports it.
  64. Options map[string]interface{} `json:"options"`
  65. }
  66. // ChatRequest describes a request sent by [Client.Chat].
  67. type ChatRequest struct {
  68. // Model is the model name, as in [GenerateRequest].
  69. Model string `json:"model"`
  70. // Messages is the messages of the chat - can be used to keep a chat memory.
  71. Messages []Message `json:"messages"`
  72. // Stream enable streaming of returned response; true by default.
  73. Stream *bool `json:"stream,omitempty"`
  74. // Format is the format to return the response in (e.g. "json").
  75. Format string `json:"format"`
  76. // KeepAlive controls how long the model will stay loaded into memory
  77. // followin the request.
  78. KeepAlive *Duration `json:"keep_alive,omitempty"`
  79. // Options lists model-specific options.
  80. Options map[string]interface{} `json:"options"`
  81. }
  82. // Message is a single message in a chat sequence. The message contains the
  83. // role ("system", "user", or "assistant"), the content and an optional list
  84. // of images.
  85. type Message struct {
  86. Role string `json:"role"`
  87. Content string `json:"content"`
  88. Images []ImageData `json:"images,omitempty"`
  89. }
  90. func (m *Message) UnmarshalJSON(b []byte) error {
  91. type Alias Message
  92. var a Alias
  93. if err := json.Unmarshal(b, &a); err != nil {
  94. return err
  95. }
  96. *m = Message(a)
  97. m.Role = strings.ToLower(m.Role)
  98. return nil
  99. }
  100. // ChatResponse is the response returned by [Client.Chat]. Its fields are
  101. // similar to [GenerateResponse].
  102. type ChatResponse struct {
  103. Model string `json:"model"`
  104. CreatedAt time.Time `json:"created_at"`
  105. Message Message `json:"message"`
  106. DoneReason string `json:"done_reason,omitempty"`
  107. Done bool `json:"done"`
  108. Metrics
  109. }
  110. type Metrics struct {
  111. TotalDuration time.Duration `json:"total_duration,omitempty"`
  112. LoadDuration time.Duration `json:"load_duration,omitempty"`
  113. PromptEvalCount int `json:"prompt_eval_count,omitempty"`
  114. PromptEvalDuration time.Duration `json:"prompt_eval_duration,omitempty"`
  115. EvalCount int `json:"eval_count,omitempty"`
  116. EvalDuration time.Duration `json:"eval_duration,omitempty"`
  117. }
  118. // Options specified in [GenerateRequest], if you add a new option here add it
  119. // to the API docs also.
  120. type Options struct {
  121. Runner
  122. // Predict options used at runtime
  123. NumKeep int `json:"num_keep,omitempty"`
  124. Seed int `json:"seed,omitempty"`
  125. NumPredict int `json:"num_predict,omitempty"`
  126. TopK int `json:"top_k,omitempty"`
  127. TopP float32 `json:"top_p,omitempty"`
  128. TFSZ float32 `json:"tfs_z,omitempty"`
  129. TypicalP float32 `json:"typical_p,omitempty"`
  130. RepeatLastN int `json:"repeat_last_n,omitempty"`
  131. Temperature float32 `json:"temperature,omitempty"`
  132. RepeatPenalty float32 `json:"repeat_penalty,omitempty"`
  133. PresencePenalty float32 `json:"presence_penalty,omitempty"`
  134. FrequencyPenalty float32 `json:"frequency_penalty,omitempty"`
  135. Mirostat int `json:"mirostat,omitempty"`
  136. MirostatTau float32 `json:"mirostat_tau,omitempty"`
  137. MirostatEta float32 `json:"mirostat_eta,omitempty"`
  138. PenalizeNewline bool `json:"penalize_newline,omitempty"`
  139. Stop []string `json:"stop,omitempty"`
  140. }
  141. // Runner options which must be set when the model is loaded into memory
  142. type Runner struct {
  143. UseNUMA bool `json:"numa,omitempty"`
  144. NumCtx int `json:"num_ctx,omitempty"`
  145. NumBatch int `json:"num_batch,omitempty"`
  146. NumGPU int `json:"num_gpu,omitempty"`
  147. MainGPU int `json:"main_gpu,omitempty"`
  148. LowVRAM bool `json:"low_vram,omitempty"`
  149. F16KV bool `json:"f16_kv,omitempty"`
  150. LogitsAll bool `json:"logits_all,omitempty"`
  151. VocabOnly bool `json:"vocab_only,omitempty"`
  152. UseMMap *bool `json:"use_mmap,omitempty"`
  153. UseMLock bool `json:"use_mlock,omitempty"`
  154. NumThread int `json:"num_thread,omitempty"`
  155. }
  156. // EmbedRequest is the request passed to [Client.Embed].
  157. type EmbedRequest struct {
  158. // Model is the model name.
  159. Model string `json:"model"`
  160. // Input is the input to embed.
  161. Input any `json:"input"`
  162. // KeepAlive controls how long the model will stay loaded in memory following
  163. // this request.
  164. KeepAlive *Duration `json:"keep_alive,omitempty"`
  165. Truncate *bool `json:"truncate,omitempty"`
  166. // Options lists model-specific options.
  167. Options map[string]interface{} `json:"options"`
  168. }
  169. // EmbedResponse is the response from [Client.Embed].
  170. type EmbedResponse struct {
  171. Model string `json:"model"`
  172. Embeddings [][]float32 `json:"embeddings,omitempty"`
  173. }
  174. // EmbeddingRequest is the request passed to [Client.Embeddings].
  175. type EmbeddingRequest struct {
  176. // Model is the model name.
  177. Model string `json:"model"`
  178. // Prompt is the textual prompt to embed.
  179. Prompt string `json:"prompt"`
  180. // KeepAlive controls how long the model will stay loaded in memory following
  181. // this request.
  182. KeepAlive *Duration `json:"keep_alive,omitempty"`
  183. // Options lists model-specific options.
  184. Options map[string]interface{} `json:"options"`
  185. }
  186. // EmbeddingResponse is the response from [Client.Embeddings].
  187. type EmbeddingResponse struct {
  188. Embedding []float64 `json:"embedding"`
  189. }
  190. // CreateRequest is the request passed to [Client.Create].
  191. type CreateRequest struct {
  192. Model string `json:"model"`
  193. Path string `json:"path"`
  194. Modelfile string `json:"modelfile"`
  195. Stream *bool `json:"stream,omitempty"`
  196. Quantize string `json:"quantize,omitempty"`
  197. // Name is deprecated, see Model
  198. Name string `json:"name"`
  199. // Quantization is deprecated, see Quantize
  200. Quantization string `json:"quantization,omitempty"`
  201. }
  202. // DeleteRequest is the request passed to [Client.Delete].
  203. type DeleteRequest struct {
  204. Model string `json:"model"`
  205. // Name is deprecated, see Model
  206. Name string `json:"name"`
  207. }
  208. // ShowRequest is the request passed to [Client.Show].
  209. type ShowRequest struct {
  210. Model string `json:"model"`
  211. System string `json:"system"`
  212. // Template is deprecated
  213. Template string `json:"template"`
  214. Verbose bool `json:"verbose"`
  215. Options map[string]interface{} `json:"options"`
  216. // Name is deprecated, see Model
  217. Name string `json:"name"`
  218. }
  219. // ShowResponse is the response returned from [Client.Show].
  220. type ShowResponse struct {
  221. License string `json:"license,omitempty"`
  222. Modelfile string `json:"modelfile,omitempty"`
  223. Parameters string `json:"parameters,omitempty"`
  224. Template string `json:"template,omitempty"`
  225. System string `json:"system,omitempty"`
  226. Details ModelDetails `json:"details,omitempty"`
  227. Messages []Message `json:"messages,omitempty"`
  228. ModelInfo map[string]any `json:"model_info,omitempty"`
  229. ProjectorInfo map[string]any `json:"projector_info,omitempty"`
  230. ModifiedAt time.Time `json:"modified_at,omitempty"`
  231. }
  232. // CopyRequest is the request passed to [Client.Copy].
  233. type CopyRequest struct {
  234. Source string `json:"source"`
  235. Destination string `json:"destination"`
  236. }
  237. // PullRequest is the request passed to [Client.Pull].
  238. type PullRequest struct {
  239. Model string `json:"model"`
  240. Insecure bool `json:"insecure,omitempty"`
  241. Username string `json:"username"`
  242. Password string `json:"password"`
  243. Stream *bool `json:"stream,omitempty"`
  244. // Name is deprecated, see Model
  245. Name string `json:"name"`
  246. }
  247. // ProgressResponse is the response passed to progress functions like
  248. // [PullProgressFunc] and [PushProgressFunc].
  249. type ProgressResponse struct {
  250. Status string `json:"status"`
  251. Digest string `json:"digest,omitempty"`
  252. Total int64 `json:"total,omitempty"`
  253. Completed int64 `json:"completed,omitempty"`
  254. }
  255. // PushRequest is the request passed to [Client.Push].
  256. type PushRequest struct {
  257. Model string `json:"model"`
  258. Insecure bool `json:"insecure,omitempty"`
  259. Username string `json:"username"`
  260. Password string `json:"password"`
  261. Stream *bool `json:"stream,omitempty"`
  262. // Name is deprecated, see Model
  263. Name string `json:"name"`
  264. }
  265. // ListResponse is the response from [Client.List].
  266. type ListResponse struct {
  267. Models []ListModelResponse `json:"models"`
  268. }
  269. // ProcessResponse is the response from [Client.Process].
  270. type ProcessResponse struct {
  271. Models []ProcessModelResponse `json:"models"`
  272. }
  273. // ListModelResponse is a single model description in [ListResponse].
  274. type ListModelResponse struct {
  275. Name string `json:"name"`
  276. Model string `json:"model"`
  277. ModifiedAt time.Time `json:"modified_at"`
  278. Size int64 `json:"size"`
  279. Digest string `json:"digest"`
  280. Details ModelDetails `json:"details,omitempty"`
  281. }
  282. // ProcessModelResponse is a single model description in [ProcessResponse].
  283. type ProcessModelResponse struct {
  284. Name string `json:"name"`
  285. Model string `json:"model"`
  286. Size int64 `json:"size"`
  287. Digest string `json:"digest"`
  288. Details ModelDetails `json:"details,omitempty"`
  289. ExpiresAt time.Time `json:"expires_at"`
  290. SizeVRAM int64 `json:"size_vram"`
  291. }
  292. type RetrieveModelResponse struct {
  293. Id string `json:"id"`
  294. Object string `json:"object"`
  295. Created int64 `json:"created"`
  296. OwnedBy string `json:"owned_by"`
  297. }
  298. type TokenResponse struct {
  299. Token string `json:"token"`
  300. }
  301. // GenerateResponse is the response passed into [GenerateResponseFunc].
  302. type GenerateResponse struct {
  303. // Model is the model name that generated the response.
  304. Model string `json:"model"`
  305. // CreatedAt is the timestamp of the response.
  306. CreatedAt time.Time `json:"created_at"`
  307. // Response is the textual response itself.
  308. Response string `json:"response"`
  309. // Done specifies if the response is complete.
  310. Done bool `json:"done"`
  311. // DoneReason is the reason the model stopped generating text.
  312. DoneReason string `json:"done_reason,omitempty"`
  313. // Context is an encoding of the conversation used in this response; this
  314. // can be sent in the next request to keep a conversational memory.
  315. Context []int `json:"context,omitempty"`
  316. Metrics
  317. }
  318. // ModelDetails provides details about a model.
  319. type ModelDetails struct {
  320. ParentModel string `json:"parent_model"`
  321. Format string `json:"format"`
  322. Family string `json:"family"`
  323. Families []string `json:"families"`
  324. ParameterSize string `json:"parameter_size"`
  325. QuantizationLevel string `json:"quantization_level"`
  326. }
  327. func (m *Metrics) Summary() {
  328. if m.TotalDuration > 0 {
  329. fmt.Fprintf(os.Stderr, "total duration: %v\n", m.TotalDuration)
  330. }
  331. if m.LoadDuration > 0 {
  332. fmt.Fprintf(os.Stderr, "load duration: %v\n", m.LoadDuration)
  333. }
  334. if m.PromptEvalCount > 0 {
  335. fmt.Fprintf(os.Stderr, "prompt eval count: %d token(s)\n", m.PromptEvalCount)
  336. }
  337. if m.PromptEvalDuration > 0 {
  338. fmt.Fprintf(os.Stderr, "prompt eval duration: %s\n", m.PromptEvalDuration)
  339. fmt.Fprintf(os.Stderr, "prompt eval rate: %.2f tokens/s\n", float64(m.PromptEvalCount)/m.PromptEvalDuration.Seconds())
  340. }
  341. if m.EvalCount > 0 {
  342. fmt.Fprintf(os.Stderr, "eval count: %d token(s)\n", m.EvalCount)
  343. }
  344. if m.EvalDuration > 0 {
  345. fmt.Fprintf(os.Stderr, "eval duration: %s\n", m.EvalDuration)
  346. fmt.Fprintf(os.Stderr, "eval rate: %.2f tokens/s\n", float64(m.EvalCount)/m.EvalDuration.Seconds())
  347. }
  348. }
  349. func (opts *Options) FromMap(m map[string]interface{}) error {
  350. valueOpts := reflect.ValueOf(opts).Elem() // names of the fields in the options struct
  351. typeOpts := reflect.TypeOf(opts).Elem() // types of the fields in the options struct
  352. // build map of json struct tags to their types
  353. jsonOpts := make(map[string]reflect.StructField)
  354. for _, field := range reflect.VisibleFields(typeOpts) {
  355. jsonTag := strings.Split(field.Tag.Get("json"), ",")[0]
  356. if jsonTag != "" {
  357. jsonOpts[jsonTag] = field
  358. }
  359. }
  360. for key, val := range m {
  361. opt, ok := jsonOpts[key]
  362. if !ok {
  363. slog.Warn("invalid option provided", "option", opt.Name)
  364. continue
  365. }
  366. field := valueOpts.FieldByName(opt.Name)
  367. if field.IsValid() && field.CanSet() {
  368. if val == nil {
  369. continue
  370. }
  371. switch field.Kind() {
  372. case reflect.Int:
  373. switch t := val.(type) {
  374. case int64:
  375. field.SetInt(t)
  376. case float64:
  377. // when JSON unmarshals numbers, it uses float64, not int
  378. field.SetInt(int64(t))
  379. default:
  380. return fmt.Errorf("option %q must be of type integer", key)
  381. }
  382. case reflect.Bool:
  383. val, ok := val.(bool)
  384. if !ok {
  385. return fmt.Errorf("option %q must be of type boolean", key)
  386. }
  387. field.SetBool(val)
  388. case reflect.Float32:
  389. // JSON unmarshals to float64
  390. val, ok := val.(float64)
  391. if !ok {
  392. return fmt.Errorf("option %q must be of type float32", key)
  393. }
  394. field.SetFloat(val)
  395. case reflect.String:
  396. val, ok := val.(string)
  397. if !ok {
  398. return fmt.Errorf("option %q must be of type string", key)
  399. }
  400. field.SetString(val)
  401. case reflect.Slice:
  402. // JSON unmarshals to []interface{}, not []string
  403. val, ok := val.([]interface{})
  404. if !ok {
  405. return fmt.Errorf("option %q must be of type array", key)
  406. }
  407. // convert []interface{} to []string
  408. slice := make([]string, len(val))
  409. for i, item := range val {
  410. str, ok := item.(string)
  411. if !ok {
  412. return fmt.Errorf("option %q must be of an array of strings", key)
  413. }
  414. slice[i] = str
  415. }
  416. field.Set(reflect.ValueOf(slice))
  417. case reflect.Pointer:
  418. var b bool
  419. if field.Type() == reflect.TypeOf(&b) {
  420. val, ok := val.(bool)
  421. if !ok {
  422. return fmt.Errorf("option %q must be of type boolean", key)
  423. }
  424. field.Set(reflect.ValueOf(&val))
  425. } else {
  426. return fmt.Errorf("unknown type loading config params: %v %v", field.Kind(), field.Type())
  427. }
  428. default:
  429. return fmt.Errorf("unknown type loading config params: %v", field.Kind())
  430. }
  431. }
  432. }
  433. return nil
  434. }
  435. // DefaultOptions is the default set of options for [GenerateRequest]; these
  436. // values are used unless the user specifies other values explicitly.
  437. func DefaultOptions() Options {
  438. return Options{
  439. // options set on request to runner
  440. NumPredict: -1,
  441. // set a minimal num_keep to avoid issues on context shifts
  442. NumKeep: 4,
  443. Temperature: 0.8,
  444. TopK: 40,
  445. TopP: 0.9,
  446. TFSZ: 1.0,
  447. TypicalP: 1.0,
  448. RepeatLastN: 64,
  449. RepeatPenalty: 1.1,
  450. PresencePenalty: 0.0,
  451. FrequencyPenalty: 0.0,
  452. Mirostat: 0,
  453. MirostatTau: 5.0,
  454. MirostatEta: 0.1,
  455. PenalizeNewline: true,
  456. Seed: -1,
  457. Runner: Runner{
  458. // options set when the model is loaded
  459. NumCtx: 2048,
  460. NumBatch: 512,
  461. NumGPU: -1, // -1 here indicates that NumGPU should be set dynamically
  462. NumThread: 0, // let the runtime decide
  463. LowVRAM: false,
  464. F16KV: true,
  465. UseMLock: false,
  466. UseMMap: nil,
  467. UseNUMA: false,
  468. },
  469. }
  470. }
  471. type Duration struct {
  472. time.Duration
  473. }
  474. func (d Duration) MarshalJSON() ([]byte, error) {
  475. if d.Duration < 0 {
  476. return []byte("-1"), nil
  477. }
  478. return []byte("\"" + d.Duration.String() + "\""), nil
  479. }
  480. func (d *Duration) UnmarshalJSON(b []byte) (err error) {
  481. var v any
  482. if err := json.Unmarshal(b, &v); err != nil {
  483. return err
  484. }
  485. d.Duration = 5 * time.Minute
  486. switch t := v.(type) {
  487. case float64:
  488. if t < 0 {
  489. d.Duration = time.Duration(math.MaxInt64)
  490. } else {
  491. d.Duration = time.Duration(int(t) * int(time.Second))
  492. }
  493. case string:
  494. d.Duration, err = time.ParseDuration(t)
  495. if err != nil {
  496. return err
  497. }
  498. if d.Duration < 0 {
  499. d.Duration = time.Duration(math.MaxInt64)
  500. }
  501. default:
  502. return fmt.Errorf("Unsupported type: '%s'", reflect.TypeOf(v))
  503. }
  504. return nil
  505. }
  506. // FormatParams converts specified parameter options to their correct types
  507. func FormatParams(params map[string][]string) (map[string]interface{}, error) {
  508. opts := Options{}
  509. valueOpts := reflect.ValueOf(&opts).Elem() // names of the fields in the options struct
  510. typeOpts := reflect.TypeOf(opts) // types of the fields in the options struct
  511. // build map of json struct tags to their types
  512. jsonOpts := make(map[string]reflect.StructField)
  513. for _, field := range reflect.VisibleFields(typeOpts) {
  514. jsonTag := strings.Split(field.Tag.Get("json"), ",")[0]
  515. if jsonTag != "" {
  516. jsonOpts[jsonTag] = field
  517. }
  518. }
  519. out := make(map[string]interface{})
  520. // iterate params and set values based on json struct tags
  521. for key, vals := range params {
  522. if opt, ok := jsonOpts[key]; !ok {
  523. return nil, fmt.Errorf("unknown parameter '%s'", key)
  524. } else {
  525. field := valueOpts.FieldByName(opt.Name)
  526. if field.IsValid() && field.CanSet() {
  527. switch field.Kind() {
  528. case reflect.Float32:
  529. floatVal, err := strconv.ParseFloat(vals[0], 32)
  530. if err != nil {
  531. return nil, fmt.Errorf("invalid float value %s", vals)
  532. }
  533. out[key] = float32(floatVal)
  534. case reflect.Int:
  535. intVal, err := strconv.ParseInt(vals[0], 10, 64)
  536. if err != nil {
  537. return nil, fmt.Errorf("invalid int value %s", vals)
  538. }
  539. out[key] = intVal
  540. case reflect.Bool:
  541. boolVal, err := strconv.ParseBool(vals[0])
  542. if err != nil {
  543. return nil, fmt.Errorf("invalid bool value %s", vals)
  544. }
  545. out[key] = boolVal
  546. case reflect.String:
  547. out[key] = vals[0]
  548. case reflect.Slice:
  549. // TODO: only string slices are supported right now
  550. out[key] = vals
  551. case reflect.Pointer:
  552. var b bool
  553. if field.Type() == reflect.TypeOf(&b) {
  554. boolVal, err := strconv.ParseBool(vals[0])
  555. if err != nil {
  556. return nil, fmt.Errorf("invalid bool value %s", vals)
  557. }
  558. out[key] = &boolVal
  559. } else {
  560. return nil, fmt.Errorf("unknown type %s for %s", field.Kind(), key)
  561. }
  562. default:
  563. return nil, fmt.Errorf("unknown type %s for %s", field.Kind(), key)
  564. }
  565. }
  566. }
  567. }
  568. return out, nil
  569. }