Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
18209c7d
authored
Aug 19, 2025
by
t0ng7u
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/alpha' into alpha
parents
6c4777bc
69686cdc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
10 deletions
+71
-10
relay/channel/gemini/adaptor.go
+15
-8
relay/channel/vertex/adaptor.go
+56
-2
No files found.
relay/channel/gemini/adaptor.go
View file @
18209c7d
...
@@ -59,15 +59,22 @@ func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInf
...
@@ -59,15 +59,22 @@ func (a *Adaptor) ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInf
return
nil
,
errors
.
New
(
"not supported model for image generation"
)
return
nil
,
errors
.
New
(
"not supported model for image generation"
)
}
}
// convert size to aspect ratio
// convert size to aspect ratio
but allow user to specify aspect ratio
aspectRatio
:=
"1:1"
// default aspect ratio
aspectRatio
:=
"1:1"
// default aspect ratio
switch
request
.
Size
{
size
:=
strings
.
TrimSpace
(
request
.
Size
)
case
"1024x1024"
:
if
size
!=
""
{
aspectRatio
=
"1:1"
if
strings
.
Contains
(
size
,
":"
)
{
case
"1024x1792"
:
aspectRatio
=
size
aspectRatio
=
"9:16"
}
else
{
case
"1792x1024"
:
switch
size
{
aspectRatio
=
"16:9"
case
"1024x1024"
:
aspectRatio
=
"1:1"
case
"1024x1792"
:
aspectRatio
=
"9:16"
case
"1792x1024"
:
aspectRatio
=
"16:9"
}
}
}
}
// build gemini imagen request
// build gemini imagen request
...
...
relay/channel/vertex/adaptor.go
View file @
18209c7d
...
@@ -66,8 +66,8 @@ func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInf
...
@@ -66,8 +66,8 @@ func (a *Adaptor) ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInf
}
}
func
(
a
*
Adaptor
)
ConvertImageRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
ImageRequest
)
(
any
,
error
)
{
func
(
a
*
Adaptor
)
ConvertImageRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
ImageRequest
)
(
any
,
error
)
{
//TODO implement me
geminiAdaptor
:=
gemini
.
Adaptor
{}
return
nil
,
errors
.
New
(
"not implemented"
)
return
geminiAdaptor
.
ConvertImageRequest
(
c
,
info
,
request
)
}
}
func
(
a
*
Adaptor
)
Init
(
info
*
relaycommon
.
RelayInfo
)
{
func
(
a
*
Adaptor
)
Init
(
info
*
relaycommon
.
RelayInfo
)
{
...
@@ -181,6 +181,60 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
...
@@ -181,6 +181,60 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
if
request
==
nil
{
if
request
==
nil
{
return
nil
,
errors
.
New
(
"request is nil"
)
return
nil
,
errors
.
New
(
"request is nil"
)
}
}
if
a
.
RequestMode
==
RequestModeGemini
&&
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"imagen"
)
{
prompt
:=
""
for
_
,
m
:=
range
request
.
Messages
{
if
m
.
Role
==
"user"
{
prompt
=
m
.
StringContent
()
if
prompt
!=
""
{
break
}
}
}
if
prompt
==
""
{
if
p
,
ok
:=
request
.
Prompt
.
(
string
);
ok
{
prompt
=
p
}
}
if
prompt
==
""
{
return
nil
,
errors
.
New
(
"prompt is required for image generation"
)
}
imgReq
:=
dto
.
ImageRequest
{
Model
:
request
.
Model
,
Prompt
:
prompt
,
N
:
1
,
Size
:
"1024x1024"
,
}
if
request
.
N
>
0
{
imgReq
.
N
=
uint
(
request
.
N
)
}
if
request
.
Size
!=
""
{
imgReq
.
Size
=
request
.
Size
}
if
len
(
request
.
ExtraBody
)
>
0
{
var
extra
map
[
string
]
any
if
err
:=
json
.
Unmarshal
(
request
.
ExtraBody
,
&
extra
);
err
==
nil
{
if
n
,
ok
:=
extra
[
"n"
]
.
(
float64
);
ok
&&
n
>
0
{
imgReq
.
N
=
uint
(
n
)
}
if
size
,
ok
:=
extra
[
"size"
]
.
(
string
);
ok
{
imgReq
.
Size
=
size
}
// accept aspectRatio in extra body (top-level or under parameters)
if
ar
,
ok
:=
extra
[
"aspectRatio"
]
.
(
string
);
ok
&&
ar
!=
""
{
imgReq
.
Size
=
ar
}
if
params
,
ok
:=
extra
[
"parameters"
]
.
(
map
[
string
]
any
);
ok
{
if
ar
,
ok
:=
params
[
"aspectRatio"
]
.
(
string
);
ok
&&
ar
!=
""
{
imgReq
.
Size
=
ar
}
}
}
}
c
.
Set
(
"request_model"
,
request
.
Model
)
return
a
.
ConvertImageRequest
(
c
,
info
,
imgReq
)
}
if
a
.
RequestMode
==
RequestModeClaude
{
if
a
.
RequestMode
==
RequestModeClaude
{
claudeReq
,
err
:=
claude
.
RequestOpenAI2ClaudeMessage
(
c
,
*
request
)
claudeReq
,
err
:=
claude
.
RequestOpenAI2ClaudeMessage
(
c
,
*
request
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment