Skip to content

Commit

Permalink
feat: add more config for app
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
  • Loading branch information
Abirdcfly committed Dec 18, 2023
1 parent 231890f commit 8248519
Show file tree
Hide file tree
Showing 27 changed files with 601 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/example_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
run: tests/example-test.sh
- name: Upload logs if test fail
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}-${{ matrix.no }}.logs
path: ${{ env.LOG_DIR }}
27 changes: 25 additions & 2 deletions api/app-node/chain/v1alpha1/llmchain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,36 @@ type Output struct {
}

type CommonChainConfig struct {
// 记忆相关参数
// for memory
Memory Memory `json:"memory,omitempty"`

// MaxTokens is the maximum number of tokens to generate to use in a llm call.
MaxTokens int `json:"maxTokens,omitempty"`
// Temperature is the temperature for sampling to use in a llm call, between 0 and 1.
//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Maximum=1
Temperature float64 `json:"temperature,omitempty"`
// StopWords is a list of words to stop on to use in a llm call.
StopWords []string `json:"stopWords,omitempty"`
// TopK is the number of tokens to consider for top-k sampling in a llm call.
TopK int `json:"topK,omitempty"`
// TopP is the cumulative probability for top-p sampling in a llm call.
TopP float64 `json:"topP,omitempty"`
// Seed is a seed for deterministic sampling in a llm call.
Seed int `json:"seed,omitempty"`
// MinLength is the minimum length of the generated text in a llm call.
MinLength int `json:"minLength,omitempty"`
// MaxLength is the maximum length of the generated text in a llm call.
MaxLength int `json:"maxLength,omitempty"`
// RepetitionPenalty is the repetition penalty for sampling in a llm call.
RepetitionPenalty float64 `json:"repetitionPenalty,omitempty"`
}

type Memory struct {
// 能记住的最大 token 数
// MaxTokenLimit is the maximum number of tokens to keep in memory. Can only use MaxTokenLimit or ConversionWindowSize.
MaxTokenLimit int `json:"maxTokenLimit,omitempty"`
// ConversionWindowSize is the maximum number of conversation rounds in memory.Can only use MaxTokenLimit or ConversionWindowSize.
ConversionWindowSize int `json:"conversionWindowSize,omitempty"`
}

// LLMChainStatus defines the observed state of LLMChain
Expand Down
9 changes: 7 additions & 2 deletions api/app-node/chain/v1alpha1/zz_generated.deepcopy.go

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

