Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2
3tokenizer = AutoTokenizer.from_pretrained("path/to/vicuna-13b-finetuned-langchain-MRKL")
4model = AutoModelForCausalLM.from_pretrained("path/to/vicuna-13b-finetuned-langchain-MRKL")
5model.cuda()
6
7prompt = """Answer the following questions as best you can. You have access to the following tools:
8
9Search: useful for when you need to answer questions about current events
10Calculator: useful for when you need to answer questions about math
11
12Use the following format:
13
14Question: the input question you must answer
15Thought: you should always think about what to do
16Action: the action to take, should be one of [Search, Calculator]
17Action Input: the input to the action
18Observation: the result of the action
19... (this Thought/Action/Action Input/Observation can repeat N times)
20Thought: I now know the final answer
21Final Answer: the final answer to the original input question
22
23Begin!
24
25Question: The current age of the President of the United States multiplied by 0.5.
26Thought:"""
27
28input_ids = tokenizer(prompt, return_tensors='pt').input_ids.to("cuda")
29tokens = model.generate(input_ids,min_length = 5, max_new_tokens=128,do_sample = True, temperature = 0.7, top_p = 0.9)
30print(tokenizer.decode(tokens[0], skip_special_tokens=True))1I need to find the current age of the President and then multiply it by 0.5
2Action: Search
3Action Input: Who is the President of the United States?