MCPcopy
hub / github.com/algorithmicsuperintelligence/optillm / generate_response

Function generate_response

scripts/gen_optillm_dataset.py:14–37  ·  view source on GitHub ↗

Generate a response using the specified approach.

(prompt: str, approach: str)

Source from the content-addressed store, hash-verified

12APPROACHES = ["none", "mcts", "bon", "moa", "rto", "z3", "self_consistency", "pvg", "rstar", "cot_reflection", "plansearch", "leap", "re2"]
13
14async 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
39async def rank_responses(prompt: str, responses: List[Dict[str, Any]]) -> List[int]:
40 """Rank the responses using the LLM."""

Callers 1

process_sampleFunction · 0.70

Calls 1

createMethod · 0.45

Tested by

no test coverage detected