Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Response struct {

type ModelListResp struct {
Models []ModelListItem `json:"models"`
Error string `json:"error"`
}

type ModelListItem struct {
Expand Down Expand Up @@ -76,22 +77,22 @@ type ModelResponseParser interface {
}

type GithubModel struct {
ID string `json:"id"`
Name string `json:"name"`
Registry string `json:"registry"`
Publisher string `json:"publisher"`
Summary string `json:"summary"`
RateLimitTier string `json:"rate_limit_tier"`
HTMLURL string `json:"html_url"`
Version string `json:"version"`
Capabilities []string `json:"capabilities"`
Limits struct {
ID string `json:"id"`
Name string `json:"name"`
Registry string `json:"registry"`
Publisher string `json:"publisher"`
Summary string `json:"summary"`
RateLimitTier string `json:"rate_limit_tier"`
HTMLURL string `json:"html_url"`
Version string `json:"version"`
Capabilities []string `json:"capabilities"`
Limits struct {
MaxInputTokens int `json:"max_input_tokens"`
MaxOutputTokens int `json:"max_output_tokens"`
} `json:"limits"`
Tags []string `json:"tags"`
SupportedInputModalities []string `json:"supported_input_modalities"`
SupportedOutputModalities []string `json:"supported_output_modalities"`
Tags []string `json:"tags"`
SupportedInputModalities []string `json:"supported_input_modalities"`
SupportedOutputModalities []string `json:"supported_output_modalities"`
}

type GithubResp []GithubModel
Expand Down
20 changes: 15 additions & 5 deletions test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ func NewModelKit(
func (p *ModelKit) GetModelList(c echo.Context) error {
var req domain.ModelListReq
if err := c.Bind(&req); err != nil {
return c.JSON(http.StatusBadRequest, domain.Response{
return c.JSON(http.StatusOK, domain.Response{
Success: false,
Message: "参数绑定失败: " + err.Error(),
Data: nil,
})
}
fmt.Println("list model req:", req)

resp, err := usecase.ModelList(c.Request().Context(), &req)
if err != nil {
fmt.Println("err:", err)
return c.JSON(http.StatusInternalServerError, domain.Response{
Success: false,
return c.JSON(http.StatusOK, domain.Response{
Success: true,
Message: err.Error(),
Data: resp,
})
}

Expand All @@ -65,13 +67,21 @@ func (p *ModelKit) CheckModel(c echo.Context) error {
}
fmt.Println("check model req:", req)

resp, _ := usecase.CheckModel(c.Request().Context(), &req)
resp, err := usecase.CheckModel(c.Request().Context(), &req)
if err != nil {
fmt.Println("err:", err)
return c.JSON(http.StatusOK, domain.Response{
Success: true,
Message: err.Error(),
Data: resp,
})
}

// 如果检查过程中有错误,返回错误响应
if resp.Error != "" {
fmt.Println("resp.Error:", resp.Error)
return c.JSON(http.StatusOK, domain.Response{
Success: false,
Success: true,
Message: resp.Error,
Data: resp,
})
Expand Down
26 changes: 7 additions & 19 deletions test/ui_example/src/localService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ApiResponse<T = any> {
// 模型列表响应
interface ModelListResponse {
models: ModelListItem[];
error?: string;
}

// 模型检查响应
Expand Down Expand Up @@ -75,8 +76,7 @@ export class LocalModelService implements ModelService {
return result;
}

async listModel(data: ListModelReq): Promise<{ models: ModelListItem[] }> {
try {
async listModel(data: ListModelReq): Promise<{ models: ModelListItem[]; error?: string }> {
const queryParams = new URLSearchParams();
if (data.provider) queryParams.append('provider', data.provider);
if (data.model_type) queryParams.append('model_type', data.model_type);
Expand All @@ -88,37 +88,25 @@ export class LocalModelService implements ModelService {
const response = await this.request<ModelListResponse>(url, {
method: 'GET',
});
return { models: response.models };
} catch (error) {
console.error('Failed to list models:', error);
throw error;
}
console.log('listModel response:', response);
return { models: response.models, error: response.error };
}

async checkModel(data: CheckModelReq): Promise<{ model: Model; error?: string }> {
try {
const queryParams = new URLSearchParams();
console.log('checkModel data:', data);
if (data.provider) queryParams.append('provider', data.provider);
if (data.model_name) queryParams.append('model_name', data.model_name);
if (data.base_url) queryParams.append('base_url', data.base_url);
if (data.api_key) queryParams.append('api_key', data.api_key);
if (data.api_header) queryParams.append('api_header', data.api_header);
if (data.model_type) queryParams.append('model_type', data.model_type);
const url = `/checkmodel${queryParams.toString() ? '?' + queryParams.toString() : ''}`;
console.log('checkModel url:', url);
const response = await this.request<CheckModelResponse>(url, {
method: 'GET',
});

if (response.error) {
throw new Error(response.error);
}

return { model: response.model };
} catch (error) {
console.error('Failed to list models:', error);
throw error;
}
console.log('checkModel response:', response);
return { model: response.model, error: response.error };
}

async updateModel(data: UpdateModelReq): Promise<{ model: Model }> {
Expand Down
2 changes: 1 addition & 1 deletion ui/ModelModal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yokowu/modelkit-ui",
"version": "0.5.1",
"version": "0.6.0",
"description": "A reusable AI model configuration modal component for React applications",
"private": false,
"type": "module",
Expand Down
Loading