11 changes: 8 additions & 3 deletions api/app-node/retriever/v1alpha1/knowledgebaseretriever_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (

// KnowledgeBaseRetrieverSpec defines the desired state of KnowledgeBaseRetriever
type KnowledgeBaseRetrieverSpec struct {
v1alpha1.CommonSpec `json:",inline"`
Input Input `json:"input,omitempty"`
Output Output `json:"output,omitempty"`
v1alpha1.CommonSpec `json:",inline"`
Input Input `json:"input,omitempty"`
Output Output `json:"output,omitempty"`
CommonRetrieverConfig `json:",inline"`
}

type Input struct {
Expand All @@ -38,6 +39,10 @@ type Output struct {
node.CommonOrInPutOrOutputRef `json:",inline"`
}

type CommonRetrieverConfig struct {
ScoreThreshold float32 `json:"scoreThreshold,omitempty"` // TODO
}

// KnowledgeBaseRetrieverStatus defines the observed state of KnowledgeBaseRetriever
type KnowledgeBaseRetrieverStatus struct {
// ObservedGeneration is the last observed generation.
Expand Down
16 changes: 16 additions & 0 deletions api/app-node/retriever/v1alpha1/zz_generated.deepcopy.go

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

48 changes: 46 additions & 2 deletions config/crd/bases/chain.arcadia.kubeagi.k8s.com.cn_llmchains.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,30 @@ spec:
- llm
- prompt
type: object
maxLength:
description: MaxLength is the maximum length of the generated text
in a llm call.
type: integer
maxTokens:
description: MaxTokens is the maximum number of tokens to generate
to use in a llm call.
type: integer
memory:
description: 记忆相关参数
description: for memory
properties:
conversionWindowSize:
description: ConversionWindowSize is the maximum number of conversation
rounds in memory.Can only use MaxTokenLimit or ConversionWindowSize.
type: integer
maxTokenLimit:
description: 能记住的最大 token 数
description: MaxTokenLimit is the maximum number of tokens to
keep in memory. Can only use MaxTokenLimit or ConversionWindowSize.
type: integer
type: object
minLength:
description: MinLength is the minimum length of the generated text
in a llm call.
type: integer
output:
properties:
apiGroup:
Expand All @@ -111,6 +128,33 @@ spec:
description: Name is the name of resource being referenced
type: string
type: object
repetitionPenalty:
description: RepetitionPenalty is the repetition penalty for sampling
in a llm call.
type: number
seed:
description: Seed is a seed for deterministic sampling in a llm call.
type: integer
stopWords:
description: StopWords is a list of words to stop on to use in a llm
call.
items:
type: string
type: array
temperature:
description: Temperature is the temperature for sampling to use in
a llm call, between 0 and 1.
maximum: 1
minimum: 0
type: number
topK:
description: TopK is the number of tokens to consider for top-k sampling
in a llm call.
type: integer
topP:
description: TopP is the cumulative probability for top-p sampling
in a llm call.
type: number
required:
- input
- output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,30 @@ spec:
- prompt
- retriever
type: object
maxLength:
description: MaxLength is the maximum length of the generated text
in a llm call.
type: integer
maxTokens:
description: MaxTokens is the maximum number of tokens to generate
to use in a llm call.
type: integer
memory:
description: 记忆相关参数
description: for memory
properties:
conversionWindowSize:
description: ConversionWindowSize is the maximum number of conversation
rounds in memory.Can only use MaxTokenLimit or ConversionWindowSize.
type: integer
maxTokenLimit:
description: 能记住的最大 token 数
description: MaxTokenLimit is the maximum number of tokens to
keep in memory. Can only use MaxTokenLimit or ConversionWindowSize.
type: integer
type: object
minLength:
description: MinLength is the minimum length of the generated text
in a llm call.
type: integer
output:
properties:
apiGroup:
Expand All @@ -132,6 +149,33 @@ spec:
description: Name is the name of resource being referenced
type: string
type: object
repetitionPenalty:
description: RepetitionPenalty is the repetition penalty for sampling
in a llm call.
type: number
seed:
description: Seed is a seed for deterministic sampling in a llm call.
type: integer
stopWords:
description: StopWords is a list of words to stop on to use in a llm
call.
items:
type: string
type: array
temperature:
description: Temperature is the temperature for sampling to use in
a llm call, between 0 and 1.
maximum: 1
minimum: 0
type: number
topK:
description: TopK is the number of tokens to consider for top-k sampling
in a llm call.
type: integer
topP:
description: TopP is the cumulative probability for top-p sampling
in a llm call.
type: number
required:
- input
- output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ spec:
description: Name is the name of resource being referenced
type: string
type: object
scoreThreshold:
type: number
type: object
status:
description: KnowledgeBaseRetrieverStatus defines the observed state of
Expand Down
117 changes: 117 additions & 0 deletions config/samples/app_llmchain_chat_with_bot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
apiVersion: arcadia.kubeagi.k8s.com.cn/v1alpha1
kind: Application
metadata:
name: base-chat-with-bot
namespace: arcadia
spec:
displayName: "对话机器人"
description: "和AI对话,品赛博人生"
prologue: "Hello, I am KubeAGI Bot🤖, Tell me something?"
nodes:
- name: Input
displayName: "用户输入"
description: "用户输入节点,必须"
ref:
kind: Input
name: Input
nextNodeName: ["prompt-node"]
- name: prompt-node
displayName: "prompt"
description: "设定prompt,template中可以使用{{xx}}来替换变量"
ref:
apiGroup: prompt.arcadia.kubeagi.k8s.com.cn
kind: Prompt
name: base-chat-with-bot
nextNodeName: ["chain-node"]
- name: llm-node
displayName: "zhipu大模型服务"
description: "设定质谱大模型的访问信息"
ref:
apiGroup: arcadia.kubeagi.k8s.com.cn
kind: LLM
name: base-chat-with-bot
nextNodeName: ["chain-node"]
- name: chain-node
displayName: "llm chain"
description: "chain是langchain的核心概念,llmChain用于连接prompt和llm"
ref:
apiGroup: chain.arcadia.kubeagi.k8s.com.cn
kind: LLMChain
name: base-chat-with-bot
nextNodeName: ["Output"]
- name: Output
displayName: "最终输出"
description: "最终输出节点,必须"
ref:
kind: Output
name: Output
---
apiVersion: prompt.arcadia.kubeagi.k8s.com.cn/v1alpha1
kind: Prompt
metadata:
name: base-chat-with-bot
namespace: arcadia
spec:
displayName: "设定对话的prompt"
description: "设定对话的prompt"
userMessage: |
The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.
Current conversation:
{{.history}}
Human: {{.question}}
AI:
input:
kind: "Input"
name: "Input"
output:
apiGroup: chain.arcadia.kubeagi.k8s.com.cn
kind: LLMChain
name: base-chat-with-bot
---
apiVersion: chain.arcadia.kubeagi.k8s.com.cn/v1alpha1
kind: LLMChain
metadata:
name: base-chat-with-bot
namespace: arcadia
spec:
displayName: "llm chain"
description: "llm chain"
memory:
conversionWindowSize: 2
input:
llm:
apiGroup: arcadia.kubeagi.k8s.com.cn
kind: LLM
name: base-chat-with-bot
prompt:
apiGroup: prompt.arcadia.kubeagi.k8s.com.cn
kind: Prompt
name: base-chat-with-bot
output:
apiGroup: "arcadia.kubeagi.k8s.com.cn"
kind: "Output"
name: "output-node"
---
apiVersion: v1
kind: Secret
metadata:
name: base-chat-with-bot
namespace: arcadia
type: Opaque
data:
apiKey: "MTZlZDcxYzcwMDE0NGFiMjIyMmI5YmEwZDFhMTBhZTUuUTljWVZtWWxmdjlnZGtDeQ==" # replace this with your API key
---
apiVersion: arcadia.kubeagi.k8s.com.cn/v1alpha1
kind: LLM
metadata:
name: base-chat-with-bot
namespace: arcadia
spec:
type: "zhipuai"
provider:
endpoint:
url: "https://open.bigmodel.cn/api/paas/v3/model-api" # replace this with your LLM URL(Zhipuai use predefined url https://open.bigmodel.cn/api/paas/v3/model-api)
authSecret:
kind: secret
name: base-chat-with-bot
Loading

0 comments on commit 8248519

Please sign in to comment.