threads.d.ts 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. import { APIResource } from "../../../resource.js";
  2. import { AssistantStream, ThreadCreateAndRunParamsBaseStream } from "../../../lib/AssistantStream.js";
  3. import { APIPromise } from "../../../core.js";
  4. import * as Core from "../../../core.js";
  5. import * as ThreadsAPI from "./threads.js";
  6. import * as Shared from "../../shared.js";
  7. import * as AssistantsAPI from "../assistants.js";
  8. import * as MessagesAPI from "./messages.js";
  9. import { Annotation, AnnotationDelta, FileCitationAnnotation, FileCitationDeltaAnnotation, FilePathAnnotation, FilePathDeltaAnnotation, ImageFile, ImageFileContentBlock, ImageFileDelta, ImageFileDeltaBlock, ImageURL, ImageURLContentBlock, ImageURLDelta, ImageURLDeltaBlock, Message as MessagesAPIMessage, MessageContent, MessageContentDelta, MessageContentPartParam, MessageCreateParams, MessageDeleted, MessageDelta, MessageDeltaEvent, MessageListParams, MessageUpdateParams, Messages, MessagesPage, RefusalContentBlock, RefusalDeltaBlock, Text, TextContentBlock, TextContentBlockParam, TextDelta, TextDeltaBlock } from "./messages.js";
  10. import * as RunsAPI from "./runs/runs.js";
  11. import { RequiredActionFunctionToolCall, Run, RunCreateAndPollParams, RunCreateAndStreamParams, RunCreateParams, RunCreateParamsNonStreaming, RunCreateParamsStreaming, RunListParams, RunStatus, RunStreamParams, RunSubmitToolOutputsAndPollParams, RunSubmitToolOutputsParams, RunSubmitToolOutputsParamsNonStreaming, RunSubmitToolOutputsParamsStreaming, RunSubmitToolOutputsStreamParams, RunUpdateParams, Runs, RunsPage } from "./runs/runs.js";
  12. import { Stream } from "../../../streaming.js";
  13. /**
  14. * @deprecated The Assistants API is deprecated in favor of the Responses API
  15. */
  16. export declare class Threads extends APIResource {
  17. runs: RunsAPI.Runs;
  18. messages: MessagesAPI.Messages;
  19. /**
  20. * Create a thread.
  21. *
  22. * @deprecated The Assistants API is deprecated in favor of the Responses API
  23. */
  24. create(body?: ThreadCreateParams, options?: Core.RequestOptions): Core.APIPromise<Thread>;
  25. create(options?: Core.RequestOptions): Core.APIPromise<Thread>;
  26. /**
  27. * Retrieves a thread.
  28. *
  29. * @deprecated The Assistants API is deprecated in favor of the Responses API
  30. */
  31. retrieve(threadId: string, options?: Core.RequestOptions): Core.APIPromise<Thread>;
  32. /**
  33. * Modifies a thread.
  34. *
  35. * @deprecated The Assistants API is deprecated in favor of the Responses API
  36. */
  37. update(threadId: string, body: ThreadUpdateParams, options?: Core.RequestOptions): Core.APIPromise<Thread>;
  38. /**
  39. * Delete a thread.
  40. *
  41. * @deprecated The Assistants API is deprecated in favor of the Responses API
  42. */
  43. del(threadId: string, options?: Core.RequestOptions): Core.APIPromise<ThreadDeleted>;
  44. /**
  45. * Create a thread and run it in one request.
  46. *
  47. * @deprecated The Assistants API is deprecated in favor of the Responses API
  48. */
  49. createAndRun(body: ThreadCreateAndRunParamsNonStreaming, options?: Core.RequestOptions): APIPromise<RunsAPI.Run>;
  50. createAndRun(body: ThreadCreateAndRunParamsStreaming, options?: Core.RequestOptions): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent>>;
  51. createAndRun(body: ThreadCreateAndRunParamsBase, options?: Core.RequestOptions): APIPromise<Stream<AssistantsAPI.AssistantStreamEvent> | RunsAPI.Run>;
  52. /**
  53. * A helper to create a thread, start a run and then poll for a terminal state.
  54. * More information on Run lifecycles can be found here:
  55. * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
  56. */
  57. createAndRunPoll(body: ThreadCreateAndRunParamsNonStreaming, options?: Core.RequestOptions & {
  58. pollIntervalMs?: number;
  59. }): Promise<Threads.Run>;
  60. /**
  61. * Create a thread and stream the run back
  62. */
  63. createAndRunStream(body: ThreadCreateAndRunParamsBaseStream, options?: Core.RequestOptions): AssistantStream;
  64. }
  65. /**
  66. * Specifies the format that the model must output. Compatible with
  67. * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
  68. * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
  69. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  70. *
  71. * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
  72. * Outputs which ensures the model will match your supplied JSON schema. Learn more
  73. * in the
  74. * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
  75. *
  76. * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
  77. * message the model generates is valid JSON.
  78. *
  79. * **Important:** when using JSON mode, you **must** also instruct the model to
  80. * produce JSON yourself via a system or user message. Without this, the model may
  81. * generate an unending stream of whitespace until the generation reaches the token
  82. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  83. * the message content may be partially cut off if `finish_reason="length"`, which
  84. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  85. * max context length.
  86. */
  87. export type AssistantResponseFormatOption = 'auto' | Shared.ResponseFormatText | Shared.ResponseFormatJSONObject | Shared.ResponseFormatJSONSchema;
  88. /**
  89. * Specifies a tool the model should use. Use to force the model to call a specific
  90. * tool.
  91. */
  92. export interface AssistantToolChoice {
  93. /**
  94. * The type of the tool. If type is `function`, the function name must be set
  95. */
  96. type: 'function' | 'code_interpreter' | 'file_search';
  97. function?: AssistantToolChoiceFunction;
  98. }
  99. export interface AssistantToolChoiceFunction {
  100. /**
  101. * The name of the function to call.
  102. */
  103. name: string;
  104. }
  105. /**
  106. * Controls which (if any) tool is called by the model. `none` means the model will
  107. * not call any tools and instead generates a message. `auto` is the default value
  108. * and means the model can pick between generating a message or calling one or more
  109. * tools. `required` means the model must call one or more tools before responding
  110. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  111. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  112. * call that tool.
  113. */
  114. export type AssistantToolChoiceOption = 'none' | 'auto' | 'required' | AssistantToolChoice;
  115. /**
  116. * Represents a thread that contains
  117. * [messages](https://platform.openai.com/docs/api-reference/messages).
  118. */
  119. export interface Thread {
  120. /**
  121. * The identifier, which can be referenced in API endpoints.
  122. */
  123. id: string;
  124. /**
  125. * The Unix timestamp (in seconds) for when the thread was created.
  126. */
  127. created_at: number;
  128. /**
  129. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  130. * for storing additional information about the object in a structured format, and
  131. * querying for objects via API or the dashboard.
  132. *
  133. * Keys are strings with a maximum length of 64 characters. Values are strings with
  134. * a maximum length of 512 characters.
  135. */
  136. metadata: Shared.Metadata | null;
  137. /**
  138. * The object type, which is always `thread`.
  139. */
  140. object: 'thread';
  141. /**
  142. * A set of resources that are made available to the assistant's tools in this
  143. * thread. The resources are specific to the type of tool. For example, the
  144. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  145. * tool requires a list of vector store IDs.
  146. */
  147. tool_resources: Thread.ToolResources | null;
  148. }
  149. export declare namespace Thread {
  150. /**
  151. * A set of resources that are made available to the assistant's tools in this
  152. * thread. The resources are specific to the type of tool. For example, the
  153. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  154. * tool requires a list of vector store IDs.
  155. */
  156. interface ToolResources {
  157. code_interpreter?: ToolResources.CodeInterpreter;
  158. file_search?: ToolResources.FileSearch;
  159. }
  160. namespace ToolResources {
  161. interface CodeInterpreter {
  162. /**
  163. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  164. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  165. * associated with the tool.
  166. */
  167. file_ids?: Array<string>;
  168. }
  169. interface FileSearch {
  170. /**
  171. * The
  172. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  173. * attached to this thread. There can be a maximum of 1 vector store attached to
  174. * the thread.
  175. */
  176. vector_store_ids?: Array<string>;
  177. }
  178. }
  179. }
  180. export interface ThreadDeleted {
  181. id: string;
  182. deleted: boolean;
  183. object: 'thread.deleted';
  184. }
  185. export interface ThreadCreateParams {
  186. /**
  187. * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
  188. * start the thread with.
  189. */
  190. messages?: Array<ThreadCreateParams.Message>;
  191. /**
  192. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  193. * for storing additional information about the object in a structured format, and
  194. * querying for objects via API or the dashboard.
  195. *
  196. * Keys are strings with a maximum length of 64 characters. Values are strings with
  197. * a maximum length of 512 characters.
  198. */
  199. metadata?: Shared.Metadata | null;
  200. /**
  201. * A set of resources that are made available to the assistant's tools in this
  202. * thread. The resources are specific to the type of tool. For example, the
  203. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  204. * tool requires a list of vector store IDs.
  205. */
  206. tool_resources?: ThreadCreateParams.ToolResources | null;
  207. }
  208. export declare namespace ThreadCreateParams {
  209. interface Message {
  210. /**
  211. * The text contents of the message.
  212. */
  213. content: string | Array<MessagesAPI.MessageContentPartParam>;
  214. /**
  215. * The role of the entity that is creating the message. Allowed values include:
  216. *
  217. * - `user`: Indicates the message is sent by an actual user and should be used in
  218. * most cases to represent user-generated messages.
  219. * - `assistant`: Indicates the message is generated by the assistant. Use this
  220. * value to insert messages from the assistant into the conversation.
  221. */
  222. role: 'user' | 'assistant';
  223. /**
  224. * A list of files attached to the message, and the tools they should be added to.
  225. */
  226. attachments?: Array<Message.Attachment> | null;
  227. /**
  228. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  229. * for storing additional information about the object in a structured format, and
  230. * querying for objects via API or the dashboard.
  231. *
  232. * Keys are strings with a maximum length of 64 characters. Values are strings with
  233. * a maximum length of 512 characters.
  234. */
  235. metadata?: Shared.Metadata | null;
  236. }
  237. namespace Message {
  238. interface Attachment {
  239. /**
  240. * The ID of the file to attach to the message.
  241. */
  242. file_id?: string;
  243. /**
  244. * The tools to add this file to.
  245. */
  246. tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;
  247. }
  248. namespace Attachment {
  249. interface FileSearch {
  250. /**
  251. * The type of tool being defined: `file_search`
  252. */
  253. type: 'file_search';
  254. }
  255. }
  256. }
  257. /**
  258. * A set of resources that are made available to the assistant's tools in this
  259. * thread. The resources are specific to the type of tool. For example, the
  260. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  261. * tool requires a list of vector store IDs.
  262. */
  263. interface ToolResources {
  264. code_interpreter?: ToolResources.CodeInterpreter;
  265. file_search?: ToolResources.FileSearch;
  266. }
  267. namespace ToolResources {
  268. interface CodeInterpreter {
  269. /**
  270. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  271. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  272. * associated with the tool.
  273. */
  274. file_ids?: Array<string>;
  275. }
  276. interface FileSearch {
  277. /**
  278. * The
  279. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  280. * attached to this thread. There can be a maximum of 1 vector store attached to
  281. * the thread.
  282. */
  283. vector_store_ids?: Array<string>;
  284. /**
  285. * A helper to create a
  286. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  287. * with file_ids and attach it to this thread. There can be a maximum of 1 vector
  288. * store attached to the thread.
  289. */
  290. vector_stores?: Array<FileSearch.VectorStore>;
  291. }
  292. namespace FileSearch {
  293. interface VectorStore {
  294. /**
  295. * The chunking strategy used to chunk the file(s). If not set, will use the `auto`
  296. * strategy.
  297. */
  298. chunking_strategy?: VectorStore.Auto | VectorStore.Static;
  299. /**
  300. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
  301. * add to the vector store. There can be a maximum of 10000 files in a vector
  302. * store.
  303. */
  304. file_ids?: Array<string>;
  305. /**
  306. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  307. * for storing additional information about the object in a structured format, and
  308. * querying for objects via API or the dashboard.
  309. *
  310. * Keys are strings with a maximum length of 64 characters. Values are strings with
  311. * a maximum length of 512 characters.
  312. */
  313. metadata?: Shared.Metadata | null;
  314. }
  315. namespace VectorStore {
  316. /**
  317. * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
  318. * `800` and `chunk_overlap_tokens` of `400`.
  319. */
  320. interface Auto {
  321. /**
  322. * Always `auto`.
  323. */
  324. type: 'auto';
  325. }
  326. interface Static {
  327. static: Static.Static;
  328. /**
  329. * Always `static`.
  330. */
  331. type: 'static';
  332. }
  333. namespace Static {
  334. interface Static {
  335. /**
  336. * The number of tokens that overlap between chunks. The default value is `400`.
  337. *
  338. * Note that the overlap must not exceed half of `max_chunk_size_tokens`.
  339. */
  340. chunk_overlap_tokens: number;
  341. /**
  342. * The maximum number of tokens in each chunk. The default value is `800`. The
  343. * minimum value is `100` and the maximum value is `4096`.
  344. */
  345. max_chunk_size_tokens: number;
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. export interface ThreadUpdateParams {
  353. /**
  354. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  355. * for storing additional information about the object in a structured format, and
  356. * querying for objects via API or the dashboard.
  357. *
  358. * Keys are strings with a maximum length of 64 characters. Values are strings with
  359. * a maximum length of 512 characters.
  360. */
  361. metadata?: Shared.Metadata | null;
  362. /**
  363. * A set of resources that are made available to the assistant's tools in this
  364. * thread. The resources are specific to the type of tool. For example, the
  365. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  366. * tool requires a list of vector store IDs.
  367. */
  368. tool_resources?: ThreadUpdateParams.ToolResources | null;
  369. }
  370. export declare namespace ThreadUpdateParams {
  371. /**
  372. * A set of resources that are made available to the assistant's tools in this
  373. * thread. The resources are specific to the type of tool. For example, the
  374. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  375. * tool requires a list of vector store IDs.
  376. */
  377. interface ToolResources {
  378. code_interpreter?: ToolResources.CodeInterpreter;
  379. file_search?: ToolResources.FileSearch;
  380. }
  381. namespace ToolResources {
  382. interface CodeInterpreter {
  383. /**
  384. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  385. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  386. * associated with the tool.
  387. */
  388. file_ids?: Array<string>;
  389. }
  390. interface FileSearch {
  391. /**
  392. * The
  393. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  394. * attached to this thread. There can be a maximum of 1 vector store attached to
  395. * the thread.
  396. */
  397. vector_store_ids?: Array<string>;
  398. }
  399. }
  400. }
  401. export type ThreadCreateAndRunParams = ThreadCreateAndRunParamsNonStreaming | ThreadCreateAndRunParamsStreaming;
  402. export interface ThreadCreateAndRunParamsBase {
  403. /**
  404. * The ID of the
  405. * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
  406. * execute this run.
  407. */
  408. assistant_id: string;
  409. /**
  410. * Override the default system message of the assistant. This is useful for
  411. * modifying the behavior on a per-run basis.
  412. */
  413. instructions?: string | null;
  414. /**
  415. * The maximum number of completion tokens that may be used over the course of the
  416. * run. The run will make a best effort to use only the number of completion tokens
  417. * specified, across multiple turns of the run. If the run exceeds the number of
  418. * completion tokens specified, the run will end with status `incomplete`. See
  419. * `incomplete_details` for more info.
  420. */
  421. max_completion_tokens?: number | null;
  422. /**
  423. * The maximum number of prompt tokens that may be used over the course of the run.
  424. * The run will make a best effort to use only the number of prompt tokens
  425. * specified, across multiple turns of the run. If the run exceeds the number of
  426. * prompt tokens specified, the run will end with status `incomplete`. See
  427. * `incomplete_details` for more info.
  428. */
  429. max_prompt_tokens?: number | null;
  430. /**
  431. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  432. * for storing additional information about the object in a structured format, and
  433. * querying for objects via API or the dashboard.
  434. *
  435. * Keys are strings with a maximum length of 64 characters. Values are strings with
  436. * a maximum length of 512 characters.
  437. */
  438. metadata?: Shared.Metadata | null;
  439. /**
  440. * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
  441. * be used to execute this run. If a value is provided here, it will override the
  442. * model associated with the assistant. If not, the model associated with the
  443. * assistant will be used.
  444. */
  445. model?: (string & {}) | Shared.ChatModel | null;
  446. /**
  447. * Whether to enable
  448. * [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
  449. * during tool use.
  450. */
  451. parallel_tool_calls?: boolean;
  452. /**
  453. * Specifies the format that the model must output. Compatible with
  454. * [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
  455. * [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
  456. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  457. *
  458. * Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
  459. * Outputs which ensures the model will match your supplied JSON schema. Learn more
  460. * in the
  461. * [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
  462. *
  463. * Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
  464. * message the model generates is valid JSON.
  465. *
  466. * **Important:** when using JSON mode, you **must** also instruct the model to
  467. * produce JSON yourself via a system or user message. Without this, the model may
  468. * generate an unending stream of whitespace until the generation reaches the token
  469. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  470. * the message content may be partially cut off if `finish_reason="length"`, which
  471. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  472. * max context length.
  473. */
  474. response_format?: AssistantResponseFormatOption | null;
  475. /**
  476. * If `true`, returns a stream of events that happen during the Run as server-sent
  477. * events, terminating when the Run enters a terminal state with a `data: [DONE]`
  478. * message.
  479. */
  480. stream?: boolean | null;
  481. /**
  482. * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
  483. * make the output more random, while lower values like 0.2 will make it more
  484. * focused and deterministic.
  485. */
  486. temperature?: number | null;
  487. /**
  488. * Options to create a new thread. If no thread is provided when running a request,
  489. * an empty thread will be created.
  490. */
  491. thread?: ThreadCreateAndRunParams.Thread;
  492. /**
  493. * Controls which (if any) tool is called by the model. `none` means the model will
  494. * not call any tools and instead generates a message. `auto` is the default value
  495. * and means the model can pick between generating a message or calling one or more
  496. * tools. `required` means the model must call one or more tools before responding
  497. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  498. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  499. * call that tool.
  500. */
  501. tool_choice?: AssistantToolChoiceOption | null;
  502. /**
  503. * A set of resources that are used by the assistant's tools. The resources are
  504. * specific to the type of tool. For example, the `code_interpreter` tool requires
  505. * a list of file IDs, while the `file_search` tool requires a list of vector store
  506. * IDs.
  507. */
  508. tool_resources?: ThreadCreateAndRunParams.ToolResources | null;
  509. /**
  510. * Override the tools the assistant can use for this run. This is useful for
  511. * modifying the behavior on a per-run basis.
  512. */
  513. tools?: Array<AssistantsAPI.AssistantTool> | null;
  514. /**
  515. * An alternative to sampling with temperature, called nucleus sampling, where the
  516. * model considers the results of the tokens with top_p probability mass. So 0.1
  517. * means only the tokens comprising the top 10% probability mass are considered.
  518. *
  519. * We generally recommend altering this or temperature but not both.
  520. */
  521. top_p?: number | null;
  522. /**
  523. * Controls for how a thread will be truncated prior to the run. Use this to
  524. * control the intial context window of the run.
  525. */
  526. truncation_strategy?: ThreadCreateAndRunParams.TruncationStrategy | null;
  527. }
  528. export declare namespace ThreadCreateAndRunParams {
  529. /**
  530. * Options to create a new thread. If no thread is provided when running a request,
  531. * an empty thread will be created.
  532. */
  533. interface Thread {
  534. /**
  535. * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
  536. * start the thread with.
  537. */
  538. messages?: Array<Thread.Message>;
  539. /**
  540. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  541. * for storing additional information about the object in a structured format, and
  542. * querying for objects via API or the dashboard.
  543. *
  544. * Keys are strings with a maximum length of 64 characters. Values are strings with
  545. * a maximum length of 512 characters.
  546. */
  547. metadata?: Shared.Metadata | null;
  548. /**
  549. * A set of resources that are made available to the assistant's tools in this
  550. * thread. The resources are specific to the type of tool. For example, the
  551. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  552. * tool requires a list of vector store IDs.
  553. */
  554. tool_resources?: Thread.ToolResources | null;
  555. }
  556. namespace Thread {
  557. interface Message {
  558. /**
  559. * The text contents of the message.
  560. */
  561. content: string | Array<MessagesAPI.MessageContentPartParam>;
  562. /**
  563. * The role of the entity that is creating the message. Allowed values include:
  564. *
  565. * - `user`: Indicates the message is sent by an actual user and should be used in
  566. * most cases to represent user-generated messages.
  567. * - `assistant`: Indicates the message is generated by the assistant. Use this
  568. * value to insert messages from the assistant into the conversation.
  569. */
  570. role: 'user' | 'assistant';
  571. /**
  572. * A list of files attached to the message, and the tools they should be added to.
  573. */
  574. attachments?: Array<Message.Attachment> | null;
  575. /**
  576. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  577. * for storing additional information about the object in a structured format, and
  578. * querying for objects via API or the dashboard.
  579. *
  580. * Keys are strings with a maximum length of 64 characters. Values are strings with
  581. * a maximum length of 512 characters.
  582. */
  583. metadata?: Shared.Metadata | null;
  584. }
  585. namespace Message {
  586. interface Attachment {
  587. /**
  588. * The ID of the file to attach to the message.
  589. */
  590. file_id?: string;
  591. /**
  592. * The tools to add this file to.
  593. */
  594. tools?: Array<AssistantsAPI.CodeInterpreterTool | Attachment.FileSearch>;
  595. }
  596. namespace Attachment {
  597. interface FileSearch {
  598. /**
  599. * The type of tool being defined: `file_search`
  600. */
  601. type: 'file_search';
  602. }
  603. }
  604. }
  605. /**
  606. * A set of resources that are made available to the assistant's tools in this
  607. * thread. The resources are specific to the type of tool. For example, the
  608. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  609. * tool requires a list of vector store IDs.
  610. */
  611. interface ToolResources {
  612. code_interpreter?: ToolResources.CodeInterpreter;
  613. file_search?: ToolResources.FileSearch;
  614. }
  615. namespace ToolResources {
  616. interface CodeInterpreter {
  617. /**
  618. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  619. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  620. * associated with the tool.
  621. */
  622. file_ids?: Array<string>;
  623. }
  624. interface FileSearch {
  625. /**
  626. * The
  627. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  628. * attached to this thread. There can be a maximum of 1 vector store attached to
  629. * the thread.
  630. */
  631. vector_store_ids?: Array<string>;
  632. /**
  633. * A helper to create a
  634. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  635. * with file_ids and attach it to this thread. There can be a maximum of 1 vector
  636. * store attached to the thread.
  637. */
  638. vector_stores?: Array<FileSearch.VectorStore>;
  639. }
  640. namespace FileSearch {
  641. interface VectorStore {
  642. /**
  643. * The chunking strategy used to chunk the file(s). If not set, will use the `auto`
  644. * strategy.
  645. */
  646. chunking_strategy?: VectorStore.Auto | VectorStore.Static;
  647. /**
  648. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
  649. * add to the vector store. There can be a maximum of 10000 files in a vector
  650. * store.
  651. */
  652. file_ids?: Array<string>;
  653. /**
  654. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  655. * for storing additional information about the object in a structured format, and
  656. * querying for objects via API or the dashboard.
  657. *
  658. * Keys are strings with a maximum length of 64 characters. Values are strings with
  659. * a maximum length of 512 characters.
  660. */
  661. metadata?: Shared.Metadata | null;
  662. }
  663. namespace VectorStore {
  664. /**
  665. * The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
  666. * `800` and `chunk_overlap_tokens` of `400`.
  667. */
  668. interface Auto {
  669. /**
  670. * Always `auto`.
  671. */
  672. type: 'auto';
  673. }
  674. interface Static {
  675. static: Static.Static;
  676. /**
  677. * Always `static`.
  678. */
  679. type: 'static';
  680. }
  681. namespace Static {
  682. interface Static {
  683. /**
  684. * The number of tokens that overlap between chunks. The default value is `400`.
  685. *
  686. * Note that the overlap must not exceed half of `max_chunk_size_tokens`.
  687. */
  688. chunk_overlap_tokens: number;
  689. /**
  690. * The maximum number of tokens in each chunk. The default value is `800`. The
  691. * minimum value is `100` and the maximum value is `4096`.
  692. */
  693. max_chunk_size_tokens: number;
  694. }
  695. }
  696. }
  697. }
  698. }
  699. }
  700. /**
  701. * A set of resources that are used by the assistant's tools. The resources are
  702. * specific to the type of tool. For example, the `code_interpreter` tool requires
  703. * a list of file IDs, while the `file_search` tool requires a list of vector store
  704. * IDs.
  705. */
  706. interface ToolResources {
  707. code_interpreter?: ToolResources.CodeInterpreter;
  708. file_search?: ToolResources.FileSearch;
  709. }
  710. namespace ToolResources {
  711. interface CodeInterpreter {
  712. /**
  713. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  714. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  715. * associated with the tool.
  716. */
  717. file_ids?: Array<string>;
  718. }
  719. interface FileSearch {
  720. /**
  721. * The ID of the
  722. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  723. * attached to this assistant. There can be a maximum of 1 vector store attached to
  724. * the assistant.
  725. */
  726. vector_store_ids?: Array<string>;
  727. }
  728. }
  729. /**
  730. * Controls for how a thread will be truncated prior to the run. Use this to
  731. * control the intial context window of the run.
  732. */
  733. interface TruncationStrategy {
  734. /**
  735. * The truncation strategy to use for the thread. The default is `auto`. If set to
  736. * `last_messages`, the thread will be truncated to the n most recent messages in
  737. * the thread. When set to `auto`, messages in the middle of the thread will be
  738. * dropped to fit the context length of the model, `max_prompt_tokens`.
  739. */
  740. type: 'auto' | 'last_messages';
  741. /**
  742. * The number of most recent messages from the thread when constructing the context
  743. * for the run.
  744. */
  745. last_messages?: number | null;
  746. }
  747. type ThreadCreateAndRunParamsNonStreaming = ThreadsAPI.ThreadCreateAndRunParamsNonStreaming;
  748. type ThreadCreateAndRunParamsStreaming = ThreadsAPI.ThreadCreateAndRunParamsStreaming;
  749. }
  750. export interface ThreadCreateAndRunParamsNonStreaming extends ThreadCreateAndRunParamsBase {
  751. /**
  752. * If `true`, returns a stream of events that happen during the Run as server-sent
  753. * events, terminating when the Run enters a terminal state with a `data: [DONE]`
  754. * message.
  755. */
  756. stream?: false | null;
  757. }
  758. export interface ThreadCreateAndRunParamsStreaming extends ThreadCreateAndRunParamsBase {
  759. /**
  760. * If `true`, returns a stream of events that happen during the Run as server-sent
  761. * events, terminating when the Run enters a terminal state with a `data: [DONE]`
  762. * message.
  763. */
  764. stream: true;
  765. }
  766. export interface ThreadCreateAndRunPollParams {
  767. /**
  768. * The ID of the
  769. * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
  770. * execute this run.
  771. */
  772. assistant_id: string;
  773. /**
  774. * Override the default system message of the assistant. This is useful for
  775. * modifying the behavior on a per-run basis.
  776. */
  777. instructions?: string | null;
  778. /**
  779. * The maximum number of completion tokens that may be used over the course of the
  780. * run. The run will make a best effort to use only the number of completion tokens
  781. * specified, across multiple turns of the run. If the run exceeds the number of
  782. * completion tokens specified, the run will end with status `incomplete`. See
  783. * `incomplete_details` for more info.
  784. */
  785. max_completion_tokens?: number | null;
  786. /**
  787. * The maximum number of prompt tokens that may be used over the course of the run.
  788. * The run will make a best effort to use only the number of prompt tokens
  789. * specified, across multiple turns of the run. If the run exceeds the number of
  790. * prompt tokens specified, the run will end with status `incomplete`. See
  791. * `incomplete_details` for more info.
  792. */
  793. max_prompt_tokens?: number | null;
  794. /**
  795. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  796. * for storing additional information about the object in a structured format. Keys
  797. * can be a maximum of 64 characters long and values can be a maxium of 512
  798. * characters long.
  799. */
  800. metadata?: unknown | null;
  801. /**
  802. * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
  803. * be used to execute this run. If a value is provided here, it will override the
  804. * model associated with the assistant. If not, the model associated with the
  805. * assistant will be used.
  806. */
  807. model?: (string & {}) | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613' | null;
  808. /**
  809. * Specifies the format that the model must output. Compatible with
  810. * [GPT-4o](https://platform.openai.com/docs/models/gpt-4o),
  811. * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4),
  812. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  813. *
  814. * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
  815. * message the model generates is valid JSON.
  816. *
  817. * **Important:** when using JSON mode, you **must** also instruct the model to
  818. * produce JSON yourself via a system or user message. Without this, the model may
  819. * generate an unending stream of whitespace until the generation reaches the token
  820. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  821. * the message content may be partially cut off if `finish_reason="length"`, which
  822. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  823. * max context length.
  824. */
  825. response_format?: AssistantResponseFormatOption | null;
  826. /**
  827. * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
  828. * make the output more random, while lower values like 0.2 will make it more
  829. * focused and deterministic.
  830. */
  831. temperature?: number | null;
  832. /**
  833. * If no thread is provided, an empty thread will be created.
  834. */
  835. thread?: ThreadCreateAndRunPollParams.Thread;
  836. /**
  837. * Controls which (if any) tool is called by the model. `none` means the model will
  838. * not call any tools and instead generates a message. `auto` is the default value
  839. * and means the model can pick between generating a message or calling one or more
  840. * tools. `required` means the model must call one or more tools before responding
  841. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  842. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  843. * call that tool.
  844. */
  845. tool_choice?: AssistantToolChoiceOption | null;
  846. /**
  847. * A set of resources that are used by the assistant's tools. The resources are
  848. * specific to the type of tool. For example, the `code_interpreter` tool requires
  849. * a list of file IDs, while the `file_search` tool requires a list of vector store
  850. * IDs.
  851. */
  852. tool_resources?: ThreadCreateAndRunPollParams.ToolResources | null;
  853. /**
  854. * Override the tools the assistant can use for this run. This is useful for
  855. * modifying the behavior on a per-run basis.
  856. */
  857. tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool | AssistantsAPI.FunctionTool> | null;
  858. /**
  859. * An alternative to sampling with temperature, called nucleus sampling, where the
  860. * model considers the results of the tokens with top_p probability mass. So 0.1
  861. * means only the tokens comprising the top 10% probability mass are considered.
  862. *
  863. * We generally recommend altering this or temperature but not both.
  864. */
  865. top_p?: number | null;
  866. /**
  867. * Controls for how a thread will be truncated prior to the run. Use this to
  868. * control the intial context window of the run.
  869. */
  870. truncation_strategy?: ThreadCreateAndRunPollParams.TruncationStrategy | null;
  871. }
  872. export declare namespace ThreadCreateAndRunPollParams {
  873. /**
  874. * If no thread is provided, an empty thread will be created.
  875. */
  876. interface Thread {
  877. /**
  878. * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
  879. * start the thread with.
  880. */
  881. messages?: Array<Thread.Message>;
  882. /**
  883. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  884. * for storing additional information about the object in a structured format. Keys
  885. * can be a maximum of 64 characters long and values can be a maxium of 512
  886. * characters long.
  887. */
  888. metadata?: unknown | null;
  889. /**
  890. * A set of resources that are made available to the assistant's tools in this
  891. * thread. The resources are specific to the type of tool. For example, the
  892. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  893. * tool requires a list of vector store IDs.
  894. */
  895. tool_resources?: Thread.ToolResources | null;
  896. }
  897. namespace Thread {
  898. interface Message {
  899. /**
  900. * The text contents of the message.
  901. */
  902. content: string | Array<MessagesAPI.MessageContentPartParam>;
  903. /**
  904. * The role of the entity that is creating the message. Allowed values include:
  905. *
  906. * - `user`: Indicates the message is sent by an actual user and should be used in
  907. * most cases to represent user-generated messages.
  908. * - `assistant`: Indicates the message is generated by the assistant. Use this
  909. * value to insert messages from the assistant into the conversation.
  910. */
  911. role: 'user' | 'assistant';
  912. /**
  913. * A list of files attached to the message, and the tools they should be added to.
  914. */
  915. attachments?: Array<Message.Attachment> | null;
  916. /**
  917. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  918. * for storing additional information about the object in a structured format. Keys
  919. * can be a maximum of 64 characters long and values can be a maxium of 512
  920. * characters long.
  921. */
  922. metadata?: unknown | null;
  923. }
  924. namespace Message {
  925. interface Attachment {
  926. /**
  927. * The ID of the file to attach to the message.
  928. */
  929. file_id?: string;
  930. /**
  931. * The tools to add this file to.
  932. */
  933. tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool>;
  934. }
  935. }
  936. /**
  937. * A set of resources that are made available to the assistant's tools in this
  938. * thread. The resources are specific to the type of tool. For example, the
  939. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  940. * tool requires a list of vector store IDs.
  941. */
  942. interface ToolResources {
  943. code_interpreter?: ToolResources.CodeInterpreter;
  944. file_search?: ToolResources.FileSearch;
  945. }
  946. namespace ToolResources {
  947. interface CodeInterpreter {
  948. /**
  949. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  950. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  951. * associated with the tool.
  952. */
  953. file_ids?: Array<string>;
  954. }
  955. interface FileSearch {
  956. /**
  957. * The
  958. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  959. * attached to this thread. There can be a maximum of 1 vector store attached to
  960. * the thread.
  961. */
  962. vector_store_ids?: Array<string>;
  963. /**
  964. * A helper to create a
  965. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  966. * with file_ids and attach it to this thread. There can be a maximum of 1 vector
  967. * store attached to the thread.
  968. */
  969. vector_stores?: Array<FileSearch.VectorStore>;
  970. }
  971. namespace FileSearch {
  972. interface VectorStore {
  973. /**
  974. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
  975. * add to the vector store. There can be a maximum of 10000 files in a vector
  976. * store.
  977. */
  978. file_ids?: Array<string>;
  979. /**
  980. * Set of 16 key-value pairs that can be attached to a vector store. This can be
  981. * useful for storing additional information about the vector store in a structured
  982. * format. Keys can be a maximum of 64 characters long and values can be a maxium
  983. * of 512 characters long.
  984. */
  985. metadata?: unknown;
  986. }
  987. }
  988. }
  989. }
  990. /**
  991. * A set of resources that are used by the assistant's tools. The resources are
  992. * specific to the type of tool. For example, the `code_interpreter` tool requires
  993. * a list of file IDs, while the `file_search` tool requires a list of vector store
  994. * IDs.
  995. */
  996. interface ToolResources {
  997. code_interpreter?: ToolResources.CodeInterpreter;
  998. file_search?: ToolResources.FileSearch;
  999. }
  1000. namespace ToolResources {
  1001. interface CodeInterpreter {
  1002. /**
  1003. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  1004. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  1005. * associated with the tool.
  1006. */
  1007. file_ids?: Array<string>;
  1008. }
  1009. interface FileSearch {
  1010. /**
  1011. * The ID of the
  1012. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  1013. * attached to this assistant. There can be a maximum of 1 vector store attached to
  1014. * the assistant.
  1015. */
  1016. vector_store_ids?: Array<string>;
  1017. }
  1018. }
  1019. /**
  1020. * Controls for how a thread will be truncated prior to the run. Use this to
  1021. * control the intial context window of the run.
  1022. */
  1023. interface TruncationStrategy {
  1024. /**
  1025. * The truncation strategy to use for the thread. The default is `auto`. If set to
  1026. * `last_messages`, the thread will be truncated to the n most recent messages in
  1027. * the thread. When set to `auto`, messages in the middle of the thread will be
  1028. * dropped to fit the context length of the model, `max_prompt_tokens`.
  1029. */
  1030. type: 'auto' | 'last_messages';
  1031. /**
  1032. * The number of most recent messages from the thread when constructing the context
  1033. * for the run.
  1034. */
  1035. last_messages?: number | null;
  1036. }
  1037. }
  1038. export interface ThreadCreateAndRunStreamParams {
  1039. /**
  1040. * The ID of the
  1041. * [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
  1042. * execute this run.
  1043. */
  1044. assistant_id: string;
  1045. /**
  1046. * Override the default system message of the assistant. This is useful for
  1047. * modifying the behavior on a per-run basis.
  1048. */
  1049. instructions?: string | null;
  1050. /**
  1051. * The maximum number of completion tokens that may be used over the course of the
  1052. * run. The run will make a best effort to use only the number of completion tokens
  1053. * specified, across multiple turns of the run. If the run exceeds the number of
  1054. * completion tokens specified, the run will end with status `incomplete`. See
  1055. * `incomplete_details` for more info.
  1056. */
  1057. max_completion_tokens?: number | null;
  1058. /**
  1059. * The maximum number of prompt tokens that may be used over the course of the run.
  1060. * The run will make a best effort to use only the number of prompt tokens
  1061. * specified, across multiple turns of the run. If the run exceeds the number of
  1062. * prompt tokens specified, the run will end with status `incomplete`. See
  1063. * `incomplete_details` for more info.
  1064. */
  1065. max_prompt_tokens?: number | null;
  1066. /**
  1067. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1068. * for storing additional information about the object in a structured format. Keys
  1069. * can be a maximum of 64 characters long and values can be a maxium of 512
  1070. * characters long.
  1071. */
  1072. metadata?: unknown | null;
  1073. /**
  1074. * The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
  1075. * be used to execute this run. If a value is provided here, it will override the
  1076. * model associated with the assistant. If not, the model associated with the
  1077. * assistant will be used.
  1078. */
  1079. model?: (string & {}) | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-0125-preview' | 'gpt-4-turbo-preview' | 'gpt-4-1106-preview' | 'gpt-4-vision-preview' | 'gpt-4' | 'gpt-4-0314' | 'gpt-4-0613' | 'gpt-4-32k' | 'gpt-4-32k-0314' | 'gpt-4-32k-0613' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-16k' | 'gpt-3.5-turbo-0613' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo-16k-0613' | null;
  1080. /**
  1081. * Specifies the format that the model must output. Compatible with
  1082. * [GPT-4o](https://platform.openai.com/docs/models/gpt-4o),
  1083. * [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4),
  1084. * and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
  1085. *
  1086. * Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
  1087. * message the model generates is valid JSON.
  1088. *
  1089. * **Important:** when using JSON mode, you **must** also instruct the model to
  1090. * produce JSON yourself via a system or user message. Without this, the model may
  1091. * generate an unending stream of whitespace until the generation reaches the token
  1092. * limit, resulting in a long-running and seemingly "stuck" request. Also note that
  1093. * the message content may be partially cut off if `finish_reason="length"`, which
  1094. * indicates the generation exceeded `max_tokens` or the conversation exceeded the
  1095. * max context length.
  1096. */
  1097. response_format?: AssistantResponseFormatOption | null;
  1098. /**
  1099. * What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
  1100. * make the output more random, while lower values like 0.2 will make it more
  1101. * focused and deterministic.
  1102. */
  1103. temperature?: number | null;
  1104. /**
  1105. * If no thread is provided, an empty thread will be created.
  1106. */
  1107. thread?: ThreadCreateAndRunStreamParams.Thread;
  1108. /**
  1109. * Controls which (if any) tool is called by the model. `none` means the model will
  1110. * not call any tools and instead generates a message. `auto` is the default value
  1111. * and means the model can pick between generating a message or calling one or more
  1112. * tools. `required` means the model must call one or more tools before responding
  1113. * to the user. Specifying a particular tool like `{"type": "file_search"}` or
  1114. * `{"type": "function", "function": {"name": "my_function"}}` forces the model to
  1115. * call that tool.
  1116. */
  1117. tool_choice?: AssistantToolChoiceOption | null;
  1118. /**
  1119. * A set of resources that are used by the assistant's tools. The resources are
  1120. * specific to the type of tool. For example, the `code_interpreter` tool requires
  1121. * a list of file IDs, while the `file_search` tool requires a list of vector store
  1122. * IDs.
  1123. */
  1124. tool_resources?: ThreadCreateAndRunStreamParams.ToolResources | null;
  1125. /**
  1126. * Override the tools the assistant can use for this run. This is useful for
  1127. * modifying the behavior on a per-run basis.
  1128. */
  1129. tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool | AssistantsAPI.FunctionTool> | null;
  1130. /**
  1131. * An alternative to sampling with temperature, called nucleus sampling, where the
  1132. * model considers the results of the tokens with top_p probability mass. So 0.1
  1133. * means only the tokens comprising the top 10% probability mass are considered.
  1134. *
  1135. * We generally recommend altering this or temperature but not both.
  1136. */
  1137. top_p?: number | null;
  1138. /**
  1139. * Controls for how a thread will be truncated prior to the run. Use this to
  1140. * control the intial context window of the run.
  1141. */
  1142. truncation_strategy?: ThreadCreateAndRunStreamParams.TruncationStrategy | null;
  1143. }
  1144. export declare namespace ThreadCreateAndRunStreamParams {
  1145. /**
  1146. * If no thread is provided, an empty thread will be created.
  1147. */
  1148. interface Thread {
  1149. /**
  1150. * A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
  1151. * start the thread with.
  1152. */
  1153. messages?: Array<Thread.Message>;
  1154. /**
  1155. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1156. * for storing additional information about the object in a structured format. Keys
  1157. * can be a maximum of 64 characters long and values can be a maxium of 512
  1158. * characters long.
  1159. */
  1160. metadata?: unknown | null;
  1161. /**
  1162. * A set of resources that are made available to the assistant's tools in this
  1163. * thread. The resources are specific to the type of tool. For example, the
  1164. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  1165. * tool requires a list of vector store IDs.
  1166. */
  1167. tool_resources?: Thread.ToolResources | null;
  1168. }
  1169. namespace Thread {
  1170. interface Message {
  1171. /**
  1172. * The text contents of the message.
  1173. */
  1174. content: string | Array<MessagesAPI.MessageContentPartParam>;
  1175. /**
  1176. * The role of the entity that is creating the message. Allowed values include:
  1177. *
  1178. * - `user`: Indicates the message is sent by an actual user and should be used in
  1179. * most cases to represent user-generated messages.
  1180. * - `assistant`: Indicates the message is generated by the assistant. Use this
  1181. * value to insert messages from the assistant into the conversation.
  1182. */
  1183. role: 'user' | 'assistant';
  1184. /**
  1185. * A list of files attached to the message, and the tools they should be added to.
  1186. */
  1187. attachments?: Array<Message.Attachment> | null;
  1188. /**
  1189. * Set of 16 key-value pairs that can be attached to an object. This can be useful
  1190. * for storing additional information about the object in a structured format. Keys
  1191. * can be a maximum of 64 characters long and values can be a maxium of 512
  1192. * characters long.
  1193. */
  1194. metadata?: unknown | null;
  1195. }
  1196. namespace Message {
  1197. interface Attachment {
  1198. /**
  1199. * The ID of the file to attach to the message.
  1200. */
  1201. file_id?: string;
  1202. /**
  1203. * The tools to add this file to.
  1204. */
  1205. tools?: Array<AssistantsAPI.CodeInterpreterTool | AssistantsAPI.FileSearchTool>;
  1206. }
  1207. }
  1208. /**
  1209. * A set of resources that are made available to the assistant's tools in this
  1210. * thread. The resources are specific to the type of tool. For example, the
  1211. * `code_interpreter` tool requires a list of file IDs, while the `file_search`
  1212. * tool requires a list of vector store IDs.
  1213. */
  1214. interface ToolResources {
  1215. code_interpreter?: ToolResources.CodeInterpreter;
  1216. file_search?: ToolResources.FileSearch;
  1217. }
  1218. namespace ToolResources {
  1219. interface CodeInterpreter {
  1220. /**
  1221. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  1222. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  1223. * associated with the tool.
  1224. */
  1225. file_ids?: Array<string>;
  1226. }
  1227. interface FileSearch {
  1228. /**
  1229. * The
  1230. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  1231. * attached to this thread. There can be a maximum of 1 vector store attached to
  1232. * the thread.
  1233. */
  1234. vector_store_ids?: Array<string>;
  1235. /**
  1236. * A helper to create a
  1237. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  1238. * with file_ids and attach it to this thread. There can be a maximum of 1 vector
  1239. * store attached to the thread.
  1240. */
  1241. vector_stores?: Array<FileSearch.VectorStore>;
  1242. }
  1243. namespace FileSearch {
  1244. interface VectorStore {
  1245. /**
  1246. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
  1247. * add to the vector store. There can be a maximum of 10000 files in a vector
  1248. * store.
  1249. */
  1250. file_ids?: Array<string>;
  1251. /**
  1252. * Set of 16 key-value pairs that can be attached to a vector store. This can be
  1253. * useful for storing additional information about the vector store in a structured
  1254. * format. Keys can be a maximum of 64 characters long and values can be a maxium
  1255. * of 512 characters long.
  1256. */
  1257. metadata?: unknown;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. /**
  1263. * A set of resources that are used by the assistant's tools. The resources are
  1264. * specific to the type of tool. For example, the `code_interpreter` tool requires
  1265. * a list of file IDs, while the `file_search` tool requires a list of vector store
  1266. * IDs.
  1267. */
  1268. interface ToolResources {
  1269. code_interpreter?: ToolResources.CodeInterpreter;
  1270. file_search?: ToolResources.FileSearch;
  1271. }
  1272. namespace ToolResources {
  1273. interface CodeInterpreter {
  1274. /**
  1275. * A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
  1276. * available to the `code_interpreter` tool. There can be a maximum of 20 files
  1277. * associated with the tool.
  1278. */
  1279. file_ids?: Array<string>;
  1280. }
  1281. interface FileSearch {
  1282. /**
  1283. * The ID of the
  1284. * [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
  1285. * attached to this assistant. There can be a maximum of 1 vector store attached to
  1286. * the assistant.
  1287. */
  1288. vector_store_ids?: Array<string>;
  1289. }
  1290. }
  1291. /**
  1292. * Controls for how a thread will be truncated prior to the run. Use this to
  1293. * control the intial context window of the run.
  1294. */
  1295. interface TruncationStrategy {
  1296. /**
  1297. * The truncation strategy to use for the thread. The default is `auto`. If set to
  1298. * `last_messages`, the thread will be truncated to the n most recent messages in
  1299. * the thread. When set to `auto`, messages in the middle of the thread will be
  1300. * dropped to fit the context length of the model, `max_prompt_tokens`.
  1301. */
  1302. type: 'auto' | 'last_messages';
  1303. /**
  1304. * The number of most recent messages from the thread when constructing the context
  1305. * for the run.
  1306. */
  1307. last_messages?: number | null;
  1308. }
  1309. }
  1310. export declare namespace Threads {
  1311. export { type AssistantResponseFormatOption as AssistantResponseFormatOption, type AssistantToolChoice as AssistantToolChoice, type AssistantToolChoiceFunction as AssistantToolChoiceFunction, type AssistantToolChoiceOption as AssistantToolChoiceOption, type Thread as Thread, type ThreadDeleted as ThreadDeleted, type ThreadCreateParams as ThreadCreateParams, type ThreadUpdateParams as ThreadUpdateParams, type ThreadCreateAndRunParams as ThreadCreateAndRunParams, type ThreadCreateAndRunParamsNonStreaming as ThreadCreateAndRunParamsNonStreaming, type ThreadCreateAndRunParamsStreaming as ThreadCreateAndRunParamsStreaming, type ThreadCreateAndRunPollParams, type ThreadCreateAndRunStreamParams, };
  1312. export { Runs as Runs, type RequiredActionFunctionToolCall as RequiredActionFunctionToolCall, type Run as Run, type RunStatus as RunStatus, RunsPage as RunsPage, type RunCreateParams as RunCreateParams, type RunCreateParamsNonStreaming as RunCreateParamsNonStreaming, type RunCreateParamsStreaming as RunCreateParamsStreaming, type RunUpdateParams as RunUpdateParams, type RunListParams as RunListParams, type RunCreateAndPollParams, type RunCreateAndStreamParams, type RunStreamParams, type RunSubmitToolOutputsParams as RunSubmitToolOutputsParams, type RunSubmitToolOutputsParamsNonStreaming as RunSubmitToolOutputsParamsNonStreaming, type RunSubmitToolOutputsParamsStreaming as RunSubmitToolOutputsParamsStreaming, type RunSubmitToolOutputsAndPollParams, type RunSubmitToolOutputsStreamParams, };
  1313. export { Messages as Messages, type Annotation as Annotation, type AnnotationDelta as AnnotationDelta, type FileCitationAnnotation as FileCitationAnnotation, type FileCitationDeltaAnnotation as FileCitationDeltaAnnotation, type FilePathAnnotation as FilePathAnnotation, type FilePathDeltaAnnotation as FilePathDeltaAnnotation, type ImageFile as ImageFile, type ImageFileContentBlock as ImageFileContentBlock, type ImageFileDelta as ImageFileDelta, type ImageFileDeltaBlock as ImageFileDeltaBlock, type ImageURL as ImageURL, type ImageURLContentBlock as ImageURLContentBlock, type ImageURLDelta as ImageURLDelta, type ImageURLDeltaBlock as ImageURLDeltaBlock, type MessagesAPIMessage as Message, type MessageContent as MessageContent, type MessageContentDelta as MessageContentDelta, type MessageContentPartParam as MessageContentPartParam, type MessageDeleted as MessageDeleted, type MessageDelta as MessageDelta, type MessageDeltaEvent as MessageDeltaEvent, type RefusalContentBlock as RefusalContentBlock, type RefusalDeltaBlock as RefusalDeltaBlock, type Text as Text, type TextContentBlock as TextContentBlock, type TextContentBlockParam as TextContentBlockParam, type TextDelta as TextDelta, type TextDeltaBlock as TextDeltaBlock, MessagesPage as MessagesPage, type MessageCreateParams as MessageCreateParams, type MessageUpdateParams as MessageUpdateParams, type MessageListParams as MessageListParams, };
  1314. export { AssistantStream };
  1315. }
  1316. //# sourceMappingURL=threads.d.ts.map