Skip to content

Commit 4286966

Browse files
author
Dev Agent
committed
Upgrade gradio SDK to 6.2.0 while maintaining 5.1.0 support
1 parent 019bd02 commit 4286966

File tree

11 files changed

+526
-179
lines changed

11 files changed

+526
-179
lines changed

AGENTS.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# AGENTS Guidelines for This Repository
2+
3+
This repository is a Go project following the **microservice** architecture design. Services including:
4+
5+
- **API**: The API service handles HTTP requests and responses. It is the entry point for external clients to interact with the system.
6+
- **User**: The User service handles user-related operations, such as user registration, login, and profile management. All requests are proxied to this service from the API service.
7+
- **Accounting**: The Accounting service handles accounting-related operations, such as recording user token or hardware resource usage, or updating user balances. All requests are proxied to this service from the API service.
8+
- **Moderation**: The Moderation service handles content moderation operations, such as flagging inappropriate text or images. All requests are proxied to this service from the API service.
9+
- **DataViewer**: The DataViewer service handles dataset preview operations, such as fetching dataset metadata or previewing dataset files. All requests are proxied to this service from the API service.
10+
- **Notification**: The Notification service handles sending notifications to users, such as email or push notifications. All requests are proxied to this service from the API service.
11+
- **Payment**: The Payment service handles payment operations, such as processing payments or refunding payments. All requests are proxied to this service from the API service.
12+
- **AIGateway**: The AIGateway service handles AI model inference operations, such as running AI models or generating AI outputs. It's another entry point for external clients to interact with the AI models.
13+
- **Runner**: The Runner service is a bridge between api service and Kubernetes cluster. It handles deployment of models, spaces.
14+
- **LogCollector**: The LogCollector service handles collecting logs from Kubernetes cluster. All logs are sent to this service from the Runner service and API service.
15+
16+
# Structure
17+
Every service follows the layered architecture design: handler -> component -> builder (database, rpc, git, etc.).
18+
19+
- The handler layer handles HTTP requests and responses.
20+
- The component layer handles business logic and coordinates between different layers.
21+
- The builder layer handles low-level operations, such as database access, RPC calls, or Git operations.
22+
- Every golang file should have a corresponding `*_test.go` file for unit tests.
23+
24+
Folders relative to the root of the repository for each service:
25+
26+
| Service | Folder |
27+
|---------|--------|
28+
| API | api |
29+
| User | user |
30+
| Accounting | accounting |
31+
| Moderation | moderation |
32+
| DataViewer | dataviewer |
33+
| Notification | notification |
34+
| Payment | payment |
35+
| AIGateway | aigateway |
36+
| Runner | runner |
37+
| LogCollector | logcollector |
38+
39+
## Examples
40+
41+
### Router
42+
43+
- `api/router/api.go` is an example of a router that registers HTTP routes and their corresponding handlers for common functionality across services.
44+
- `accounting/router/api.go` is an example of a router that registers HTTP routes and their corresponding handlers for the Accounting service.
45+
- `runner/router/api.go` is an example of a router that registers HTTP routes and their corresponding handlers for the runner service.
46+
47+
### Handler Layer
48+
49+
- `api/handler/space.go` is an example of a handler that deals with space-related HTTP requests.
50+
- `api/handler/evaluation.go` is an example of a handler that deals with evaluation-related HTTP requests.
51+
52+
### Component Layer
53+
54+
- `component/space.go` is an example of a component that deals with space-related business logic.
55+
- `component/evaluation.go` is an example of a component that deals with evaluation-related business logic.
56+
57+
### Database Builder Layer
58+
59+
- `builder/store/database/space.go` is an example of a builder that deals with space-related database operations.
60+
61+
### Database Migration
62+
63+
- `builder/store/database/migrations/20240201061926_create_spaces.go` is an example of a database migration script that creates a space table.
64+
- use `go run cmd/csghub-server/main.go migration create_go` to generate a go database migration script.
65+
- use `go run cmd/csghub-server/main.go migration create_sql` to generate a sql database migration script.
66+
67+
### Space Deploy
68+
69+
- `builder/deploy/deployer.go` create build and deploy task in database, then create temporal workflow to run the task.
70+
- `api/workflow/activity/deploy_activity.go` impletements temporal activities to run the build and deploy task by call runner api.
71+
- `runner/handler/imagebuilder.go` implements runner api to trigger image builder process by call image builder component.
72+
- `runner/component/imagebuilder.go` implements runner component to trigger deploy process by call knative api.
73+
- `runner/handler/service.go` implements runner api to trigger deploy process by call deploy component.
74+
- `runner/component/service.go` implements runner component to trigger deploy process by call knative api.
75+
- `docker/spaces/builder/Dockerfile*` are Dockerfile that builds the space image.
76+
77+
## Code Style & Conventions:
78+
79+
- Each layer's interface should only expose data structures defined within its own layer or common type definitions from the common.types package. For example, interfaces in the Component layer (such as UserComponent) should not return data structures from the underlying database layer (such as database.User structure), as the database layer is considered lower-level than the component layer.
80+
- Write unit tests for new code.
81+
- Use struct data types instead of primitive types for function parameters and return values.
82+
- All variables should be named in camelCase.
83+
- Variables should be declared at the smallest possible scope under `common/types`.
84+
85+
### Do
86+
87+
### Do Not
88+
89+
## Testing
90+
91+
- Use `make mock_gen GO_TAGS={go.buildTags}` to generate mock implementations for the interfaces.
92+
- Use `make test GO_TAGS={go.buildTags}` to run all tests in project.
93+
- Mock dependencies (e.g., database, RPC clients) using tools like `mockery`.
94+
95+
## Tools
96+
97+
- Search `Makefile` for running, building, testing, and linting tools.
98+
- Swagger doc is generated by `swag` tool, and it will be served by handler layer.
99+
100+
## Commit & Pull Request Guidelines:
101+
102+
- Each PR must include a clear description of the changes made and their impact, including root cause analysis if applicable, and solution details, and local test result.
103+
104+
## Specific Instructions

