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
f30a0f77
authored
Jul 14, 2025
by
RedwindA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
馃悰
fix: Use correct dto for non-stream xai
parent
5c55da29
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
+21
-19
relay/channel/xai/dto.go
+12
-13
relay/channel/xai/text.go
+9
-6
No files found.
relay/channel/xai/dto.go
View file @
f30a0f77
...
...
@@ -4,24 +4,24 @@ import "one-api/dto"
// ChatCompletionResponse represents the response from XAI chat completion API
type
ChatCompletionResponse
struct
{
Id
string
`json:"id"`
Object
string
`json:"object"`
Created
int64
`json:"created"`
Model
string
`json:"model"`
Choices
[]
dto
.
ChatCompletionsStreamResponseChoice
Usage
*
dto
.
Usage
`json:"usage"`
SystemFingerprint
string
`json:"system_fingerprint"`
Id
string
`json:"id"`
Object
string
`json:"object"`
Created
int64
`json:"created"`
Model
string
`json:"model"`
Choices
[]
dto
.
OpenAITextResponseChoice
`json:"choices"`
Usage
*
dto
.
Usage
`json:"usage"`
SystemFingerprint
string
`json:"system_fingerprint"`
}
// quality, size or style are not supported by xAI API at the moment.
type
ImageRequest
struct
{
Model
string
`json:"model"`
Prompt
string
`json:"prompt" binding:"required"`
N
int
`json:"n,omitempty"`
Model
string
`json:"model"`
Prompt
string
`json:"prompt" binding:"required"`
N
int
`json:"n,omitempty"`
// Size string `json:"size,omitempty"`
// Quality string `json:"quality,omitempty"`
ResponseFormat
string
`json:"response_format,omitempty"`
ResponseFormat
string
`json:"response_format,omitempty"`
// Style string `json:"style,omitempty"`
// User string `json:"user,omitempty"`
// ExtraFields json.RawMessage `json:"extra_fields,omitempty"`
}
\ No newline at end of file
}
relay/channel/xai/text.go
View file @
f30a0f77
...
...
@@ -82,21 +82,24 @@ func xAIHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.Response
defer
common
.
CloseResponseBodyGracefully
(
resp
)
responseBody
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
var
response
*
dto
.
SimpleResponse
err
=
common
.
Unmarshal
(
responseBody
,
&
response
)
if
err
!=
nil
{
return
nil
,
types
.
NewError
(
err
,
types
.
ErrorCodeBadResponseBody
)
}
response
.
Usage
.
CompletionTokens
=
response
.
Usage
.
TotalTokens
-
response
.
Usage
.
PromptTokens
response
.
Usage
.
CompletionTokenDetails
.
TextTokens
=
response
.
Usage
.
CompletionTokens
-
response
.
Usage
.
CompletionTokenDetails
.
ReasoningTokens
var
xaiResponse
ChatCompletionResponse
err
=
common
.
Unmarshal
(
responseBody
,
&
xaiResponse
)
if
err
!=
nil
{
return
nil
,
types
.
NewError
(
err
,
types
.
ErrorCodeBadResponseBody
)
}
xaiResponse
.
Usage
.
CompletionTokens
=
xaiResponse
.
Usage
.
TotalTokens
-
xaiResponse
.
Usage
.
PromptTokens
xaiResponse
.
Usage
.
CompletionTokenDetails
.
TextTokens
=
xaiResponse
.
Usage
.
CompletionTokens
-
xaiResponse
.
Usage
.
CompletionTokenDetails
.
ReasoningTokens
// new body
encodeJson
,
err
:=
common
.
Marshal
(
r
esponse
)
encodeJson
,
err
:=
common
.
Marshal
(
xaiR
esponse
)
if
err
!=
nil
{
return
nil
,
types
.
NewError
(
err
,
types
.
ErrorCodeBadResponseBody
)
}
common
.
IOCopyBytesGracefully
(
c
,
resp
,
encodeJson
)
return
&
r
esponse
.
Usage
,
nil
return
xaiR
esponse
.
Usage
,
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