@@ -2,12 +2,7 @@ import { anthropic } from '@ai-sdk/anthropic';
22import { openai } from '@ai-sdk/openai' ;
33import { Injectable } from '@nestjs/common' ;
44import { ConfigService } from '@nestjs/config' ;
5- import {
6- AIStreamResponse ,
7- GetAIRequestDTO ,
8- LLMMappings ,
9- LLMModelEnum ,
10- } from '@tegonhq/types' ;
5+ import { AIStreamResponse , GetAIRequestDTO } from '@tegonhq/types' ;
116import {
127 CoreMessage ,
138 CoreUserMessage ,
@@ -74,7 +69,7 @@ export default class AIRequestsService {
7469 try {
7570 return await this . makeModelCall (
7671 stream ,
77- model as LLMModelEnum ,
72+ model ,
7873 messages ,
7974 ( text : string , model : string ) => {
8075 this . createRecord (
@@ -98,33 +93,35 @@ export default class AIRequestsService {
9893
9994 async makeModelCall (
10095 stream : boolean ,
101- model : LLMModelEnum ,
96+ model : string ,
10297 messages : CoreMessage [ ] ,
10398 onFinish : ( text : string , model : string ) => void ,
10499 ) {
105100 let modelInstance ;
106101 let finalModel : string ;
107-
108- if ( ! this . configService . get ( 'OPENAI_API_KEY' ) ) {
102+ if (
103+ ! this . configService . get ( 'OPENAI_API_KEY' ) ||
104+ ! this . configService . get ( 'ANTHROPIC_API_KEY' )
105+ ) {
109106 model = null ;
110107 }
111108
112109 switch ( model ) {
113- case LLMModelEnum . GPT35TURBO :
114- case LLMModelEnum . GPT4TURBO :
115- case LLMModelEnum . GPT4O :
116- finalModel = LLMMappings [ model ] ;
110+ case 'gpt-3.5-turbo' :
111+ case 'gpt-4-turbo' :
112+ case 'gpt-4o' :
113+ finalModel = model ;
117114 this . logger . info ( {
118- message : `Sending request to OpenAI with model: ${ model } ` ,
115+ message : `Sending request to OpenAI with model: ${ finalModel } ` ,
119116 where : `AIRequestsService.makeModelCall` ,
120117 } ) ;
121- modelInstance = openai ( model ) ;
118+ modelInstance = openai ( finalModel ) ;
122119 break ;
123120
124- case LLMModelEnum . CLAUDEOPUS :
125- case LLMModelEnum . CLAUDESONNET :
126- case LLMModelEnum . CLAUDEHAIKU :
127- finalModel = LLMMappings [ model ] ;
121+ case 'claude-3-opus-20240229' :
122+ case 'claude-3-5-sonnet-20241022' :
123+ case 'claude-3-haiku-20240307' :
124+ finalModel = model ;
128125 this . logger . info ( {
129126 message : `Sending request to Claude with model: ${ finalModel } ` ,
130127 where : `AIRequestsService.makeModelCall` ,
0 commit comments