Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/gcr-custom' into xuhan/gcr-custom
Browse files Browse the repository at this point in the history
  • Loading branch information
IcyKallen committed Feb 27, 2025
2 parents 822dabe + 431e831 commit 001ba48
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 183 deletions.
2 changes: 1 addition & 1 deletion source/infrastructure/lib/chat/chat-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class ChatStack extends NestedStack implements ChatStackOutputs {
BEDROCK_AWS_SECRET_ACCESS_KEY: props.config.chat.bedrockSk || ""
},
// layers: [apiLambdaOnlineSourceLayer, modelLayer],
layers: [apiLambdaOnlineSourceLayer],
layers: [apiLambdaOnlineSourceLayer]
});
this.lambdaOnlineMain = lambdaOnlineMain.function;

Expand Down
40 changes: 1 addition & 39 deletions source/infrastructure/lib/ui/ui-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { join } from "path";

import { SystemConfig } from "../shared/types";
import { PortalConstruct } from "../ui/ui-portal";
import { UserConstruct } from "../user/user-construct";




Expand All @@ -28,14 +28,12 @@ interface UIStackProps extends StackProps {
export interface UIStackOutputs {
readonly mainPortalConstruct: PortalConstruct;
readonly clientPortalConstruct: PortalConstruct;
readonly userConstruct: UserConstruct;
}

export class UIStack extends Stack implements UIStackOutputs {

public mainPortalConstruct: PortalConstruct;
public clientPortalConstruct: PortalConstruct;
public userConstruct: UserConstruct;

constructor(scope: Construct, id: string, props: UIStackProps) {
super(scope, id, props);
Expand All @@ -48,44 +46,8 @@ export class UIStack extends Stack implements UIStackOutputs {
responseHeadersPolicyName: `SecHdr${Aws.REGION}${Aws.STACK_NAME}-client`
});

const userConstruct = new UserConstruct(this, "User", {
deployRegion: props.config.deployRegion,
adminEmail: props.config.email,
callbackUrls: [
`https://${clientPortalConstruct.portalUrl}/signin`,
`https://${mainPortalConstruct.portalUrl}/signin`
],
logoutUrls: [
`https://${clientPortalConstruct.portalUrl}`,
`https://${mainPortalConstruct.portalUrl}`
],
// userPoolName: `${Constants.SOLUTION_NAME}-workspace_UserPool`,
// domainPrefix: `${Constants.SOLUTION_NAME.toLowerCase()}-workspace-${Aws.ACCOUNT_ID}`,
});
this.mainPortalConstruct = mainPortalConstruct;
this.clientPortalConstruct = clientPortalConstruct;
this.userConstruct = userConstruct;

// Add CfnOutputs to export values
new CfnOutput(this, 'UserPoolId', {
value: userConstruct.userPoolId,
exportName: `${id}-user-pool-id`
});

new CfnOutput(this, 'OidcClientId', {
value: userConstruct.oidcClientId,
exportName: `${id}-oidc-client-id`
});

new CfnOutput(this, 'OidcIssuer', {
value: userConstruct.oidcIssuer,
exportName: `${id}-oidc-issuer`
});

new CfnOutput(this, 'OidcLogoutUrl', {
value: userConstruct.oidcLogoutUrl,
exportName: `${id}-oidc-logout-url`
});

new CfnOutput(this, 'PortalBucketName', {
value: mainPortalConstruct.portalBucket.bucketName,
Expand Down
140 changes: 0 additions & 140 deletions source/infrastructure/lib/user/user-construct.ts

This file was deleted.

8 changes: 8 additions & 0 deletions source/lambda/online/common_logic/common_utils/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class ModelProvider(ConstantBase):
BRCONNECTOR_BEDROCK = "Bedrock API"
OPENAI = "OpenAI API"
SAGEMAKER = "SageMaker"
SILICONFLOW = "siliconflow"



class LLMModelType(ConstantBase):
Expand Down Expand Up @@ -161,7 +163,13 @@ class LLMModelType(ConstantBase):
QWEN25_INSTRUCT_72B_AWQ = "Qwen2.5-72B-Instruct-AWQ"
DEEPSEEK_R1_DISTILL_LLAMA_8B = "DeepSeek-R1-Distill-Llama-8B"
DEEPSEEK_R1_DISTILL_LLAMA_70B = "DeepSeek-R1-Distill-Llama-70B"
DEEPSEEK_R1_DISTILL_QWEN_1d5B = "DeepSeek-R1-Distill-Qwen-1.5B"
DEEPSEEK_R1_DISTILL_QWEN_7B = "DeepSeek-R1-Distill-Qwen-7B"
DEEPSEEK_R1_DISTILL_QWEN_14B = "DeepSeek-R1-Distill-Qwen-14B"
DEEPSEEK_R1_DISTILL_QWEN_32B = "DeepSeek-R1-Distill-Qwen-32B"
DEEPSEEK_R1 = "DeepSeek-R1"
DEEPSEEK_V3 = "DeepSeek-R3"

QWEN15INSTRUCT32B = "qwen1_5-32B-instruct"
LLAMA3_1_70B_INSTRUCT = "meta.llama3-1-70b-instruct-v1:0"
LLAMA3_2_90B_INSTRUCT = "us.meta.llama3-2-90b-instruct-v1:0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ModelProvider,
)
from dmaa.integrations.langchain_clients import (
SageMakerVllmChatModel as _SageMakerVllmChatModel,
SageMakerVllmChatModel as _SageMakerVllmChatModel
)

from . import Model
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import boto3
from common_logic.common_utils.constant import (
ModelProvider
)
from common_logic.common_utils.logger_utils import get_logger, llm_messages_print_decorator
from . import Model
from langchain_deepseek import ChatDeepSeek as _ChatDeepSeek
from ..model_config import SILICONFLOW_DEEPSEEK_MODEL_CONFIGS

logger = get_logger("siliconflow_models")

class ChatDeepSeek(_ChatDeepSeek):
enable_any_tool_choice: bool = False
any_tool_choice_value: str = 'required'
enable_prefill: bool = False


class DeepSeekBaseModel(Model):
default_model_kwargs = {"max_tokens": 2000,
"temperature": 0.6, "top_p": 0.9}
enable_any_tool_choice: bool = False
enable_prefill: bool = False
model_provider = ModelProvider.SILICONFLOW

@classmethod
def create_model(cls, model_kwargs=None, **kwargs):
model_kwargs = model_kwargs or {}
model_kwargs = {**cls.default_model_kwargs, **model_kwargs}
# base_url = kwargs.get("base_url", None) or os.environ.get(
# "OPENAI_BASE_URL", None)
api_key = kwargs.get('siliconflow_api_key', None) or os.environ.get(
"SILICONFLOW_API_KEY", None)
return ChatDeepSeek(
enable_any_tool_choice=cls.enable_any_tool_choice,
enable_prefill=cls.enable_prefill,
base_url="https://api.siliconflow.cn/v1",
api_key=api_key,
model=cls.model_id,
**model_kwargs
)


DeepSeekBaseModel.create_for_models(SILICONFLOW_DEEPSEEK_MODEL_CONFIGS)

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
@dataclass
class ModelConfig:
model_id: str
model: Union[str,None] = None
default_model_kwargs: Dict[str, Any] = None
enable_any_tool_choice: bool = True
any_tool_choice_value: str = "any"
enable_prefill: bool = True


def __post_init__(self):
if self.default_model_kwargs is None:
self.default_model_kwargs = {}
Expand Down Expand Up @@ -184,6 +186,58 @@ def __post_init__(self):
)
]

SILICONFLOW_DEEPSEEK_MODEL_CONFIGS = [
ModelConfig(
model_id=LLMModelType.DEEPSEEK_R1_DISTILL_LLAMA_70B,
model="deepseek-ai/DeepSeek-R1-Distill-Llama-70B",
default_model_kwargs=BASE_CONFIG.default_model_kwargs.copy(),
enable_any_tool_choice=False,
enable_prefill=False
),
ModelConfig(
model_id=LLMModelType.DEEPSEEK_R1_DISTILL_LLAMA_8B,
model="deepseek-ai/DeepSeek-R1-Distill-Llama-8B",
default_model_kwargs=BASE_CONFIG.default_model_kwargs.copy(),
enable_any_tool_choice=False,
enable_prefill=False
),
ModelConfig(
model_id=LLMModelType.DEEPSEEK_R1_DISTILL_QWEN_7B,
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
default_model_kwargs=BASE_CONFIG.default_model_kwargs.copy(),
enable_any_tool_choice=False,
enable_prefill=False
),
ModelConfig(
model_id=LLMModelType.DEEPSEEK_R1_DISTILL_QWEN_14B,
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
default_model_kwargs=BASE_CONFIG.default_model_kwargs.copy(),
enable_any_tool_choice=False,
enable_prefill=False
),
ModelConfig(
model_id=LLMModelType.DEEPSEEK_R1_DISTILL_QWEN_1d5B,
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
default_model_kwargs=BASE_CONFIG.default_model_kwargs.copy(),
enable_any_tool_choice=False,
enable_prefill=False
),
ModelConfig(
model_id=LLMModelType.DEEPSEEK_R1_DISTILL_QWEN_32B,
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
default_model_kwargs=BASE_CONFIG.default_model_kwargs.copy(),
enable_any_tool_choice=False,
enable_prefill=False
),
ModelConfig(
model_id=LLMModelType.DEEPSEEK_R1,
model="deepseek-ai/DeepSeek-R1",
default_model_kwargs=BASE_CONFIG.default_model_kwargs.copy(),
enable_any_tool_choice=False,
enable_prefill=False
)
]


OPENAI_MODEL_CONFIGS = [
ModelConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def filter_response(res: Iterable, state: dict):
references = []
tag_start = "<reference>"
tag_end = "</reference>"

for char in res:
char_strip = char.strip()
if not buffer and char_strip not in ["<", "<reference"]:
Expand Down Expand Up @@ -138,6 +138,8 @@ def rag_tool(retriever_config: dict, query=None):
)
output = chain.invoke(llm_input)



filtered_output = filter_response(output, state)

return filtered_output, filtered_output
3 changes: 2 additions & 1 deletion source/lambda/online/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ opensearch-py==2.2.0
requests_aws4auth==1.2.2
pydantic==2.9.2
datamodel-code-generator==0.26.2
langchain-openai==0.2.6
langchain-openai==0.3.7
langchain-deepseek==0.1.2

0 comments on commit 001ba48

Please sign in to comment.