-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlangsmith_trace.tsx
More file actions
38 lines (30 loc) · 1.01 KB
/
langsmith_trace.tsx
File metadata and controls
38 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# install npm module and get API key
# npm install langsmith
#
# export LANGSMITH_TRACING=true
# export LANGSMITH_API_KEY=<your-api-key>
# export LANGSMITH_PROJECT=default
import { OpenAI } from "openai";
import { wrapOpenAI } from "langsmith/wrappers";
# with traceable you can trace the entire chain
# import { traceable } from "langsmith/traceable";
const openAIClient = wrapOpenAI(new OpenAI());
async function retriever(query: string) {
return ["This is a document"];
}
# replace async function with traceable()
# const rag = traceable(async function rag(question: string) {
async function rag(question: string) {
const docs = await retriever(question);
const systemMessage =
"Answer the users question using only the provided information below:\n\n" +
docs.join("\n");
return await openAIClient.chat.completions.create({
messages: [
{ role: "system", content: systemMessage },
{ role: "user", content: question },
],
model: "gpt-4o-mini",
});
}
rag("ask your question here")