-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
217 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# MidJourney Cloud Function | ||
|
||
This is a Google Cloud Function used to access the MidJourney Discord channel on my Discord Server and query the MidJourney bot to generate stuff. This function is triggered when a new document (generation) is created. | ||
|
||
## How it works | ||
|
||
```mermaid | ||
graph TB; | ||
weather_journey_app[Weather Journey App] -->|User selects a location| generation_process[Initiate Generation Process] | ||
generation_process -->|API request| weather_journey_image_api[Weather Journey Image API] | ||
weather_journey_image_api -->|Fetch weather data & craft ChatGPT prompt| midJourneyPrompt[Create Generation Document in Firestore] | ||
midJourneyPrompt -->|Document creation triggers| cloudFunction[Cloud Function] | ||
cloudFunction -->|Function invokes| midJourney[MidJourney Bot] | ||
classDef classDefault fill:#fff,stroke:#333,stroke-width:1px; | ||
classDef classLink stroke:#333,stroke-width:1px; | ||
class weather_journey_app,generation_process,weather_journey_image_api,midJourneyPrompt,cloudFunction,midJourney classDefault; | ||
linkStyle default classLink; | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export class Location { | ||
id: string; | ||
city: string; | ||
latitude: number; | ||
longitude: number; | ||
|
||
public constructor(id: string, city: string, latitude: number, longitude: number) { | ||
this.id = id; | ||
this.city = city; | ||
this.latitude = latitude; | ||
this.longitude = longitude; | ||
} | ||
|
||
static fromFirestoreDocument(id: any, data: any): Location { | ||
return new Location(id, data.city, data.latitude, data.longitude); | ||
} | ||
|
||
static fromJson(data: any): Location { | ||
return new Location(data.id, data.city, data.latitude, data.longitude); | ||
} | ||
|
||
toFirestoreDocument(): any { | ||
return { | ||
id: this.id, | ||
city: this.city, | ||
latitude: this.latitude, | ||
longitude: this.longitude, | ||
}; | ||
} | ||
|
||
toJson(): any { | ||
return { | ||
id: this.id, | ||
city: this.city, | ||
latitude: this.latitude, | ||
longitude: this.longitude, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
export class RootGenerationUser { | ||
id: string; | ||
firstname: string; | ||
lastname: string; | ||
email: string; | ||
|
||
public constructor( | ||
id: string, | ||
firstname: string, | ||
lastname: string, | ||
email: string, | ||
) { | ||
this.id = id; | ||
this.firstname = firstname; | ||
this.lastname = lastname; | ||
this.email = email; | ||
} | ||
|
||
static fromFirestoreDocument(id: any, data: any): RootGenerationUser { | ||
return new RootGenerationUser( | ||
id, | ||
data.firstname, | ||
data.lastname, | ||
data.email, | ||
); | ||
} | ||
|
||
static fromJson(data: any): RootGenerationUser { | ||
return new RootGenerationUser( | ||
data.id, | ||
data.firstname, | ||
data.lastname, | ||
data.email, | ||
); | ||
} | ||
|
||
toFirestoreDocument(): any { | ||
const firestoreDocument: any = { | ||
id: this.id, | ||
firstname: this.firstname, | ||
lastname: this.lastname, | ||
email: this.email, | ||
}; | ||
//Remove all undefined values | ||
Object.keys(firestoreDocument).forEach( | ||
(key) => | ||
firestoreDocument[key] === undefined && delete firestoreDocument[key], | ||
); | ||
|
||
return firestoreDocument; | ||
} | ||
|
||
toJson(): any { | ||
return { | ||
id: this.id, | ||
firstname: this.firstname, | ||
lastname: this.lastname, | ||
email: this.email, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {Generation} from "./generation.entity"; | ||
import {Location} from "./location.entity"; | ||
import {RootGenerationUser} from "./root-generation-user.entity"; | ||
|
||
export class RootGeneration { | ||
id: string; | ||
generation: Generation; | ||
location: Location; | ||
user: RootGenerationUser; | ||
|
||
public constructor(id: string, generation: Generation, location: Location, user: RootGenerationUser) { | ||
this.id = id; | ||
this.generation = generation; | ||
this.location = location; | ||
this.user = user; | ||
} | ||
|
||
static fromFirestoreDocument(id: any, data: any): RootGeneration { | ||
return new RootGeneration(id, data.generation, data.location, data.user); | ||
} | ||
|
||
static fromJson(data: any): RootGeneration { | ||
return new RootGeneration(data.id, data.generation, data.location, data.user); | ||
} | ||
|
||
toFirestoreDocument(): any { | ||
return { | ||
id: this.id, | ||
generation: (this.generation == null) ? null : this.generation.toFirestoreDocument(), | ||
location: (this.location == null) ? null : this.location.toFirestoreDocument(), | ||
user: (this.user == null) ? null : this.user.toFirestoreDocument(), | ||
}; | ||
} | ||
|
||
toJson(): any { | ||
return { | ||
id: this.id, | ||
generatedImage: (this.generation == null) ? null : this.generation.toJSON(), | ||
location: (this.location == null) ? null : this.location.toJson(), | ||
user: (this.user == null) ? null : this.user.toJson(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters