MCPcopy
hub / github.com/OpenPipe/OpenPipe / create

Method create

client-libs/typescript/src/openai.ts:86–181  ·  view source on GitHub ↗
(
    { openpipe: rawOpenpipe, ...body }: ChatCompletionCreateParams & OpenPipeArgs,
    options?: Core.RequestOptions,
  )

Source from the content-addressed store, hash-verified

84 options?: Core.RequestOptions,
85 ): Core.APIPromise<Stream<ChatCompletionChunk> | ChatCompletion>;
86 async create(
87 { openpipe: rawOpenpipe, ...body }: ChatCompletionCreateParams & OpenPipeArgs,
88 options?: Core.RequestOptions,
89 ): Promise<
90 Core.APIPromise<
91 | (ChatCompletion & { openpipe?: OpenPipeMeta })
92 | (Stream<ChatCompletionChunk> & { openpipe?: OpenPipeMeta })
93 >
94 > {
95 const openpipe = { logRequest: true, ...rawOpenpipe };
96 const requestedAt = Date.now();
97 let reportingFinished: OpenPipeMeta["reportingFinished"] = Promise.resolve();
98
99 if (body.model.startsWith("openpipe:")) {
100 if (!this.opCompletionClient) throw new Error("OpenPipe client not set");
101 return this.opCompletionClient?.chat.completions.create(body, {
102 ...options,
103 headers: {
104 ...options?.headers,
105 "op-log-request": openpipe.logRequest ? "true" : "false",
106 "op-cache": openpipe.cache ? "true" : "false",
107 "op-tags": JSON.stringify(getTags(openpipe)),
108 },
109 });
110 }
111
112 try {
113 if (body.stream) {
114 const stream = await super.create(body, options);
115 try {
116 return new WrappedStream(stream, (response) => {
117 if (!openpipe.logRequest) return Promise.resolve();
118 return this._report({
119 requestedAt,
120 receivedAt: Date.now(),
121 reqPayload: body,
122 respPayload: response,
123 statusCode: 200,
124 tags: getTags(openpipe),
125 });
126 });
127 } catch (e) {
128 console.error("OpenPipe: error creating wrapped stream");
129 console.error(e);
130 throw e;
131 }
132 } else {
133 const response = await super.create(body, options);
134
135 reportingFinished = openpipe.logRequest
136 ? this._report({
137 requestedAt,
138 receivedAt: Date.now(),
139 reqPayload: body,
140 respPayload: response,
141 statusCode: 200,
142 tags: getTags(openpipe),
143 })

Callers 15

JsonEditorFunction · 0.45
requireCanViewProjectFunction · 0.45
recordUsageFunction · 0.45
recordLoggedCallFunction · 0.45
setupTestProjectFunction · 0.45
getAnyscaleCompletionFunction · 0.45
getOpenaiCompletionFunction · 0.45
getAzureGpt4CompletionFunction · 0.45
createSetupIntentFunction · 0.45
invertFunction · 0.45

Calls 2

_reportMethod · 0.95
getTagsFunction · 0.90

Tested by 7

setupTestProjectFunction · 0.36
initializeProjectFunction · 0.36
createNodeEntryFunction · 0.36
createPruningRuleFunction · 0.36
createFineTuneFunction · 0.36
setupTestDbFunction · 0.36