Skip to content

Commit

Permalink
feat: able to configure gpts categories
Browse files Browse the repository at this point in the history
Signed-off-by: bjwswang <[email protected]>
  • Loading branch information
bjwswang committed Mar 27, 2024
1 parent 797f359 commit 7f8cf97
Show file tree
Hide file tree
Showing 12 changed files with 569 additions and 43 deletions.
384 changes: 372 additions & 12 deletions apiserver/graph/generated/generated.go

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions apiserver/graph/generated/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions apiserver/graph/impl/gpt.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions apiserver/graph/schema/gpt.graphqls
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
type GPTQuery {
getGPT(name: String!): GPT!
listGPT(input: ListGPTInput!): PaginatedResult!
}

extend type Query{
GPT: GPTQuery
}

input ListGPTInput {

"""
Expand Down Expand Up @@ -79,3 +70,20 @@ type GPT {
"""
prologue: String
}

# GPTCategory in gpt store
type GPTCategory {
id: String!
name: String!
nameEn: String!
}

type GPTQuery {
getGPT(name: String!): GPT!
listGPT(input: ListGPTInput!): PaginatedResult!
listGPTCategory: [GPTCategory]!
}

extend type Query{
GPT: GPTQuery
}
19 changes: 19 additions & 0 deletions apiserver/pkg/gpt/gpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/kubeagi/arcadia/apiserver/pkg/chat"
"github.com/kubeagi/arcadia/apiserver/pkg/chat/storage"
"github.com/kubeagi/arcadia/apiserver/pkg/common"
"github.com/kubeagi/arcadia/pkg/config"
)

var (
Expand Down Expand Up @@ -92,6 +93,7 @@ func GetGPT(ctx context.Context, c client.Client, name string) (*generated.Gpt,
return app2gpt(app, c)
}

// ListGPT list all gpt
func ListGPT(ctx context.Context, c client.Client, input generated.ListGPTInput) (*generated.PaginatedResult, error) {
keyword := pointer.StringDeref(input.Keyword, "")
category := pointer.StringDeref(input.Category, "")
Expand Down Expand Up @@ -121,3 +123,20 @@ func ListGPT(ctx context.Context, c client.Client, input generated.ListGPTInput)
return app2gpt(app, c)
}, filter...)
}

// ListGPTCategory list all categories
func ListGPTCategory(ctx context.Context, c client.Client) ([]*generated.GPTCategory, error) {
categories, err := config.GetGPTsCategories(ctx, c)
if err != nil {
return nil, err
}
resp := make([]*generated.GPTCategory, len(categories))
for i := range categories {
resp[i] = &generated.GPTCategory{
Name: categories[i].Name,
NameEn: categories[i].NameEn,
ID: categories[i].ID,
}
}
return resp, nil
}
1 change: 1 addition & 0 deletions apiserver/service/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
)

