Skip to content

Commit

Permalink
Merge pull request #40 from upstash/add-helicone-upstash
Browse files Browse the repository at this point in the history
feat: add helicone analytics to qstash llm
  • Loading branch information
ogzhanolguncu authored Aug 9, 2024
2 parents 1f50c91 + cc48fac commit 2a3e49d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ Helicone is a powerful observability platform that provides valuable insights in

To enable Helicone observability in RAGChat, you simply need to pass your Helicone API key when initializing your model. Here's how to do it for both custom models and OpenAI:

#### For Upstash Models

```ts
import { RAGChat, upstash } from "ragchat";

const ragChat = new RAGChat({
model: upstash("meta-llama/Meta-Llama-3-8B-Instruct", {
apiKey: process.env.QSTASH_TOKEN,
analytics: { name: "helicone", token: process.env.HELICONE_API_KEY },
}),
});
```

#### For Custom Models (e.g., Meta-Llama)

```ts
Expand All @@ -388,7 +401,7 @@ import { RAGChat, openai } from "ragchat";
const ragChat = new RAGChat({
model: openai("gpt-3.5-turbo", {
apiKey: process.env.OPENAI_API_KEY!,
analytics: { name: "helicone", token: process.env.HELICONE_API_KEY! },
analytics: { name: "helicone", token: process.env.HELICONE_API_KEY },
}),
});
```
Expand Down
20 changes: 16 additions & 4 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ const analyticsBaseUrlMap = (
Authorization: `Bearer ${providerApiKey}`,
},
},
upstash: {
basePath: "https://qstash.helicone.ai/llm/v1",
defaultHeaders: {
"Helicone-Auth": `Bearer ${analyticsToken}`,
Authorization: `Bearer ${providerApiKey}`,
},
},
},
}[analyticsName];
};
Expand All @@ -81,15 +88,20 @@ export const upstash = (model: UpstashChatModel, options?: Omit<ModelOptions, "b
" Pass apiKey parameter or set QSTASH_TOKEN env variable."
);
}
const { analytics, ...optionsWithoutAnalytics } = options ?? {};

return new ChatOpenAI({
modelName: model,
apiKey,
...options,
...optionsWithoutAnalytics,
streamUsage: false,
configuration: {
baseURL: "https://qstash.upstash.io/llm/v1",
},
...(analytics
? { configuration: analyticsBaseUrlMap(analytics.name, analytics.token, apiKey).upstash }
: {
configuration: {
baseURL: "https://qstash.upstash.io/llm/v1",
},
}),
});
};

Expand Down

0 comments on commit 2a3e49d

Please sign in to comment.