-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sdk): properly initialize token enrich value for instrumentations (…
- Loading branch information
Showing
5 changed files
with
39 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as traceloop from "@traceloop/node-server-sdk"; | ||
import OpenAI from "openai"; | ||
|
||
traceloop.initialize({ | ||
appName: "sample_openai_streaming", | ||
apiKey: process.env.TRACELOOP_API_KEY, | ||
disableBatch: true, | ||
}); | ||
const openai = new OpenAI(); | ||
|
||
async function create_joke() { | ||
const responseStream = await traceloop.withTask( | ||
{ name: "joke_creation" }, | ||
() => { | ||
return openai.chat.completions.create({ | ||
model: "gpt-3.5-turbo", | ||
messages: [ | ||
{ role: "user", content: "Tell me a joke about opentelemetry" }, | ||
], | ||
stream: true, | ||
}); | ||
}, | ||
); | ||
let result = ""; | ||
for await (const chunk of responseStream) { | ||
result += chunk.choices[0]?.delta?.content || ""; | ||
} | ||
console.log(result); | ||
return result; | ||
} | ||
|
||
create_joke(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters