( assistant: AssistantUnrolled, authConfig: AuthConfig, )
| 58 | } |
| 59 | |
| 60 | export function getLlmApi( |
| 61 | assistant: AssistantUnrolled, |
| 62 | authConfig: AuthConfig, |
| 63 | ): [BaseLlmApi, ModelConfig] { |
| 64 | if (!assistant.models || assistant.models.length === 0) { |
| 65 | throw new Error("No models found in the configured assistant"); |
| 66 | } |
| 67 | |
| 68 | const model = assistant.models?.find( |
| 69 | (model) => |
| 70 | model?.roles?.includes("chat") || (model && model.roles === undefined), |
| 71 | ); |
| 72 | |
| 73 | if (!model) { |
| 74 | throw new Error( |
| 75 | "No models with the chat role found in the configured assistant", |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | const llmApi = createLlmApi(model, authConfig); |
| 80 | |
| 81 | if (!llmApi) { |
| 82 | throw new Error( |
| 83 | "Failed to initialize LLM. Please check your configuration.", |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | return [llmApi, model]; |
| 88 | } |
| 89 | |
| 90 | export function getApiClient( |
| 91 | accessToken: string | undefined | null, |
no test coverage detected