MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / call_llm

Method call_llm

eval_heldout/rewoo/nodes/LLMNode.py:134–240  ·  view source on GitHub ↗
(self, prompt, stop)

Source from the content-addressed store, hash-verified

132 return completion
133
134 def call_llm(self, prompt, stop):
135 if self.model_name in OPENAI_COMPLETION_MODELS:
136 response = openai.Completion.create(
137 model=self.model_name,
138 prompt=prompt,
139 temperature=OPENAI_CONFIG["temperature"],
140 max_tokens=OPENAI_CONFIG["max_tokens"],
141 top_p=OPENAI_CONFIG["top_p"],
142 frequency_penalty=OPENAI_CONFIG["frequency_penalty"],
143 presence_penalty=OPENAI_CONFIG["presence_penalty"],
144 stop=stop
145 )
146 return {"input": prompt,
147 "output": response["choices"][0]["text"],
148 "prompt_tokens": response["usage"]["prompt_tokens"],
149 "completion_tokens": response["usage"]["completion_tokens"]}
150 elif self.model_name in OPENAI_CHAT_MODELS:
151 print('*****GPT-4*****')
152 messages = [{"role": "user", "content": prompt}]
153 while True:
154 try:
155 response = openai.ChatCompletion.create(
156 model=self.model_name,
157 messages=messages,
158 # temperature=OPENAI_CONFIG["temperature"],
159 temperature=0.0,
160 max_tokens=OPENAI_CONFIG["max_tokens"],
161 # top_p=OPENAI_CONFIG["top_p"],
162 # frequency_penalty=OPENAI_CONFIG["frequency_penalty"],
163 # presence_penalty=OPENAI_CONFIG["presence_penalty"],
164 # stop=stop
165 )
166 break
167 except:
168 continue
169
170 traj.append({
171 'id': f'{ID}_{len(traj)}',
172 'conversations': [
173 {
174 'from': 'human',
175 'value': prompt,
176 },
177 {
178 'from': 'gpt',
179 'value': response["choices"][0]["message"]["content"],
180 },
181 ]
182 })
183 json.dump(traj, open(LOG, 'w'))
184
185 return {"input": prompt,
186 "output": response["choices"][0]["message"]["content"],
187 "prompt_tokens": response["usage"]["prompt_tokens"],
188 "completion_tokens": response["usage"]["completion_tokens"]}
189 elif self.model_name in LLAMA_WEIGHTS:
190 instruction, input = prompt[0], prompt[1]
191 output, prompt = self.al.lora_generate(instruction, input)

Callers 3

runMethod · 0.95
runMethod · 0.80
runMethod · 0.80

Calls 5

token_countFunction · 0.85
createMethod · 0.80
lora_generateMethod · 0.80
llm_llamaFunction · 0.70
get_promptFunction · 0.70

Tested by

no test coverage detected