Skip to content

Commit

Permalink
Merge branch 'main' into add-pytest-replays
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White authored Oct 30, 2023
2 parents 20b3346 + cb05a8a commit e9697f4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions JavaScript/openai-manual/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const openai = new OpenAI({
});

const tracer = new AutoblocksTracer(process.env.AUTOBLOCKS_INGESTION_KEY, {
// These apply to every call of ab.sendEvent() so we don't have to repeat them
// These apply to every call of tracer.sendEvent() so we don't have to repeat them
traceId: crypto.randomUUID(),
properties: {
provider: 'openai',
Expand All @@ -18,6 +18,9 @@ const tracer = new AutoblocksTracer(process.env.AUTOBLOCKS_INGESTION_KEY, {
async function run() {
console.log('Running example...');

// Use a spanId to group together the request + response/error events
const spanId = crypto.randomUUID();

const openAIRequest = {
model: 'gpt-3.5-turbo',
messages: [
Expand All @@ -41,7 +44,7 @@ async function run() {
};

await tracer.sendEvent('ai.request', {
properties: openAIRequest,
properties: { ...openAIRequest, spanId },
});

try {
Expand All @@ -51,12 +54,14 @@ async function run() {
properties: {
response,
latency: Date.now() - now,
spanId,
},
});
} catch (error) {
await tracer.sendEvent('ai.error', {
properties: {
error,
spanId,
},
});
}
Expand Down

0 comments on commit e9697f4

Please sign in to comment.