(action, candidates, look, inventory, goal, logger, n=1, gpt_version="gpt-4", llm=None)
| 884 | |
| 885 | |
| 886 | def gpt_select_valid(action, candidates, look, inventory, goal, logger, n=1, gpt_version="gpt-4", llm=None): |
| 887 | prompt_to_search = [] |
| 888 | prompt_to_search.append("Let's play a text game.") |
| 889 | prompt_to_search.append(clean_look(look, version="all")) |
| 890 | prompt_to_search.append(inventory) |
| 891 | prompt_to_search.append("There are some action candidates as follows:") |
| 892 | for ac in candidates: |
| 893 | prompt_to_search.append(f"- {ac}") |
| 894 | prompt_to_search.append(f"\n I want to achieve this goal: {goal} but my action '{action}' is not in the candidate list.") |
| 895 | prompt_to_search.append(f"Please consider the objects in the room and inventory and my goal. Think carefully, and then select the best replacement from the list. If no one in the list is a good replacement, return 'none'.") |
| 896 | prompt_to_search.append(f"Selected action:") |
| 897 | |
| 898 | prompt_to_search = "\n".join(prompt_to_search) |
| 899 | logger("-"*30 + "prompt_to_search" + "-"*30) |
| 900 | logger("\n"+prompt_to_search) |
| 901 | logger("-"*35 + "-"*35) |
| 902 | if llm is None: |
| 903 | responses = completion_with_backoff(model=gpt_version, |
| 904 | messages=[{"role": "user", "content": prompt_to_search}, |
| 905 | ], n = n, temperature=0, top_p=1) |
| 906 | # logger(responses) |
| 907 | selections = [responses["choices"][i]["message"]["content"] for i in range(n)] |
| 908 | else: |
| 909 | selections = local_llm.generate(prompt_to_search) |
| 910 | |
| 911 | logger("\n" + "Responses: \n" + "\n".join(selections)) |
| 912 | |
| 913 | return selections |
| 914 | |
| 915 | |
| 916 |
nothing calls this directly
no test coverage detected