types.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package api
  2. import (
  3. "fmt"
  4. "net/http"
  5. "strings"
  6. )
  7. type Error struct {
  8. Code int32 `json:"code"`
  9. Message string `json:"message"`
  10. }
  11. func (e Error) Error() string {
  12. if e.Message == "" {
  13. return fmt.Sprintf("%d %v", e.Code, strings.ToLower(http.StatusText(int(e.Code))))
  14. }
  15. return e.Message
  16. }
  17. type PullRequest struct {
  18. Model string `json:"model"`
  19. }
  20. type PullProgress struct {
  21. Total int64 `json:"total"`
  22. Completed int64 `json:"completed"`
  23. Percent float64 `json:"percent"`
  24. }
  25. type GenerateRequest struct {
  26. Model string `json:"model"`
  27. Prompt string `json:"prompt"`
  28. ModelOptions `json:"model_opts"`
  29. PredictOptions `json:"predict_opts"`
  30. }
  31. type ModelOptions struct {
  32. ContextSize int `json:"context_size"`
  33. Seed int `json:"seed"`
  34. NBatch int `json:"n_batch"`
  35. F16Memory bool `json:"memory_f16"`
  36. MLock bool `json:"mlock"`
  37. MMap bool `json:"mmap"`
  38. VocabOnly bool `json:"vocab_only"`
  39. LowVRAM bool `json:"low_vram"`
  40. Embeddings bool `json:"embeddings"`
  41. NUMA bool `json:"numa"`
  42. NGPULayers int `json:"gpu_layers"`
  43. MainGPU string `json:"main_gpu"`
  44. TensorSplit string `json:"tensor_split"`
  45. }
  46. type PredictOptions struct {
  47. Seed int `json:"seed"`
  48. Threads int `json:"threads"`
  49. Tokens int `json:"tokens"`
  50. TopK int `json:"top_k"`
  51. Repeat int `json:"repeat"`
  52. Batch int `json:"batch"`
  53. NKeep int `json:"nkeep"`
  54. TopP float64 `json:"top_p"`
  55. Temperature float64 `json:"temp"`
  56. Penalty float64 `json:"penalty"`
  57. F16KV bool
  58. DebugMode bool
  59. StopPrompts []string
  60. IgnoreEOS bool `json:"ignore_eos"`
  61. TailFreeSamplingZ float64 `json:"tfs_z"`
  62. TypicalP float64 `json:"typical_p"`
  63. FrequencyPenalty float64 `json:"freq_penalty"`
  64. PresencePenalty float64 `json:"pres_penalty"`
  65. Mirostat int `json:"mirostat"`
  66. MirostatETA float64 `json:"mirostat_lr"`
  67. MirostatTAU float64 `json:"mirostat_ent"`
  68. PenalizeNL bool `json:"penalize_nl"`
  69. LogitBias string `json:"logit_bias"`
  70. PathPromptCache string
  71. MLock bool `json:"mlock"`
  72. MMap bool `json:"mmap"`
  73. PromptCacheAll bool
  74. PromptCacheRO bool
  75. MainGPU string
  76. TensorSplit string
  77. }
  78. var DefaultModelOptions ModelOptions = ModelOptions{
  79. ContextSize: 128,
  80. Seed: 0,
  81. F16Memory: true,
  82. MLock: false,
  83. Embeddings: true,
  84. MMap: true,
  85. LowVRAM: false,
  86. }
  87. var DefaultPredictOptions PredictOptions = PredictOptions{
  88. Seed: -1,
  89. Threads: -1,
  90. Tokens: 512,
  91. Penalty: 1.1,
  92. Repeat: 64,
  93. Batch: 512,
  94. NKeep: 64,
  95. TopK: 90,
  96. TopP: 0.86,
  97. TailFreeSamplingZ: 1.0,
  98. TypicalP: 1.0,
  99. Temperature: 0.8,
  100. FrequencyPenalty: 0.0,
  101. PresencePenalty: 0.0,
  102. Mirostat: 0,
  103. MirostatTAU: 5.0,
  104. MirostatETA: 0.1,
  105. MMap: true,
  106. StopPrompts: []string{"llama"},
  107. }
  108. type GenerateResponse struct {
  109. Response string `json:"response"`
  110. }