Generate a response using the specified approach.
(prompt: str, approach: str)
| 12 | APPROACHES = ["none", "mcts", "bon", "moa", "rto", "z3", "self_consistency", "pvg", "rstar", "cot_reflection", "plansearch", "leap", "re2"] |
| 13 | |
| 14 | async def generate_response(prompt: str, approach: str) -> Dict[str, Any]: |
| 15 | """Generate a response using the specified approach.""" |
| 16 | if approach == "none": |
| 17 | # Use the base model without any optimization technique |
| 18 | client = AsyncOpenAI() |
| 19 | response = await client.chat.completions.create( |
| 20 | model="gpt-4o-mini", |
| 21 | messages=[{"role": "user", "content": prompt}], |
| 22 | ) |
| 23 | return { |
| 24 | "content": response.choices[0].message.content, |
| 25 | "tokens": response.usage.completion_tokens, |
| 26 | } |
| 27 | else: |
| 28 | # Use OptILM with the specified approach |
| 29 | client = AsyncOpenAI(api_key="none", base_url="http://localhost:8080/v1") |
| 30 | response = await client.chat.completions.create( |
| 31 | model=f"{approach}-gpt-4o-mini", # Assuming OptILM uses this naming convention |
| 32 | messages=[{"role": "user", "content": prompt}], |
| 33 | ) |
| 34 | return { |
| 35 | "content": response.choices[0].message.content, |
| 36 | "tokens": response.usage.completion_tokens, |
| 37 | } |
| 38 | |
| 39 | async def rank_responses(prompt: str, responses: List[Dict[str, Any]]) -> List[int]: |
| 40 | """Rank the responses using the LLM.""" |
no test coverage detected