mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
refactor(ai): initialize GoogleGenAI with process.env.GEMINI_API_KEY directly for embedding
This commit is contained in:
@@ -33,6 +33,7 @@ vi.mock('@google/genai', () => {
|
|||||||
describe('AI Activities', () => {
|
describe('AI Activities', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
|
process.env.GEMINI_API_KEY = 'test-key'
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should generate image embedding', async () => {
|
it('should generate image embedding', async () => {
|
||||||
@@ -45,7 +46,6 @@ describe('AI Activities', () => {
|
|||||||
const context = {
|
const context = {
|
||||||
agent: { config: { provider: 'google', model: 'gemini' } },
|
agent: { config: { provider: 'google', model: 'gemini' } },
|
||||||
asset: { id: 'a1', mediaType: 'image/png', storageKey: { key: 'test.png' } },
|
asset: { id: 'a1', mediaType: 'image/png', storageKey: { key: 'test.png' } },
|
||||||
dbProvider: { config: { apiKey: 'key' } },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await generateEmbeddingActivity({
|
const res = await generateEmbeddingActivity({
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export interface GenerateEmbeddingParams {
|
|||||||
context: {
|
context: {
|
||||||
agent: unknown
|
agent: unknown
|
||||||
asset: unknown
|
asset: unknown
|
||||||
dbProvider: unknown
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,16 +64,16 @@ export async function generateEmbeddingActivity(params: GenerateEmbeddingParams)
|
|||||||
usage: Usage
|
usage: Usage
|
||||||
}> {
|
}> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- context properties are fetched as JSON from the DB activity
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- context properties are fetched as JSON from the DB activity
|
||||||
const { asset, dbProvider } = params.context as any
|
const { asset } = params.context as any
|
||||||
|
|
||||||
if (!asset.mediaType) {
|
if (!asset.mediaType) {
|
||||||
throw ApplicationFailure.create({ message: 'asset has no media type', nonRetryable: true })
|
throw ApplicationFailure.create({ message: 'asset has no media type', nonRetryable: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiKey = dbProvider?.config?.apiKey
|
const apiKey = process.env.GEMINI_API_KEY
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw ApplicationFailure.create({
|
throw ApplicationFailure.create({
|
||||||
message: 'Google GenAI apiKey not found in provider config',
|
message: 'GEMINI_API_KEY environment variable is not configured',
|
||||||
nonRetryable: true,
|
nonRetryable: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -474,20 +474,9 @@ export async function getEmbeddingContextActivity(params: GetEmbeddingContextPar
|
|||||||
throw ApplicationFailure.create({ message: 'asset has no media type', nonRetryable: true })
|
throw ApplicationFailure.create({ message: 'asset has no media type', nonRetryable: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
const dbProvider = await prisma.provider.findFirst({
|
|
||||||
where: { teamId: params.teamId, name: 'google' },
|
|
||||||
})
|
|
||||||
if (!dbProvider) {
|
|
||||||
throw ApplicationFailure.create({
|
|
||||||
message: 'Google provider not found in database',
|
|
||||||
nonRetryable: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
agent,
|
agent,
|
||||||
asset,
|
asset,
|
||||||
dbProvider,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user