File size: 887 Bytes
dbd33b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import ollama

class QueryRewriter:
    def __init__(self):
        self.model = "phi"  # Using Phi-3.5 model

    def rewrite_cot(self, query):
        prompt = f"""
        Rewrite the following query using Chain-of-Thought reasoning:
        Query: {query}
        
        Rewritten query:
        """
        response = ollama.generate(model=self.model, prompt=prompt)
        return response['response'].strip()

    def rewrite_react(self, query):
        prompt = f"""
        Rewrite the following query using the ReAct framework (Reasoning and Acting):
        Query: {query}
        
        Thought 1:
        Action 1:
        Observation 1:
        
        Thought 2:
        Action 2:
        Observation 2:
        
        Final rewritten query:
        """
        response = ollama.generate(model=self.model, prompt=prompt)
        return response['response'].strip()