### Verify Backend Installation Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Command to run an example Python script to verify the successful installation of the backend components. ```Bash python examples/discriminative_task/optimizer_example.py ``` -------------------------------- ### Start Backend Service Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Commands to set up a Python virtual environment, install backend dependencies, and start the FastAPI backend server. ```Bash cd prompt-optimizer conda create --name prompt_optimizer python=3.10 conda activate prompt_optimizer pip install -r requirements.txt cd api uvicorn main:app --reload --host 0.0.0.0 --port 8000 ``` -------------------------------- ### Start Frontend Service Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Commands to navigate to the frontend directory, install dependencies, and start the development server in a new terminal. ```Bash cd frontend npm install npm run dev ``` -------------------------------- ### Install Frontend Dependencies Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Commands to navigate into the frontend directory and install project dependencies using npm. ```Bash cd frontend npm install ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Commands to install all required Python dependencies from `requirements.txt` or specific core dependencies individually. ```Bash pip install -r requirements.txt # Or install main dependencies individually pip install pandas openpyxl requests python-dotenv tqdm ``` -------------------------------- ### Run Frontend Development Server Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Command to start the frontend development server for local testing and development. ```Bash npm run serve ``` -------------------------------- ### Full Prompt Optimization Example with Python Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md A comprehensive Python example demonstrating how to define an evaluation function, prepare test data, configure LLM models, and initialize the PromptOptimizer for a time parsing task. This snippet showcases the core components and their integration for an end-to-end prompt optimization workflow. ```Python from datetime import datetime from optimizer.core.prompt_optimizer import PromptOptimizer from llm.llm_config import LLM_Config import pandas as pd # 1. Define evaluation function def example_evaluation_func(response: str, test_case: dict) -> float: """ 评估函数示例 - 检查模型输出是否符合预期 """ expected = str(test_case.get("expected", "")) if response == expected: return 1.0 return 0.0 # 2. Prepare test dataset def read_questions_and_units(file_path: str, sheet_name: str) -> list: """ 从Excel文件读取测试数据 """ df = pd.read_excel(file_path, sheet_name=sheet_name) return df.apply(lambda row: { "input": row["用户问题"], "expected": row["起始时间"] }, axis=1).tolist() # 3. Configure LLM model optimize_llm_config = LLM_Config( model_name="qwen-plus", api_key="your-api-key", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1" ) test_llm_config = LLM_Config( model_name="qwen2.5-32b-instruct", api_key="your-api-key", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1" ) # 4. Create optimizer instance optimizer = PromptOptimizer( optimize_llm_config=optimize_llm_config, test_llm_config=test_llm_config ) ``` -------------------------------- ### Build Frontend for Production Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Command to build the frontend project for production deployment. ```Bash npm run build ``` -------------------------------- ### Clone Project Repository Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Commands to clone the Prompt Optimizer repository using either HTTPS or SSH, and then navigate into the project directory. ```Bash git https://github.com/songtingze/prompt-optimizer.git # Or using SSH git clone git@github.com:songtingze/prompt-optimizer.git cd prompt-optimizer ``` -------------------------------- ### Optimize Prompt API Endpoint Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Documentation for the `/api/optimize` POST endpoint, detailing request and response structures for prompt optimization. ```APIDOC Endpoint: /api/optimize Method: POST Request Body (JSON): initial_prompt: string (Required) - The initial prompt. success_experience: string (Optional) - Description of successful experiences. optimize_suggestion: string (Optional) - Suggestions for optimization. test_accuracy: number (Required) - Initial test accuracy. Response Body (JSON): optimized_prompt: string - The optimized prompt. success_experience: string - Optimized successful experience. optimize_suggestion: string - Optimized optimization suggestion. test_accuracy: number - Optimized test accuracy. execution_time: string - Time taken for execution. total_tokens: string - Total tokens consumed. ``` -------------------------------- ### Create Python Virtual Environment Source: https://github.com/songtingze/prompt-optimizer/blob/master/README.md Commands to create and activate a new Python virtual environment using Conda, recommended for dependency management. ```Bash conda create --name prompt_optimizer python=3.10 # Activate virtual environment conda activate prompt_optimizer ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.