Skip to content

Commit

Permalink
Merge pull request #1799 from cardstack/openrouter-ai-bot
Browse files Browse the repository at this point in the history
Use open router for ai bot
  • Loading branch information
jurgenwerk authored Nov 15, 2024
2 parents ade7903 + e843e47 commit db8c1b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ To build the entire repository and run the application, follow these steps:

```zsh
cd ./packages/ai-bot
OPENAI_API_KEY=*** pnpm start
OPENROUTER_API_KEY=*** pnpm start
```

## Cleanup command
Expand Down
6 changes: 3 additions & 3 deletions packages/ai-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ If you are working on boxel development, you do not need to connect this up to O

### Access to GPT4

You can get an OpenAI api key one from the staging parameter store or ask within the team.
Set this as the `OPENAI_API_KEY` environment variable. Note that if you set this broadly (such as in your bashrc) this will be used by default for many other openai based tools.
You can get an OpenRouter api key one from the staging parameter store or ask within the team.
Set this as the `OPENROUTER_API_KEY` environment variable.

OPENAI_API_KEY="sk-..."
OPENROUTER_API_KEY="sk-..."

## Running

Expand Down
9 changes: 6 additions & 3 deletions packages/ai-bot/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class Assistant {
id: string;

constructor(client: MatrixClient, id: string) {
this.openai = new OpenAI();
this.openai = new OpenAI({
baseURL: 'https://openrouter.ai/api/v1', // We use openrouter so that we can track usage cost in $
apiKey: process.env.OPENROUTER_API_KEY,
});
this.id = id;
this.client = client;
}
Expand All @@ -43,12 +46,12 @@ class Assistant {
let messages = getModifyPrompt(history, this.id, tools);
if (tools.length === 0) {
return this.openai.beta.chat.completions.stream({
model: 'gpt-4o',
model: 'openai/gpt-4o',
messages: messages,
});
} else {
return this.openai.beta.chat.completions.stream({
model: 'gpt-4o',
model: 'openai/gpt-4o',
messages: messages,
tools: tools,
tool_choice: 'auto',
Expand Down

0 comments on commit db8c1b1

Please sign in to comment.