MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / Chat

Class Chat

integrations/openai/src/chat.ts:14–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import { FetchRetryOptions, FetchTimeoutOptions } from "@trigger.dev/integration-kit";
13
14export class Chat {
15 constructor(
16 private runTask: OpenAIRunTask,
17 private options: OpenAIIntegrationOptions
18 ) {}
19
20 completions = {
21 create: (
22 key: IntegrationTaskKey,
23 params: Prettify<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming>,
24 options: OpenAIRequestOptions = {}
25 ): Promise<OpenAI.Chat.ChatCompletion> => {
26 return this.runTask(
27 key,
28 async (client, task) => {
29 const { data, response } = await client.chat.completions
30 .create(params, {
31 idempotencyKey: task.idempotencyKey,
32 ...options,
33 })
34 .withResponse();
35
36 task.outputProperties = createTaskOutputProperties(data.usage, response.headers);
37
38 return data;
39 },
40 {
41 name: "Chat Completion",
42 params,
43 properties: [
44 {
45 label: "model",
46 text: params.model,
47 },
48 ],
49 },
50 handleOpenAIError
51 );
52 },
53
54 backgroundCreate: (
55 key: IntegrationTaskKey,
56 params: Prettify<OpenAI.Chat.ChatCompletionCreateParamsNonStreaming>,
57 options: OpenAIRequestOptions = {},
58 fetchOptions: { retries?: FetchRetryOptions; timeout?: FetchTimeoutOptions } = {}
59 ): Promise<OpenAI.Chat.ChatCompletion> => {
60 return this.runTask(
61 key,
62 async (client, task, io) => {
63 const url = createBackgroundFetchUrl(
64 client,
65 "/chat/completions",
66 this.options.defaultQuery,
67 options
68 );
69
70 const response = await io.backgroundFetchResponse<OpenAI.Chat.ChatCompletion>(
71 "background",

Callers

nothing calls this directly

Calls 6

createBackgroundFetchUrlFunction · 0.90
withResponseMethod · 0.80
createMethod · 0.65
runTaskMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…