interfaces.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. export type Fetch = typeof fetch
  2. export interface Config {
  3. host: string
  4. fetch?: Fetch
  5. proxy?: boolean
  6. headers?: HeadersInit
  7. }
  8. // request types
  9. export interface Options {
  10. numa: boolean
  11. num_ctx: number
  12. num_batch: number
  13. num_gpu: number
  14. main_gpu: number
  15. low_vram: boolean
  16. f16_kv: boolean
  17. logits_all: boolean
  18. vocab_only: boolean
  19. use_mmap: boolean
  20. use_mlock: boolean
  21. embedding_only: boolean
  22. num_thread: number
  23. // Runtime options
  24. num_keep: number
  25. seed: number
  26. num_predict: number
  27. top_k: number
  28. top_p: number
  29. tfs_z: number
  30. typical_p: number
  31. repeat_last_n: number
  32. temperature: number
  33. repeat_penalty: number
  34. presence_penalty: number
  35. frequency_penalty: number
  36. mirostat: number
  37. mirostat_tau: number
  38. mirostat_eta: number
  39. penalize_newline: boolean
  40. stop: string[]
  41. }
  42. export interface GenerateRequest {
  43. model: string
  44. prompt: string
  45. suffix?: string
  46. system?: string
  47. template?: string
  48. context?: number[]
  49. stream?: boolean
  50. raw?: boolean
  51. format?: string | object
  52. images?: Uint8Array[] | string[]
  53. keep_alive?: string | number // a number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc)
  54. options?: Partial<Options>
  55. }
  56. export interface Message {
  57. role: string
  58. content: string
  59. images?: Uint8Array[] | string[]
  60. tool_calls?: ToolCall[]
  61. }
  62. export interface ToolCall {
  63. function: {
  64. name: string;
  65. arguments: {
  66. [key: string]: any;
  67. };
  68. };
  69. }
  70. export interface Tool {
  71. type: string;
  72. function: {
  73. name?: string;
  74. description?: string;
  75. type?: string;
  76. parameters?: {
  77. type?: string;
  78. $defs?: any;
  79. items?: any;
  80. required?: string[];
  81. properties?: {
  82. [key: string]: {
  83. type?: string | string[];
  84. items?: any;
  85. description?: string;
  86. enum?: any[];
  87. };
  88. };
  89. };
  90. };
  91. }
  92. export interface ChatRequest {
  93. model: string
  94. messages?: Message[]
  95. stream?: boolean
  96. format?: string | object
  97. keep_alive?: string | number // a number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc)
  98. tools?: Tool[]
  99. options?: Partial<Options>
  100. }
  101. export interface PullRequest {
  102. model: string
  103. insecure?: boolean
  104. stream?: boolean
  105. }
  106. export interface PushRequest {
  107. model: string
  108. insecure?: boolean
  109. stream?: boolean
  110. }
  111. export interface CreateRequest {
  112. model: string
  113. from?: string
  114. stream?: boolean
  115. quantize?: string
  116. template?: string
  117. license?: string | string[]
  118. system?: string
  119. parameters?: Record<string, unknown>
  120. messages?: Message[]
  121. adapters?: Record<string, string>
  122. }
  123. export interface DeleteRequest {
  124. model: string
  125. }
  126. export interface CopyRequest {
  127. source: string
  128. destination: string
  129. }
  130. export interface ShowRequest {
  131. model: string
  132. system?: string
  133. template?: string
  134. options?: Partial<Options>
  135. }
  136. export interface EmbedRequest {
  137. model: string
  138. input: string | string[]
  139. truncate?: boolean
  140. keep_alive?: string | number // a number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc)
  141. options?: Partial<Options>
  142. }
  143. export interface EmbeddingsRequest {
  144. model: string
  145. prompt: string
  146. keep_alive?: string | number // a number (seconds) or a string with a duration unit suffix ("300ms", "1.5h", "2h45m", etc)
  147. options?: Partial<Options>
  148. }
  149. // response types
  150. export interface GenerateResponse {
  151. model: string
  152. created_at: Date
  153. response: string
  154. done: boolean
  155. done_reason: string
  156. context: number[]
  157. total_duration: number
  158. load_duration: number
  159. prompt_eval_count: number
  160. prompt_eval_duration: number
  161. eval_count: number
  162. eval_duration: number
  163. }
  164. export interface ChatResponse {
  165. model: string
  166. created_at: Date
  167. message: Message
  168. done: boolean
  169. done_reason: string
  170. total_duration: number
  171. load_duration: number
  172. prompt_eval_count: number
  173. prompt_eval_duration: number
  174. eval_count: number
  175. eval_duration: number
  176. }
  177. export interface EmbedResponse {
  178. model: string
  179. embeddings: number[][]
  180. total_duration: number
  181. load_duration: number
  182. prompt_eval_count: number
  183. }
  184. export interface EmbeddingsResponse {
  185. embedding: number[]
  186. }
  187. export interface ProgressResponse {
  188. status: string
  189. digest: string
  190. total: number
  191. completed: number
  192. }
  193. export interface ModelResponse {
  194. name: string
  195. modified_at: Date
  196. model: string
  197. size: number
  198. digest: string
  199. details: ModelDetails
  200. expires_at: Date
  201. size_vram: number
  202. }
  203. export interface ModelDetails {
  204. parent_model: string
  205. format: string
  206. family: string
  207. families: string[]
  208. parameter_size: string
  209. quantization_level: string
  210. }
  211. export interface ShowResponse {
  212. license: string
  213. modelfile: string
  214. parameters: string
  215. template: string
  216. system: string
  217. details: ModelDetails
  218. messages: Message[]
  219. modified_at: Date
  220. model_info: Map<string, any>
  221. projector_info?: Map<string, any>
  222. }
  223. export interface ListResponse {
  224. models: ModelResponse[]
  225. }
  226. export interface ErrorResponse {
  227. error: string
  228. }
  229. export interface StatusResponse {
  230. status: string
  231. }