-
Notifications
You must be signed in to change notification settings - Fork 392
Added CreateModel functionality and tests #788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,7 @@ | |
|
||
import {FirebaseApp} from '../firebase-app'; | ||
import {FirebaseServiceInterface, FirebaseServiceInternalsInterface} from '../firebase-service'; | ||
import {Storage} from '../storage/storage'; | ||
import {MachineLearningApiClient, ModelResponse, OperationResponse} from './machine-learning-api-client'; | ||
import {MachineLearningApiClient, ModelResponse, OperationResponse, ModelContent} from './machine-learning-api-client'; | ||
import {FirebaseError} from '../utils/error'; | ||
|
||
import * as validator from '../utils/validator'; | ||
|
@@ -61,7 +60,6 @@ export class MachineLearning implements FirebaseServiceInterface { | |
|
||
private readonly client: MachineLearningApiClient; | ||
private readonly appInternal: FirebaseApp; | ||
private readonly storage: Storage; | ||
|
||
/** | ||
* @param {FirebaseApp} app The app for this ML service. | ||
|
@@ -76,7 +74,6 @@ export class MachineLearning implements FirebaseServiceInterface { | |
}); | ||
} | ||
|
||
this.storage = app.storage(); | ||
this.appInternal = app; | ||
this.client = new MachineLearningApiClient(app); | ||
} | ||
|
@@ -174,7 +171,7 @@ export class MachineLearning implements FirebaseServiceInterface { | |
return this.client.deleteModel(modelId); | ||
} | ||
|
||
private convertOptionstoContent(options: ModelOptions, forUpload?: boolean): Promise<object> { | ||
private convertOptionstoContent(options: ModelOptions, forUpload?: boolean): Promise<ModelContent> { | ||
const modelContent = deepCopy(options); | ||
|
||
if (forUpload && modelContent.tfliteModel?.gcsTfliteUri) { | ||
|
@@ -187,11 +184,10 @@ export class MachineLearning implements FirebaseServiceInterface { | |
throw new FirebaseMachineLearningError( | ||
'internal-error', | ||
`Error during signing upload url: ${err.message}`); | ||
|
||
}); | ||
}) as Promise<ModelContent>; | ||
} | ||
|
||
return Promise.resolve(modelContent); | ||
return Promise.resolve(modelContent) as Promise<ModelContent>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. I need to cast at the end after all the assignments are complete. |
||
} | ||
|
||
private signUrl(unsignedUrl: string): Promise<string> { | ||
|
@@ -207,7 +203,7 @@ export class MachineLearning implements FirebaseServiceInterface { | |
} | ||
const bucketName = matches[1]; | ||
const blobName = matches[2]; | ||
const bucket = this.storage.bucket(bucketName); | ||
const bucket = this.appInternal.storage().bucket(bucketName); | ||
const blob = bucket.file(blobName); | ||
return blob.getSignedUrl({ | ||
action: 'read', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,13 +121,11 @@ describe('MachineLearning', () => { | |
|
||
let machineLearning: MachineLearning; | ||
let mockApp: FirebaseApp; | ||
let mockCredentialApp: FirebaseApp; | ||
|
||
const stubs: sinon.SinonStub[] = []; | ||
|
||
before(() => { | ||
mockApp = mocks.app(); | ||
mockCredentialApp = mocks.mockCredentialApp(); | ||
machineLearning = new MachineLearning(mockApp); | ||
}); | ||
|
||
|
@@ -161,16 +159,6 @@ describe('MachineLearning', () => { | |
+ 'instance.'); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to keep this test, but just update it to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
||
it('should throw given invalid credential', () => { | ||
const expectedError = 'Failed to initialize Google Cloud Storage client with ' + | ||
'the available credential. Must initialize the SDK with a certificate credential ' + | ||
'or application default credentials to use Cloud Storage API.'; | ||
expect(() => { | ||
const machineLearningAny: any = MachineLearning; | ||
return new machineLearningAny(mockCredentialApp); | ||
}).to.throw(expectedError); | ||
}); | ||
|
||
it('should not throw given a valid app', () => { | ||
expect(() => { | ||
return new MachineLearning(mockApp); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of weird. Just define your constant to be
ModelContent
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do that I wouldn't be able to assign to it here: modelContent.tfliteModel!.gcsTfliteUri = uri;
because all the ModelContent properties are read only.
(That's why I initially left it as Promise<object>)