Skip to content

Commit

Permalink
fix bugs in clear and improve prompts
Browse files Browse the repository at this point in the history
- [x] fix bugs in clear conversation in conversation history pure mode
- [x] modify system prompts for better instruction following
- [x] update readme for open-source model usage
  • Loading branch information
XuHwang authored and Leavingseason committed May 11, 2024
1 parent 24a7339 commit 566f185
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 43 deletions.
31 changes: 31 additions & 0 deletions InteRecAgent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,37 @@ InteRecAgent consists of 4 necessary components:
bot_type="chat" # model type, ["chat", "completetion"]. For gpt-3.5-turbo and gpt-4, it should be "chat". For text-davinci-003, it should be "completetion"
```

Meanwhile, we support to serve local models such as Vicuna as the backbone language model instead of OpenAI APIs:

1. Download the weights of [Vicuna](https://huggingface.co/lmsys/vicuna-7b-v1.5) from huggingface.

2. Install `fschat` package according to [FastChat](https://github.com/lm-sys/FastChat?tab=readme-ov-file#install)

3. Deploy the Vicuna model with OpenAI-Compatible RESTful APIs by running the following command:

```bash
# First, launch the controller
python3 -m fastchat.serve.controller
# Then, launch the model worker(s)
python3 -m fastchat.serve.model_worker --model-path path-to-vicuna
# Finally, launch the RESTful API server
python3 -m fastchat.serve.openai_api_server --host localhost --port 8000
```

4. Set the configuration for RecLlama API in `run.sh`

```bash
API_KEY="EMPTY"
API_BASE="http://localhost:8000/v1"
API_VERSION="2023-03-15-preview"
API_TYPE="open_ai"
engine="vicuna-7b-v1.5" # model name
bot_type="completetion" # model type
```

5. Run the `run.sh` script to start the chatbot.


Also, we support to use our finetuned model RecLlama as the backbone language model, the tutorial could be found in [RecLlama](./RecLlama.md).


Expand Down
31 changes: 0 additions & 31 deletions InteRecAgent/RecLlama.md

This file was deleted.

3 changes: 3 additions & 0 deletions InteRecAgent/llm4crs/agent_plan_first_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def __init__(
self.memory = []

def clear(self) -> None:
self._shortened_dialogue_history: str = ""
self._shortened_dialogue_turn: int = 0
self.memory = []

def get(self) -> str:
Expand Down Expand Up @@ -406,6 +408,7 @@ def clear(self):
if self._record_planning:
self._plan_record_cache = {"traj": [], "conv": [], "reward": 0}
logger.debug("History Cleared!")
logger.debug("Memory Cleared!")
if self.user_profile:
self.user_profile.clear()

Expand Down
14 changes: 5 additions & 9 deletions InteRecAgent/llm4crs/prompt/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
You are a conversational {item} recommendation assistant. Your task is to help human find {item}s they are interested in. \
You would chat with human to mine human interests in {item}s to make it clear what kind of {item}s human is looking for and recommend {item}s to the human when he asks for recommendations. \
Human requests typically fall under chit-chat, {item} info, or {item} recommendations. There are some tools to use to deal with human request.\
Human requests typically fall under chit-chat, asking for {item} info, or asking for {item} recommendations. There are some tools to use to deal with human request.\
For chit-chat, respond with your knowledge. For {item} info, use the {LookUpTool}. \
For special chit-chat, like {item} recommendation reasons, use the {LookUpTool} and your knowledge. \
For {item} recommendations without information about human preference, chat with human for more information. \
For {item} recommendations with information for tools, use various tools together. \
For {item} recommendations without obvious intention, chat with human for more information. \
For {item} recommendations with information, use various tools to get recommendations. \
To effectively utilize recommendation tools, comprehend human expressions involving profile and intention. \
Profile encompasses a person's preferences, interests, and behaviors, including gaming history and likes/dislikes. \
Expand Down Expand Up @@ -150,8 +150,8 @@
###
Question: Do I need to use tools to process human's input?
Thought: No, I know the final answer.
Final Answer: the final answer to the original input question
Thought: No, I do not need to use tools because I know the final answer (or I need to ask more questions).
Final Answer: the final answer to the original input question (or the question I asked)
###
If use tools, use the format:
Expand All @@ -161,10 +161,6 @@
Action: {tool_exe_name}
Action Input: the input to {tool_exe_name}, should be a plan
Observation: the result of tool execution
Question: Do I need to use tools to process human's input?
Thought: No, I know the final answer.
Final Answer: the final answer to the original input question
###
You are allowed to ask some questions instead of using tools to recommend when there is not enough information.
Expand Down
6 changes: 3 additions & 3 deletions InteRecAgent/llm4crs/prompt/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


LOOK_UP_TOOL_DESC = """
The tool is used to look up some {item} information in a {item} information table (including statistical information), like number of {item}s, description of {item}s and so on. \
The tool is used to look up {item}'s detailed information in a {item} information table (including statistical information), like number of {item}s, description of {item}s, price and so on. \
The input of the tools should be a SQL command (in one line) converted from the search query, which would be used to search information in {item} information table. \
You should try to select as less columns as you can to get the necessary information. \
Expand All @@ -36,7 +36,7 @@


HARD_FILTER_TOOL_DESC = """
The tool is a hard condition tool. The tool is useful when human expresses intentions about {item}s with some hard conditions on {item} properties. \
The tool is a hard-condition {item} filtering tool. The tool is useful when human want {item}s with some hard conditions on {item} properties. \
The input of the tool should be a one-line SQL SELECT command converted from hard conditions. Here are some rules: \
1. {item} titles can not be used as conditions in SQL;
2. the tool can not find similar {item}s;
Expand All @@ -49,7 +49,7 @@


SOFT_FILTER_TOOL_DESC = """
The tool is a soft condition filtering tool. \
The tool is a soft condition {item} filtering tool. \
The tool can find similar {item}s for specific seed {item}s. \
Never use this tool if human doesn't express to find some {item}s similar with seed {item}s. \
There is a similarity score threshold in the tool, only {item}s with similarity above the threshold would be kept. \
Expand Down

0 comments on commit 566f185

Please sign in to comment.