Skip to content

Commit 187e18a

Browse files
committed
move from ts to js, no esm
1 parent ea544e9 commit 187e18a

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

observability-tutorial-typescript/index.ts renamed to observability-tutorial-typescript/observability-example.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
1-
import * as dotenv from 'dotenv';
2-
import { OpenAI } from 'openai';
1+
import OpenAI from 'openai';
32
import { Pinecone } from '@pinecone-database/pinecone';
43
import { HoneyHiveTracer } from 'honeyhive';
5-
4+
import dotenv from 'dotenv';
65
dotenv.config();
76

7+
// Initialize HoneyHive Tracer
8+
const tracer = await HoneyHiveTracer.init({
9+
apiKey: process.env.HH_API_KEY,
10+
project: process.env.HH_PROJECT,
11+
source: "dev",
12+
sessionName: "JS RAG Session"
13+
});
14+
815
// Initialize clients
916
const openai = new OpenAI();
1017
const pc = new Pinecone();
11-
const index = pc.index("your-index-name");
18+
const index = pc.index("chunk-size-512");
1219

13-
async function embedQuery(query: string): Promise<number[]> {
20+
async function embedQuery(query) {
1421
const res = await openai.embeddings.create({
1522
model: "text-embedding-ada-002",
1623
input: query
1724
});
1825
return res.data[0].embedding;
1926
}
2027

21-
async function getRelevantDocuments(query: string): Promise<string[]> {
28+
async function getRelevantDocuments(query) {
2229
const queryVector = await embedQuery(query);
2330
const res = await index.query({
2431
vector: queryVector,
2532
topK: 3,
2633
includeMetadata: true
2734
});
28-
return res.matches.map(item => item.metadata!._node_content as string);
35+
return res.matches.map(item => item.metadata._node_content);
2936
}
3037

31-
async function generateResponse(context: string, query: string): Promise<string> {
38+
async function generateResponse(context, query) {
3239
const prompt = `Context: ${context}\n\nQuestion: ${query}\n\nAnswer:`;
3340
const response = await openai.chat.completions.create({
34-
model: "gpt-4",
41+
model: "gpt-4o-mini",
3542
messages: [
3643
{ role: "system", content: "You are a helpful assistant." },
3744
{ role: "user", content: prompt }
@@ -40,21 +47,13 @@ async function generateResponse(context: string, query: string): Promise<string>
4047
return response.choices[0].message.content || "";
4148
}
4249

43-
async function ragPipeline(query: string): Promise<string> {
50+
async function ragPipeline(query) {
4451
const docs = await getRelevantDocuments(query);
4552
const response = await generateResponse(docs.join("\n"), query);
4653
return response;
4754
}
4855

4956
async function main() {
50-
// Initialize HoneyHive Tracer
51-
const tracer = await HoneyHiveTracer.init({
52-
apiKey: process.env.HH_API_KEY!,
53-
project: process.env.HH_PROJECT!,
54-
source: "dev",
55-
sessionName: "TS RAG Session"
56-
});
57-
5857
await tracer.trace(async () => {
5958
const query = "What does the document talk about?";
6059
const response = await ragPipeline(query);
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
{
2-
"name": "typescript-rag-implementation",
2+
"name": "honeyhive-js-implementation",
33
"version": "1.0.0",
4-
"description": "TypeScript implementation of RAG pipeline with OpenAI, Pinecone, and HoneyHive",
5-
"main": "index.ts",
4+
"description": "JavaScript implementation of RAG pipeline with OpenAI, Pinecone, and HoneyHive",
5+
"main": "observability-example.js",
66
"scripts": {
7-
"start": "npx tsx index.ts"
7+
"start": "node observability-example.js"
88
},
99
"dependencies": {
1010
"@pinecone-database/pinecone": "^3.0.3",
1111
"dotenv": "^16.0.3",
1212
"honeyhive": "^1.0.5",
1313
"openai": "^4.0.0"
14-
},
15-
"devDependencies": {
16-
"@types/node": "^18.0.0",
17-
"tsx": "^3.12.0",
18-
"typescript": "^4.9.5"
1914
}
2015
}

observability-tutorial-typescript/tsconfig.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)