-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from sebiweise/feature/image_generation
Add image generation
- Loading branch information
Showing
30 changed files
with
796 additions
and
328 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
import { getImage } from '@/utils/server/ai_vendors/image'; | ||
|
||
import { ImageBody } from '@/types/chat'; | ||
|
||
export const runtime = 'edge'; | ||
|
||
const handler = async (req: Request): Promise<Response> => { | ||
const { model, prompt, apiKey, params } = | ||
(await req.json()) as ImageBody; | ||
|
||
const { error: imageError, images } = await getImage( | ||
model, | ||
params, | ||
apiKey, | ||
prompt | ||
); | ||
|
||
if (imageError) { | ||
let message = imageError; | ||
|
||
if (message.message) { | ||
message = message.message; | ||
} | ||
|
||
console.error(message); | ||
|
||
return new Response('Error', { | ||
status: 500, | ||
statusText: message, | ||
}); | ||
} | ||
|
||
return new Response(JSON.stringify(images), { status: 200 }); | ||
}; | ||
|
||
export { handler as GET, handler as POST }; |
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
25 changes: 25 additions & 0 deletions
25
apps/unsaged/components/Home/components/ChatZone/Screens/Chat/ImageChatMessage.tsx
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,25 @@ | ||
import { FC } from "react"; | ||
|
||
interface Props { | ||
src: string | undefined; | ||
alt?: string | undefined; | ||
width?: string | number | undefined; | ||
height?: string | number | undefined; | ||
} | ||
|
||
export const ImageChatMessage: FC<Props> = ({ src, alt, width, height }) => { | ||
if (!width && !height) { | ||
width = '1024px'; | ||
height = '1024px'; | ||
} | ||
return ( | ||
// eslint-disable-next-line @next/next/no-img-element | ||
<img | ||
src={src!} | ||
alt={alt!} | ||
width={parseInt(width as string)} | ||
height={parseInt(height as string)} | ||
className="m-1" | ||
/> | ||
); | ||
}; |
Oops, something went wrong.