interface.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import { ContentItem, OutputText, Refusal } from "../foundation";
  2. export interface ChatCompletion {
  3. id?: string;
  4. object?: string;
  5. created?: number;
  6. model?: string;
  7. choices?: Choice[];
  8. usage?: Usage;
  9. service_tier?: string;
  10. system_fingerprint?: string
  11. }
  12. export interface ChatCompletionChunk {
  13. id?: string;
  14. object?: string;
  15. created?: number;
  16. model?: string;
  17. choices?: ChoiceChunk[];
  18. usage?: Usage;
  19. service_tier?: string;
  20. system_fingerprint?: string
  21. }
  22. export interface Choice {
  23. index?: number;
  24. message?: ChatCompletionMessage;
  25. logprobs?: Logprobs;
  26. finish_reason?: string
  27. }
  28. export interface ChoiceChunk {
  29. index?: number;
  30. delta?: Delta;
  31. logprobs?: Logprobs;
  32. finish_reason?: string
  33. }
  34. export interface Delta {
  35. role?: string;
  36. content?: string;
  37. refusal?: string;
  38. function_call?: FunctionCall;
  39. tool_calls?: ChatCompletionToolCall[]
  40. }
  41. interface ChatCompletionMessage {
  42. role?: string;
  43. content?: string;
  44. refusal?: string;
  45. annotations?: ChatCompletionAnnotation[];
  46. audio?: Audio;
  47. function_call?: FunctionCall;
  48. tool_calls?: ChatCompletionToolCalls[]
  49. }
  50. export type ChatCompletionToolCalls = ChatCompletionToolCall | ChatCompletionCustomToolCall
  51. interface ChatCompletionAnnotation {
  52. type?: string;
  53. url_citation?: URLCitation
  54. }
  55. interface URLCitation {
  56. end_index?: number;
  57. start_index?: number;
  58. title?: string;
  59. url?: string
  60. }
  61. interface Audio {
  62. data: string;
  63. expires_at?: number;
  64. id?: string;
  65. transcript?: string
  66. }
  67. interface FunctionCall {
  68. name?: string;
  69. arguments?: string
  70. }
  71. interface ToolCall {
  72. input?: string;
  73. name?: string
  74. }
  75. export interface ChatCompletionToolCall {
  76. id?: string;
  77. index?: number;
  78. type?: string;
  79. function?: FunctionCall;
  80. custom?: ToolCall
  81. }
  82. export interface ChatCompletionCustomToolCall {
  83. id?: string;
  84. type?: string;
  85. custom?: ToolCall
  86. }
  87. interface Logprobs {
  88. content?: LogprobsContent[];
  89. refusal?: LogprobsContent[]
  90. }
  91. interface LogprobsContent {
  92. bytes?: number[];
  93. logprob?: number;
  94. token?: string;
  95. top_logprobs?: LogprobsContent[]
  96. }
  97. interface Usage {
  98. prompt_tokens?: number;
  99. completion_tokens?: number;
  100. total_tokens?: number;
  101. completion_tokens_details?: CompletionTokensDetails;
  102. prompt_tokens_details?: PromptTokensDetails
  103. }
  104. interface CompletionTokensDetails {
  105. reasoning_tokens?: number;
  106. audio_tokens?: number;
  107. accepted_prediction_tokens?: number;
  108. rejected_prediction_tokens?: number
  109. }
  110. interface PromptTokensDetails {
  111. cached_tokens?: number;
  112. audio_tokens?: number
  113. }
  114. export interface Response {
  115. id?: string;
  116. created_at?: number;
  117. error?: ResponseError;
  118. incomplete_details?: {
  119. reason: string
  120. };
  121. max_output_tokens?: number;
  122. max_tool_calls?: number;
  123. model?: string;
  124. object?: string;
  125. output?: ContentItem | ContentItem[];
  126. output_text?: string;
  127. parallel_tool_calls?: boolean;
  128. previous_response_id?: string;
  129. reasoning?: ResponseReasoning;
  130. safety_identifier?: string;
  131. status?: string;
  132. temperature?: number;
  133. top_logprobs?: number;
  134. top_p?: number;
  135. truncation?: string;
  136. [x: string]: any
  137. }
  138. export interface ResponseError {
  139. code?: string;
  140. message?: string
  141. }
  142. interface ResponseReasoning {
  143. effort?: string;
  144. generate_summary?: string;
  145. summary?: string
  146. }
  147. export interface ResponseChunk {
  148. type?: string;
  149. response?: Response;
  150. sequence_number?: number;
  151. output_index?: number;
  152. item?: ContentItem;
  153. content_index?: number;
  154. item_id?: string;
  155. part?: OutputText | Refusal | ReasoningText;
  156. delta?: string;
  157. refusal?: string;
  158. name?: string;
  159. arguments?: string;
  160. summary_index?: number;
  161. text?: string;
  162. code?: string;
  163. message?: string;
  164. param?: string;
  165. [x: string]: any
  166. }
  167. interface ReasoningText {
  168. text?: string;
  169. type?: string
  170. }
  171. export interface CodeInterpreterCall {
  172. code?: string;
  173. status?: string;
  174. outputs?: {
  175. logs?: string;
  176. url?: string;
  177. type?: string
  178. }[];
  179. id?: string;
  180. container_id?: string;
  181. type?: string
  182. }
  183. export interface ImageGenerationCall {
  184. id?: string;
  185. result?: string;
  186. status?: string;
  187. type?: string
  188. }
  189. // chat completion input
  190. export interface ChatCompletionInput {
  191. messages?: ChatCompletionInputMessage[];
  192. model?: string;
  193. audio?: {
  194. format: string;
  195. voice: string
  196. };
  197. function_call?: string | { name: string };
  198. functions?: { name: string; description: string }[];
  199. n?: number;
  200. modalities?: string[];
  201. [x: string]: any
  202. }
  203. export type ChatCompletionInputMessage = DeveloperMessage | SystemMessage | UserMessage | AssistantMessage | ToolMessage | FunctionMessage;
  204. interface CommonInputItem {
  205. role?: string;
  206. name?: string
  207. }
  208. interface DeveloperMessage extends CommonInputItem {
  209. content?: string | { type: string; text: string }[]
  210. }
  211. interface SystemMessage extends CommonInputItem {
  212. content?: string | any[]
  213. }
  214. export interface UserMessage extends CommonInputItem {
  215. content?: string | (ImageContentPart | AudioContentPart | FileContentPart | TextInput)[]
  216. }
  217. export interface TextInput {
  218. text?: string;
  219. type?: string
  220. }
  221. export interface ImageContentPart {
  222. image_url?: {
  223. url?: string;
  224. detail?: string
  225. };
  226. type?: string
  227. }
  228. export interface AudioContentPart {
  229. input_audio?: {
  230. data?: string;
  231. format?: string
  232. };
  233. type?: string
  234. }
  235. export interface FileContentPart {
  236. file?: {
  237. file_data?: string;
  238. file_id?: string;
  239. filename?: string
  240. };
  241. type?: string
  242. }
  243. interface AssistantMessage extends CommonInputItem {
  244. audio?: { id: string };
  245. content?: string | (OutputText | Refusal)[];
  246. function_call?: { name: string; arguments: string };
  247. name?: string;
  248. refusal?: string;
  249. tool_calls?: (ChatCompletionToolCall | ChatCompletionCustomToolCall)[]
  250. }
  251. interface ToolMessage extends CommonInputItem {
  252. content?: string | any[]
  253. }
  254. interface FunctionMessage extends CommonInputItem {
  255. content?: string
  256. }
  257. export interface StreamingResponseState {
  258. processedSeq: Set<number>;
  259. outputs: Map<number, ContentItem | null>;
  260. meta: {
  261. id?: string;
  262. model?: string;
  263. status?: string;
  264. created_at?: number
  265. };
  266. error?: ResponseError;
  267. buffer: Map<number, ResponseChunk>;
  268. lastProcessedSeq: number
  269. }