Skip to content

Commit

Permalink
Add R1, add support for non-tool supporting models by loading a list …
Browse files Browse the repository at this point in the history
…of supported models to check against
  • Loading branch information
IanCal committed Jan 26, 2025
1 parent d683a53 commit c6babc5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/ai-bot/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const MINIMUM_CREDITS = 10;
class Assistant {
private openai: OpenAI;
private client: MatrixClient;
private toolCallCapableModels: Set<string>;
pgAdapter: PgAdapter;
id: string;

Expand All @@ -57,6 +58,21 @@ class Assistant {
this.id = id;
this.client = client;
this.pgAdapter = new PgAdapter();
this.toolCallCapableModels = new Set();
}

async loadToolCallCapableModels() {
// api request is https://openrouter.ai/api/v1/models?supported_parameters=tools
let response = await fetch(
'https://openrouter.ai/api/v1/models?supported_parameters=tools',
);
let responseJson = (await response.json()) as {
data: { id: string }[];
};
let modelList = responseJson.data;
this.toolCallCapableModels = new Set(
modelList.map((model: any) => model.id),
);
}

async trackAiUsageCost(matrixUserId: string, generationId: string) {
Expand All @@ -72,7 +88,12 @@ class Assistant {
}

getResponse(prompt: PromptParts) {
if (prompt.tools.length === 0) {
// Sending tools to models that don't support them results in an error
// from openrouter.
if (
prompt.tools.length === 0 ||
!this.toolCallCapableModels.has(prompt.model)
) {
return this.openai.beta.chat.completions.stream({
model: prompt.model,
messages: prompt.messages as ChatCompletionMessageParam[],
Expand Down Expand Up @@ -144,6 +165,7 @@ Common issues are:
});
let { user_id: aiBotUserId } = auth;
let assistant = new Assistant(client, aiBotUserId);
await assistant.loadToolCallCapableModels();

client.on(RoomMemberEvent.Membership, function (_event, member) {
if (member.membership === 'invite' && member.userId === aiBotUserId) {
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime-common/matrix-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export const DEFAULT_LLM_LIST = [
'google/gemini-pro-1.5',
'openai/gpt-4o',
'openai/gpt-4o-mini',
'deepseek/deepseek-r1',
'deepseek/deepseek-r1-distill-llama-70b',
];

0 comments on commit c6babc5

Please sign in to comment.