api/workflow/activity/deploy_activity.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@ func (a *DeployActivity) createBuildRequest(ctx context.Context, task *database.
470470
return nil, fmt.Errorf("invalid repository path format: %s", repoInfo.Path)
471471
}
472472

473-
sdkVersion := a.determineSDKVersion(repoInfo)
474-
475473
lastCommitReq := gitserver.GetRepoLastCommitReq{
476474
RepoType: types.RepositoryType(repoInfo.RepoType),
477475
Namespace: pathParts[0],
@@ -490,7 +488,7 @@ func (a *DeployActivity) createBuildRequest(ctx context.Context, task *database.
490488
PythonVersion: "3.10",
491489
Sdk: repoInfo.Sdk,
492490
DriverVersion: repoInfo.DriverVersion,
493-
Sdk_version: sdkVersion,
491+
Sdk_version: repoInfo.SdkVersion,
494492
SpaceURL: repoInfo.HTTPCloneURL,
495493
GitRef: task.Deploy.GitBranch,
496494
UserId: accessToken.User.Username,
@@ -588,21 +586,6 @@ func (a *DeployActivity) createDeployRequest(ctx context.Context, task *database
588586
}, nil
589587
}
590588

591-
func (a *DeployActivity) determineSDKVersion(repoInfo common.RepoInfo) string {
592-
if repoInfo.SdkVersion != "" {
593-
return repoInfo.SdkVersion
594-
}
595-
596-
switch repoInfo.Sdk {
597-
case types.GRADIO.Name:
598-
return types.GRADIO.Version
599-
case types.STREAMLIT.Name:
600-
return types.STREAMLIT.Version
601-
default:
602-
return ""
603-
}
604-
}
605-
606589
func (a *DeployActivity) parseHardware(input string) string {
607590
if strings.Contains(input, "GPU") || strings.Contains(input, "NVIDIA") {
608591
return "gpu"

api/workflow/activity/deploy_activity_test.go

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"opencsg.com/csghub-server/builder/deploy/common"
10+
"opencsg.com/csghub-server/builder/git/gitserver"
1011
"opencsg.com/csghub-server/builder/store/database"
1112
"opencsg.com/csghub-server/common/config"
1213
"opencsg.com/csghub-server/common/types"
@@ -91,56 +92,41 @@ func setupTest(t *testing.T) *testEnv {
9192
}
9293
}
9394

94-
// TestActivities_determineSDKVersion tests the determineSDKVersion method
95-
func TestActivities_determineSDKVersion(t *testing.T) {
95+
// TestActivities_createBuildRequest tests the createBuildRequest method
96+
func TestActivities_createBuildRequest(t *testing.T) {
9697
tester := setupTest(t)
9798

98-
// Test cases
99-
testCases := []struct {
100-
name string
101-
repoInfo common.RepoInfo
102-
expectedSDK string
103-
}{
104-
{
105-
name: "With explicit SDK version",
106-
repoInfo: common.RepoInfo{
107-
SdkVersion: "custom-version",
108-
Sdk: "some-other-sdk",
109-
},
110-
expectedSDK: "custom-version",
111-
},
112-
{
113-
name: "With GRADIO SDK",
114-
repoInfo: common.RepoInfo{
115-
SdkVersion: "",
116-
Sdk: types.GRADIO.Name,
117-
},
118-
expectedSDK: types.GRADIO.Version,
119-
},
120-
{
121-
name: "With STREAMLIT SDK",
122-
repoInfo: common.RepoInfo{
123-
SdkVersion: "",
124-
Sdk: types.STREAMLIT.Name,
125-
},
126-
expectedSDK: types.STREAMLIT.Version,
127-
},
128-
{
129-
name: "With unknown SDK",
130-
repoInfo: common.RepoInfo{
131-
SdkVersion: "",
132-
Sdk: "unknown-sdk",
133-
},
134-
expectedSDK: "",
99+
task := &database.DeployTask{
100+
Deploy: &database.Deploy{
101+
UserID: 1,
135102
},
136103
}
137104

138-
for _, tc := range testCases {
139-
t.Run(tc.name, func(t *testing.T) {
140-
sdkVersion := tester.activities.determineSDKVersion(tc.repoInfo)
141-
require.Equal(t, tc.expectedSDK, sdkVersion)
142-
})
105+
repoInfo := common.RepoInfo{
106+
Path: "org/space",
107+
SdkVersion: "6.2.0",
143108
}
109+
110+
tester.mockTokenStore.EXPECT().FindByUID(tester.ctx, task.Deploy.UserID).Return(&database.AccessToken{
111+
Token: "test-token",
112+
User: &database.User{
113+
Username: "uname",
114+
},
115+
}, nil)
116+
117+
tester.mockGitServer.EXPECT().GetRepoLastCommit(tester.ctx, gitserver.GetRepoLastCommitReq{
118+
RepoType: types.RepositoryType(repoInfo.RepoType),
119+
Namespace: "org",
120+
Name: "space",
121+
Ref: task.Deploy.GitBranch,
122+
}).Return(&types.Commit{
123+
ID: "id",
124+
}, nil)
125+
126+
r, err := tester.activities.createBuildRequest(tester.ctx, task, repoInfo)
127+
require.Nil(t, err)
128+
require.Equal(t, r.Sdk_version, repoInfo.SdkVersion)
129+
require.Equal(t, r.LastCommitID, "id")
144130
}
145131

146132
// TestActivities_handleDeployError tests the handleDeployError method

common/types/space.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type SDKConfig struct {
1414
var (
1515
GRADIO = SDKConfig{
1616
Name: "gradio",
17-
Version: "3.37.0",
17+
Version: "6.2.0",
1818
Port: 7860,
1919
Image: "",
2020
}

component/space.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ func (c *spaceComponentImpl) Create(ctx context.Context, req types.CreateSpaceRe
7474
req.DefaultBranch = types.MainBranch
7575
}
7676

77+
if req.Sdk == types.GRADIO.Name && len(req.SdkVersion) < 1 {
78+
req.SdkVersion = types.GRADIO.Version
79+
}
80+
81+
if req.Sdk == types.STREAMLIT.Name && len(req.SdkVersion) < 1 {
82+
req.SdkVersion = types.STREAMLIT.Version
83+
}
84+
7785
req.Nickname = nickname
7886
req.RepoType = types.SpaceRepo
7987
req.Readme = generateReadmeData(req.License)

0 commit comments

Comments
 (0)