11import { Agent } from "@mastra/core/agent" ;
22import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock" ;
3- import type { LanguageModelV2 } from "@ai-sdk/provider" ;
43import { fromNodeProviderChain } from "@aws-sdk/credential-providers" ;
5- import { createVertex } from "@ai-sdk/google-vertex" ;
4+ import { vertex } from "@ai-sdk/google-vertex" ;
65
76import { getMemory } from "../memory" ;
87import { instructions } from "./instructions" ;
@@ -13,49 +12,25 @@ import { getRepositoryCommits } from "../tools/getRepositoryCommits";
1312import { getRepositoryPullRequests } from "../tools/getRepositoryPullRequests" ;
1413import { getRepositoryStars } from "../tools/getRepositoryStars" ;
1514
16- // https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock#using-aws-sdk-credentials-chain-instance-profiles-instance-roles-ecs-roles-eks-service-accounts-etc
17- function createAWSModelProvider ( modelName : string ) : LanguageModelV2 {
18- return createAmazonBedrock ( {
19- credentialProvider : fromNodeProviderChain ( ) ,
20- } ) ( modelName ) ;
21- }
22-
23- // https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex
24- function createGCPModelProvider ( modelName : string ) : LanguageModelV2 {
25- const projectId = process . env . DEFANG_GCP_PROJECT ;
26- if ( projectId === undefined ) {
27- throw new Error (
28- "DEFANG_GCP_PROJECT is not defined in environment variables"
29- ) ;
30- }
31- const location = process . env . DEFANG_GCP_LOCATION ;
32- if ( location === undefined ) {
33- throw new Error (
34- "DEFANG_GCP_LOCATION is not defined in environment variables"
35- ) ;
36- }
37- return createVertex ( {
38- project : projectId ,
39- location : location ,
40- } ) ( modelName ) ;
41- }
42-
43- function getModel ( ) : LanguageModelV2 {
44- const provider = process . env . DEFANG_PROVIDER ;
15+ function getModel ( ) {
16+ const provider = process . env . AWS_REGION ? "aws" : "gcp" ;
4517 const modelName = process . env . LLM_MODEL ;
4618 if ( modelName === undefined ) {
4719 throw new Error ( "LLM_MODEL is not defined in environment variables" ) ;
4820 }
4921
50- if ( provider === "aws" ) {
51- return createAWSModelProvider ( modelName ) ;
52- }
53-
54- if ( provider === "gcp" ) {
55- return createGCPModelProvider ( modelName ) ;
22+ switch ( provider ) {
23+ case "aws" :
24+ // https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock#using-aws-sdk-credentials-chain-instance-profiles-instance-roles-ecs-roles-eks-service-accounts-etc
25+ return createAmazonBedrock ( {
26+ credentialProvider : fromNodeProviderChain ( ) ,
27+ } ) ( modelName ) ;
28+ case "gcp" :
29+ // https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex
30+ return vertex ( modelName ) ;
31+ default :
32+ return modelName ;
5633 }
57-
58- throw new Error ( `Unsupported DEFANG_PROVIDER: ${ provider } ` ) ;
5934}
6035
6136export const agent = new Agent ( {
0 commit comments