type (
// FrowarAPI is the forward api handler which forward requests to other services
FrowarAPI struct{}
SummaryResp struct {
Summary string `json:"summary"`
Expand Down
2 changes: 1 addition & 1 deletion deploy/charts/arcadia/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: arcadia
description: A Helm chart(Also a KubeBB Component) for KubeAGI Arcadia
type: application
version: 0.3.22
version: 0.3.23
appVersion: "0.2.1"

keywords:
Expand Down
30 changes: 30 additions & 0 deletions deploy/charts/arcadia/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,36 @@ data:
user: {{ .Values.postgresql.global.postgresql.auth.username }}
password: {{ .Values.postgresql.global.postgresql.auth.password }}
database: {{ .Values.postgresql.global.postgresql.auth.database }}
# configurations for gpts
gptsConfig: |
categories:
- id: 1
name: "通用对话"
nameEn: "General Conversation"
- id: 2
name: "工作"
nameEn: "Work"
- id: 3
name: "学习"
nameEn: "Learning"
- id: 4
name: "效率"
nameEn: "Efficiency"
- id: 4
name: "人物扮演"
nameEn: "Character Play"
- id: 5
name: "游戏"
nameEn: "Game"
- id: 6
name: "生活"
nameEn: "Life"
- id: 7
name: "情感"
nameEn: "Emotion"
- id: 8
name: "动漫"
nameEn: "Anime"
{{- end }}
kind: ConfigMap
metadata:
Expand Down
15 changes: 6 additions & 9 deletions deploy/charts/arcadia/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,9 @@ chromadb:
ray:
# clusters provided by ray
# For more information on cluster configurations,please refer to http://kubeagi.k8s.com.cn/docs/Configuration/DistributedInference/run-inference-using-ray
clusters:
# cluster1 comes from https://github.com/kubeagi/arcadia/blob/main/config/samples/ray.io_v1_raycluster.yaml
- name: cluster1
headAddress: raycluster-kuberay-head-svc.kuberay-system.svc:6379
pythonVersion: 3.9.18
dashboardHost: raycluster-kuberay-head-svc.kuberay-system.svc:8265

rerank:
enabled: true
clusters: {}
# # cluster1 comes from https://github.com/kubeagi/arcadia/blob/main/config/samples/ray.io_v1_raycluster.yaml
# - name: cluster1
# headAddress: raycluster-kuberay-head-svc.kuberay-system.svc:6379
# pythonVersion: 3.9.18
# dashboardHost: raycluster-kuberay-head-svc.kuberay-system.svc:8265
2 changes: 2 additions & 0 deletions gqlgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ models:
resolver: true
listGPT:
resolver: true
listGPTCategory:
resolver: true
NodeQuery:
fields:
listNodes:
Expand Down
34 changes: 24 additions & 10 deletions pkg/config/config_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,41 @@ type Config struct {
// Gateway to access LLM api services
Gateway *Gateway `json:"gateway,omitempty"`

// Embedder specifies the default embedder for Arcadia to generate embeddings
Embedder *arcadiav1alpha1.TypedObjectReference `json:"embedder,omitempty"`

// VectorStore to access VectorStore api services
VectorStore *arcadiav1alpha1.TypedObjectReference `json:"vectorStore,omitempty"`

// Streamlit to get the Streamlit configuration
Streamlit *Streamlit `json:"streamlit,omitempty"`
// EmbeddingSuite here represents the system embedding service provided by the system
EmbeddingSuite

// Resource pool managed by Ray cluster
RayClusters []RayCluster `json:"rayClusters,omitempty"`

// the default rerank model
Rerank *arcadiav1alpha1.TypedObjectReference `json:"rerank,omitempty"`

// Streamlit to get the Streamlit configuration
// Deprecated: this field no longer maintained
Streamlit *Streamlit `json:"streamlit,omitempty"`
}

// EmbeddingSuite contains everything required to provide embedding service
type EmbeddingSuite struct {
// Embedder specifies the default embedder for Arcadia to generate embeddings
Embedder *arcadiav1alpha1.TypedObjectReference `json:"embedder,omitempty"`

// VectorStore to access VectorStore api services
VectorStore *arcadiav1alpha1.TypedObjectReference `json:"vectorStore,omitempty"`
}

// Gateway defines the way to access llm apis host by Arcadia
type Gateway struct {
// ExternalAPIServer is the api(LLM/Embedding) server address that can be accessed from internet
ExternalAPIServer string `json:"externalApiServer,omitempty"`
APIServer string `json:"apiServer,omitempty"`
Controller string `json:"controller,omitempty"`
// APIServer is api(LLM/Embedding) server which can be accessed within platform
APIServer string `json:"apiServer,omitempty"`
// Controller is the server address which is responsible for llm/embedding service registration
Controller string `json:"controller,omitempty"`
}

// Streamlit defines the configuration of streamlit app
// Deprecated: no longer maintained
type Streamlit struct {
Image string `json:"image"`
IngressClassName string `json:"ingressClassName"`
Expand All @@ -78,6 +89,7 @@ type RayCluster struct {
RayVersion string `json:"rayVersion,omitempty"`
}

// String format raycluster into string
func (rayCluster RayCluster) String() string {
return fmt.Sprintf("Name:%s HeadAddress: %s DashboardHost:%s PythonVersion:%s RayVersion: %s", rayCluster.Name, rayCluster.HeadAddress, rayCluster.DashboardHost, rayCluster.PythonVersion, rayCluster.RayVersion)
}
Expand All @@ -91,6 +103,7 @@ func (rayCluster RayCluster) GetRayVersion() string {
return rayCluster.RayVersion
}

// GetPythonVersion in ray cluster
func (rayCluster RayCluster) GetPythonVersion() string {
// Default python version is 3.9.5
if rayCluster.PythonVersion == "" {
Expand All @@ -99,6 +112,7 @@ func (rayCluster RayCluster) GetPythonVersion() string {
return rayCluster.PythonVersion
}

// DefaultRayCluster which can be used for vllm worker as local ray cluster
func DefaultRayCluster() RayCluster {
return RayCluster{
Name: "default",
Expand Down
79 changes: 79 additions & 0 deletions pkg/config/gpts_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
Copyright 2023 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package config

import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/utils/env"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kubeagi/arcadia/pkg/utils"
)

var (
ErrNoGPTsConfig = fmt.Errorf("gpts config in configmap is empty")
ErrNoGPTsConfigCategory = fmt.Errorf("gpts config Categories in comfigmap is not found")
)

// GPTsConfig is the configurations for GPT Store
type GPTsConfig struct {
Categories []Category `json:"categories,omitempty"`
}

// Category in gpt store
type Category struct {
ID string `json:"id"`
Name string `json:"name"`
NameEn string `json:"nameEn,omitempty"`
}

// GetGPTsConfig gets the gpts configurations
func GetGPTsConfig(ctx context.Context, c client.Client) (gptsConfig *GPTsConfig, err error) {
cmName := env.GetString(EnvConfigKey, EnvConfigDefaultValue)
if cmName == "" {
return nil, ErrNoConfigEnv
}
cmNamespace := utils.GetCurrentNamespace()
cm := &corev1.ConfigMap{}
if err = c.Get(ctx, client.ObjectKey{Name: cmName, Namespace: cmNamespace}, cm); err != nil {
return nil, err
}
value, ok := cm.Data["gptsConfig"]
if !ok || len(value) == 0 {
return nil, ErrNoConfig
}
if err = yaml.Unmarshal([]byte(value), &gptsConfig); err != nil {
return nil, err
}
return gptsConfig, nil
}

// GetGPTsCategories gets the gpts Categories
func GetGPTsCategories(ctx context.Context, c client.Client) (categories []Category, err error) {
gptsConfig, err := GetGPTsConfig(ctx, c)
if err != nil {
return nil, err
}
if gptsConfig.Categories == nil || len(gptsConfig.Categories) == 0 {
return nil, ErrNoGPTsConfigCategory
}
return gptsConfig.Categories, nil
}

0 comments on commit 7f8cf97

Please sign in to comment.