Skip to content

Commit

Permalink
feat: fix the bot build (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying authored Nov 15, 2024
1 parent 2789bf6 commit c859912
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
8 changes: 7 additions & 1 deletion client/app/factory/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import SaveIcon from '@/public/icons/SaveIcon';
import { useBot } from '@/app/contexts/BotContext';
import useUser from '@/app/hooks/useUser';
import Knowledge from './components/Knowledge';
import { useGlobal } from '@/app/contexts/GlobalContext';
import KnowledgeBtn from './components/KnowledgeBtn';
import { BotTaskProvider } from './components/TaskContext';
import { useSearchParams } from 'next/navigation';
Expand All @@ -40,6 +41,8 @@ enum ConfigTypeEnum {
MANUAL_CONFIG = 'MANUAL_CONFIG',
}
export default function Edit() {
const { language } = useGlobal();

const { botProfile, setBotProfile } = useBot();
const { user, status } = useUser();
const router = useRouter();
Expand Down Expand Up @@ -310,7 +313,10 @@ export default function Edit() {
startContent={<AIBtnIcon />}
isLoading={createBotLoading}
onClick={() => {
getBotInfoByRepoName(botProfile?.repoName!);
getBotInfoByRepoName({
repo_name: botProfile?.repoName!,
lang: language,
});
}}
>
{I18N.edit.page.chongXinShengChengPei}
Expand Down
17 changes: 7 additions & 10 deletions client/app/services/BotsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ export async function updateBot(profile: BotProfile) {
}

// Get Bot Info by Repo Name
export async function getBotInfoByRepoName(
repo_name: string,
starters?: string[],
hello_message?: string,
) {
return axios.post(`${apiDomain}/api/bot/config/generator`, {
repo_name,
starters: starters ?? [],
hello_message,
});
export async function getBotInfoByRepoName(params: {
repo_name: string;
lang?: string;
starters?: string[];
hello_message?: string;
}) {
return axios.post(`${apiDomain}/api/bot/config/generator`, params);
}

export async function getChunkList(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"client": "cd client && yarn run dev",
"assistant": "cd assistant && yarn run dev",
"server": "cd server && ./venv/bin/python3 -m uvicorn main:app --reload",
"env:pull": "server/venv/bin/python3 scripts/envs.py pull",
"env:pull": "cd server && ./venv/bin/python3 scripts/envs.py pull",
"client:server": "concurrently \"yarn run server\" \"yarn run client\"",
"assistant:server": "concurrently \"yarn run server\" \"yarn run assistant\"",
"build:docker": "docker build -t petercat .",
Expand Down
6 changes: 6 additions & 0 deletions server/agent/prompts/bot_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
Skill 2: Create a Q&A Bot
- Generate the corresponding prompt questions and greetings based on the GitHub Repository Name and the language used by the user when interacting with you. For example, the repository name is 'petercat':
The starters array contains questions like: ["Tell me about the project petercat"]
The hello_message is: "👋🏻 Hello, I’m petercat. I'm your personal Q&A bot. I’m here to assist you with any questions about this project. Feel free to ask me anything!"
The hello_message should start with an introduction of the bot. This approach allows dynamic adjustment of the prompts based on the language environment, providing a personalized user experience.
- Use the create_bot tool to create a bot based on the GitHub repository name provided by the user.
- The uid of the current user is {user_id}
Skill 3: Modify Bot Configuration
- Utilize the edit_bot tool to modify the bot's configuration information based on the user's description.
Expand Down
2 changes: 1 addition & 1 deletion server/agent/tools/bot_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def create_bot(
"""
Create a bot based on the specified GitHub repository.
:param repo_name: The full name of the GitHub repository (e.g., "ant-design/ ant-design").
:param repo_name: The full name of the GitHub repository (e.g., "ant-design/ant-design").
:param uid: The unique identifier of the bot owner.
:param starters: Optional. A list of opening dialogue prompts (e.g., ["介绍一下项目", "快速上手", "贡献指南"]).
:param hello_message: Optional. A custom hello message for the bot.
Expand Down
9 changes: 4 additions & 5 deletions server/bot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,13 @@ async def bot_generator(
request: Request,
bot_data: BotCreateRequest,
user_id: Annotated[str | None, Depends(get_user_id)] = None,
lang: str = Query("en", description="Language of the bot"),
):
default_starters = [
request.state.i18n.get_text("starter0", lang),
request.state.i18n.get_text("starter1", lang),
request.state.i18n.get_text("starter2", lang),
request.state.i18n.get_text("starter0", bot_data.lang),
request.state.i18n.get_text("starter1", bot_data.lang),
request.state.i18n.get_text("starter2", bot_data.lang),
]
default_hello_message = request.state.i18n.get_text("hello_message", lang)
default_hello_message = request.state.i18n.get_text("hello_message", bot_data.lang)
starters = bot_data.starters if bot_data.starters else default_starters
hello_message = (
bot_data.hello_message if bot_data.hello_message else default_hello_message
Expand Down
1 change: 1 addition & 0 deletions server/core/type_class/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class BotCreateRequest(BaseModel):
repo_name: str
starters: Optional[List[str]] = None
hello_message: Optional[str] = None
lang: Optional[str] = "en"


class BotDeployRequest(BaseModel):
Expand Down

0 comments on commit c859912

Please sign in to comment.