Skip to content

Commit

Permalink
OpenAi: completion: capture array prompt (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik1397 authored Jan 29, 2024
1 parent a67e5d3 commit 792bbc2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/instrumentation-openai/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,12 @@ export class OpenAIInstrumentation extends InstrumentationBase<any> {
}
});
} else {
attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = "user";
if (typeof params.prompt === "string") {
attributes[`${SpanAttributes.LLM_PROMPTS}.0.role`] = "user";
attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] = params.prompt;
} else {
attributes[`${SpanAttributes.LLM_PROMPTS}.0.content`] =
JSON.stringify(params.prompt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sample-app/src/sample_with.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function chat() {
async function completion() {
return await traceloop.withWorkflow("sample_completion", {}, async () => {
const completion = await openai.completions.create({
prompt: "Tell me a joke about TypeScript",
prompt: ["Tell me a joke about TypeScript"],
model: "gpt-3.5-turbo-instruct",
});

Expand Down

0 comments on commit 792bbc2

Please sign in to comment.