Skip to content

Commit

Permalink
对接 AI,联调完成
Browse files Browse the repository at this point in the history
  • Loading branch information
flycash committed Jul 18, 2024
1 parent 7f9f666 commit 1f87b43
Show file tree
Hide file tree
Showing 43 changed files with 546 additions and 352 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
> 这里比较蛋疼的是 401 和 403 的语义。所以我也没什么好纠结的,只是做一个简单的区分
## 商品SPU类别说明

从标准的电商结构上来说,类别是一个独立的模块,并且会做比较复杂的关系型数据库的设计。但是目前我们在这个项目里面,并不需要这么复杂的东西,所以只需要搞一个粗糙的二级目录就可以了。

- category0表示SPU顶级类别,可选值有product表示商品,code表示兑换码
- category1表示SPU次级类别,可选值有member/project等

两者组合语义如下:
- category0=product, category1=member 表示会员商品
- category0=code, category1=project 表示项目兑换码
- category0=product, category1=credit 表示积分(积分本身也可以购买)

## 营销模块说明

Expand Down
2 changes: 1 addition & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ qywechat:

zhipu:
apikey: ''
knowledgeId: ''
price: 0

mysql:
dsn: "webook:webook@tcp(mysql8:3306)/webook?charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=True&loc=Local&timeout=1s&readTimeout=3s&writeTimeout=3s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package biz
package ai

import (
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler"
)
import "github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler/credit"

// GPTBizHandler 近似于标记接口,也就是用于区分专属于业务的,和通用的 Handler
type GPTBizHandler interface {
handler.Handler
// Biz 它处理的业务
Biz() string
}
var ErrInsufficientCredit = credit.ErrInsufficientCredit
22 changes: 11 additions & 11 deletions internal/ai/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package ai

import (
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler"
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler/biz"
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler/config"
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler/credit"
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler/gpt/zhipu"
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler/log"
"github.com/ecodeclub/webook/internal/ai/internal/service/gpt/handler/record"
"github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler"
"github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler/biz"
"github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler/config"
"github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler/credit"
"github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler/log"
"github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler/platform/zhipu"
"github.com/ecodeclub/webook/internal/ai/internal/service/llm/handler/record"
"github.com/gotomicro/ego/core/econf"
)

Expand Down Expand Up @@ -51,12 +51,12 @@ func InitZhipu() *zhipu.Handler {

func InitQuestionExamineHandler(
common []handler.Builder,
// gpt 就是真正的出口
gpt handler.Handler) *biz.CompositionHandler {
// log -> cfg -> credit -> record -> question_examine -> gpt
// platform 就是真正的出口
platform handler.Handler) *biz.CompositionHandler {
// log -> cfg -> credit -> record -> question_examine -> platform
builder := biz.NewQuestionExamineBizHandlerBuilder()
common = append(common, builder)
res := biz.NewCombinedBizHandler("question_examine", common, gpt)
res := biz.NewCombinedBizHandler("question_examine", common, platform)
return res
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package domain

const BizQuestionExamine = "question_examine"

type GPTRequest struct {
type LLMRequest struct {
Biz string
Uid int64
// 请求id
Expand All @@ -15,12 +15,12 @@ type GPTRequest struct {
Config BizConfig
}

type GPTResponse struct {
type LLMResponse struct {
// 花费的token
Tokens int64
// 花费的金额
Amount int64
// gpt的回答
// llm 的回答
Answer string
}

Expand All @@ -37,7 +37,7 @@ type BizConfig struct {
PromptTemplate string
}

type GPTCredit struct {
type LLMCredit struct {
Id int64
Tid string
Uid int64
Expand All @@ -49,7 +49,7 @@ type GPTCredit struct {
Utime int64
}

type GPTRecord struct {
type LLMRecord struct {
Id int64
Tid string
Uid int64
Expand Down
Loading

0 comments on commit 1f87b43

Please sign in to comment.